commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject cvs commit: jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking GenericLockManager.java LockManager2.java
Date Fri, 07 Jan 2005 23:24:03 GMT
ozeigermann    2005/01/07 15:24:03

  Modified:    transaction/src/java/org/apache/commons/transaction/locking
                        GenericLockManager.java LockManager2.java
  Log:
  Added all the flexibility GenericLock offers to the new lock manager
  
  Revision  Changes    Path
  1.14      +19 -11    jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLockManager.java
  
  Index: GenericLockManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLockManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- GenericLockManager.java	7 Jan 2005 13:52:42 -0000	1.13
  +++ GenericLockManager.java	7 Jan 2005 23:24:03 -0000	1.14
  @@ -157,7 +157,15 @@
        */
       public void lock(Object ownerId, Object resourceId, int targetLockLevel, boolean reentrant,
               long timeoutMSecs) throws LockException {
  +        lock(ownerId, resourceId, targetLockLevel, reentrant ? GenericLock.COMPATIBILITY_REENTRANT
  +                : GenericLock.COMPATIBILITY_NONE, false, globalTimeoutMSecs);
  +    }
   
  +    /**
  +     * @see LockManager2#lock(Object, Object, int, int, boolean, long)
  +     */
  +    public void lock(Object ownerId, Object resourceId, int targetLockLevel, int compatibility,
  +            boolean preferred, long timeoutMSecs) throws LockException {
           timeoutCheck(ownerId);
           
           long now = System.currentTimeMillis();
  @@ -189,7 +197,8 @@
               // if not we still can check what the reason for this is
               if (checkThreshhold != -1 && timeoutMSecs > checkThreshhold) {
                   acquired = lock
  -                        .acquire(ownerId, targetLockLevel, true, reentrant, checkThreshhold);
  +                        .acquire(ownerId, targetLockLevel, true, compatibility,
  +                                preferred, checkThreshhold);
                   if (acquired) {
                       addOwner(ownerId, lock);
                       return;
  @@ -211,12 +220,10 @@
                       // have a deadlock
       
                       Set conflicts = lock.getConflictingOwners(ownerId, targetLockLevel,
  -                            reentrant ? GenericLock.COMPATIBILITY_REENTRANT
  -                                    : GenericLock.COMPATIBILITY_NONE);
  +                            compatibility);
   
                       boolean deadlock = wouldDeadlock(ownerId, lock, targetLockLevel,
  -                            reentrant ? GenericLock.COMPATIBILITY_REENTRANT
  -                                    : GenericLock.COMPATIBILITY_NONE, conflicts);
  +                            compatibility, conflicts);
                       if (deadlock) {
                           throw new LockException("Lock would cause deadlock",
                                   LockException.CODE_DEADLOCK_VICTIM, resourceId);
  @@ -233,8 +240,8 @@
                           timeoutMSecs = waitEnd - now;
                       }
               
  -                    acquired = lock
  -                            .acquire(ownerId, targetLockLevel, true, reentrant, timeoutMSecs);
  +                    acquired = lock.acquire(ownerId, targetLockLevel, true, compatibility,
  +                            preferred, timeoutMSecs);
                       
                   }
               }
  @@ -481,4 +488,5 @@
                       LockException.CODE_TIMED_OUT, null);
           }
       }
  +
   }
  
  
  
  1.2       +39 -4     jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/LockManager2.java
  
  Index: LockManager2.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/LockManager2.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LockManager2.java	7 Jan 2005 13:32:33 -0000	1.1
  +++ LockManager2.java	7 Jan 2005 23:24:03 -0000	1.2
  @@ -106,6 +106,41 @@
               long timeoutMSecs) throws LockException;
   
       /**
  +     * Most flexible way to acquire a lock on a resource. <br>
  +     * <br>
  +     * This method blocks and waits for the lock in case it is not avaiable. If
  +     * there is a timeout or a deadlock or the thread is interrupted a
  +     * LockException is thrown.
  +     * 
  +     * @param ownerId
  +     *            a unique id identifying the entity that wants to acquire this
  +     *            lock
  +     * @param resourceId
  +     *            the resource to get the level for
  +     * @param targetLockLevel
  +     *            the lock level to acquire
  +     * @param compatibility
  +     *            {@link GenericLock#COMPATIBILITY_NONE}if no additional compatibility
is
  +     *            desired (same as reentrant set to false) ,
  +     *            {@link GenericLock#COMPATIBILITY_REENTRANT}if lock level by the same
  +     *            owner shall not affect compatibility (same as reentrant set to
  +     *            true), or {@link GenericLock#COMPATIBILITY_SUPPORT}if lock levels that
  +     *            are the same as the desired shall not affect compatibility, or
  +     *            finally {@link GenericLock#COMPATIBILITY_REENTRANT_AND_SUPPORT}which
is
  +     *            a combination of reentrant and support
  +     * @param preferred
  +     *            in case this lock request is incompatible with existing ones
  +     *            and we wait, it shall be granted before other waiting requests
  +     *            that are not preferred
  +     * @param timeoutMSecs
  +     *            specifies the maximum wait time in milliseconds
  +     * @throws LockException
  +     *             will be thrown when the lock can not be acquired
  +     */
  +    public void lock(Object ownerId, Object resourceId, int targetLockLevel, int compatibility,
  +            boolean preferred, long timeoutMSecs) throws LockException;
  +
  +    /**
        * Gets the lock level held by certain owner on a certain resource.
        * 
        * @param ownerId the id of the owner of the lock
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message