db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r518416 - in /db/ojb/branches/OJB_1_0_RELEASE/src: java/org/apache/ojb/broker/locking/ test/org/apache/ojb/
Date Thu, 15 Mar 2007 01:13:09 GMT
Author: arminw
Date: Wed Mar 14 18:13:07 2007
New Revision: 518416

URL: http://svn.apache.org/viewvc?view=rev&rev=518416
Log:
add new methods to locking-api, adapt and improve existing LockManager-impl classes

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManager.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/web.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java?view=diff&rev=518416&r1=518415&r2=518416
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java
Wed Mar 14 18:13:07 2007
@@ -15,11 +15,16 @@
  * limitations under the License.
  */
 
+import java.util.Set;
+import java.util.Iterator;
+
 import org.apache.commons.transaction.locking.GenericLock;
 import org.apache.commons.transaction.locking.GenericLockManager;
 import org.apache.commons.transaction.locking.LockException;
 import org.apache.commons.transaction.locking.MultiLevelLock;
 import org.apache.commons.transaction.util.LoggerFacade;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
 
 /**
  * Extension of {@link org.apache.commons.transaction.locking.GenericLockManager} to
@@ -32,7 +37,6 @@
  * {@link #createIsolationLevel(Object, Object, org.apache.commons.transaction.util.LoggerFacade)}
  * dependend on the specified isolation level.
  *
- * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  * @version $Id$
  */
 class CommonsOJBLockManager extends GenericLockManager
@@ -41,10 +45,20 @@
     static final int COMMON_WRITE_LOCK = 107;
     static final int COMMON_UPGRADE_LOCK = 113;
 
-    public CommonsOJBLockManager(LoggerFacade logger, long timeoutMSecs, long checkThreshholdMSecs)
+    public CommonsOJBLockManager(LoggerFacade logger, long globalLockTimeoutMSecs, long checkThreshholdMSecs)
             throws IllegalArgumentException
     {
-        super(1, logger, timeoutMSecs, checkThreshholdMSecs);
+        super(1, logger, globalLockTimeoutMSecs, checkThreshholdMSecs);
+    }
+
+    public synchronized String toString()
+    {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("globalOwner_MapSize="+globalOwners.size())
+                .append("globalLocks_MapSize="+globalLocks.size())
+                .append("effectiveGlobalTimeouts_MapSize="+effectiveGlobalTimeouts.size())
+                .append("timedOutOwners_SetSize="+effectiveGlobalTimeouts.size())
+                .toString();
     }
 
     /**
@@ -192,7 +206,7 @@
      */
     public OJBLock createIsolationLevel(Object resourceId, Object isolationId, LoggerFacade
logger)
     {
-        OJBLock result = null;
+        OJBLock result;
         switch(((Integer) isolationId).intValue())
         {
             case LockManager.IL_READ_UNCOMMITTED:
@@ -223,7 +237,7 @@
      *
      * @param isolationId
      * @param lockLevel
-     * @return
+     * @return the commons-tx lock level
      */
     int mapLockLevelDependendOnIsolationLevel(Integer isolationId, int lockLevel)
     {
@@ -382,7 +396,7 @@
 
         static int mapLockLevel(int commonLockLevel)
         {
-            int result = 0;
+            int result;
             switch(commonLockLevel)
             {
                 case COMMON_READ_LOCK:
@@ -447,7 +461,7 @@
 
         protected boolean isCompatible(int targetLockLevel, int currentLockLevel)
         {
-            return currentLockLevel > NO_LOCK ? false : true;
+            return currentLockLevel <= NO_LOCK;
         }
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManager.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManager.java?view=diff&rev=518416&r1=518415&r2=518416
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManager.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManager.java
Wed Mar 14 18:13:07 2007
@@ -86,82 +86,130 @@
     public String getLockInfo();
 
     /**
-     * Acquires a readlock for lock key on resource object.
+     * Acquires a readlock for lock owner on resource object.
      * Returns true if successful, else false.
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to lock.
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to lock.
      * @param isolationLevel The isolation level of the lock.
      * @return <em>True</em> if the lock was successfully acquired.
      */
-    public boolean readLock(Object key, Object resourceId, int isolationLevel);
+    public boolean readLock(Object owner, Object resource, int isolationLevel);
 
     /**
-     * Acquires a write lock for lock key on resource object.
+     * Acquires a readlock for lock owner on resource object.
+     * Returns <em>true</em> if successful, else false.
+     * The <em>lock timeout</em> and the <em>block timeout</em> must
+     * be specified too (support for <em>lock timeout</em> and the <em>block
timeout</em>
+     * depends on the implementation).
+     *
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to lock.
+     * @param isolationLevel The isolation level of the lock.
+     * @param lockTimeout The lock timeout in <em>ms</em> of acquired lock.
+     * @param blockTimeout The time to wait for acquire the lock in <em>ms</em>.
+     * @return <em>True</em> if the lock was successfully acquired.
+     */
+    public boolean readLock(Object owner, Object resource, int isolationLevel, long lockTimeout,
long blockTimeout);
+
+    /**
+     * Acquires a write lock for lock owner on resource object.
      * Returns true if successful, else false.
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to lock.
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to lock.
+     * @param isolationLevel The isolation level of the lock.
+     * @return <em>True</em> if the lock was successfully acquired.
+     */
+    public boolean writeLock(Object owner, Object resource, int isolationLevel);
+
+    /**
+     * Acquires a write lock for lock owner on resource object.
+     * Returns true if successful, else false.
+     * The <em>lock timeout</em> and the <em>block timeout</em> must
+     * be specified too (support for <em>lock timeout</em> and the <em>block
timeout</em>
+     * depends on the implementation).
+     *
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to lock.
+     * @param isolationLevel The isolation level of the lock.
+     * @param lockTimeout The lock timeout in <em>ms</em> of acquired lock.
+     * @param blockTimeout The time to wait for acquire the lock in <em>ms</em>.
+     * @return <em>True</em> if the lock was successfully acquired.
+     */
+    public boolean writeLock(Object owner, Object resource, int isolationLevel, long lockTimeout,
long blockTimeout);
+
+    /**
+     * Acquire an upgrade lock.
+     * (Current implementations always acquire a write lock instead).
+     *
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to lock.
      * @param isolationLevel The isolation level of the lock.
      * @return <em>True</em> if the lock was successfully acquired.
      */
-    public boolean writeLock(Object key, Object resourceId, int isolationLevel);
+    public boolean upgradeLock(Object owner, Object resource, int isolationLevel);
 
     /**
      * Acquire an upgrade lock.
      * (Current implementations always acquire a write lock instead).
+     * The <em>lock timeout</em> and the <em>block timeout</em> must
+     * be specified too (support for <em>lock timeout</em> and the <em>block
timeout</em>
+     * depends on the implementation).
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to lock.
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to lock.
      * @param isolationLevel The isolation level of the lock.
+     * @param lockTimeout The lock timeout in <em>ms</em> of acquired lock.
+     * @param blockTimeout The time to wait for acquire the lock in <em>ms</em>.
      * @return <em>True</em> if the lock was successfully acquired.
      */
-    public boolean upgradeLock(Object key, Object resourceId, int isolationLevel);
+    public boolean upgradeLock(Object owner, Object resource, int isolationLevel, long lockTimeout,
long blockTimeout);
 
     /**
-     * Releases a lock for lock key on resource object.
+     * Releases a lock for lock owner on resource object.
      * Returns true if successful, else false.
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to release.
+     * @param owner        The owner of the lock.
+     * @param resource     The resource to release.
      * @return <em>True</em> if the lock was successfully released.
      */
-    public boolean releaseLock(Object key, Object resourceId);
+    public boolean releaseLock(Object owner, Object resource);
 
     /**
-     * Release all resource locks hold by the specified owner key.
+     * Release all resource locks hold by the specified owner owner.
      *
-     * @param key The owner key to release all associated locks.
+     * @param owner The owner to release all associated locks.
      */
-    public void releaseLocks(Object key);
+    public void releaseLocks(Object owner);
 
     /**
      * Checks if there is a read lock for owner key on resource object.
      * Returns true if so, else false.
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to check.
+     * @param owner        The owner key of the lock.
+     * @param resource     The resource to check.
      * @return <em>True</em> if the lock exists.
      */
-    public boolean hasRead(Object key, Object resourceId);
+    public boolean hasRead(Object owner, Object resource);
 
     /**
-     * Checks if there is a write lock for lock key on resource object.
+     * Checks if there is a write lock for lock owner on resource object.
      * Returns true if so, else false.
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to check.
+     * @param owner        The owner key of the lock.
+     * @param resource     The resource to check.
      * @return <em>True</em> if the lock exists.
      */
-    public boolean hasWrite(Object key, Object resourceId);
+    public boolean hasWrite(Object owner, Object resource);
 
     /**
-     * Checks if there is a upgrade lock for lock key on resource object.
+     * Checks if there is a upgrade lock for lock owner on resource object.
      * Returns true if so, else false.
      *
-     * @param key            The owner key of the lock.
-     * @param resourceId     The resource to check.
+     * @param owner        The owner key of the lock.
+     * @param resource     The resource to check.
      * @return <em>True</em> if the lock exists.
      */
-    public boolean hasUpgrade(Object key, Object resourceId);
+    public boolean hasUpgrade(Object owner, Object resource);
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java?view=diff&rev=518416&r1=518415&r2=518416
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java
Wed Mar 14 18:13:07 2007
@@ -29,11 +29,7 @@
 /**
  * A {@link LockManager} implementation based on apache's commons-transaction
  * locking part.
- * <p/>
- * The timeout of locks is currently (OJB 1.0.2) not supported, maybe
- * in further versions.
  *
- * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
  * @version $Id$
  */
 public class LockManagerCommonsImpl implements LockManager, Configurable
@@ -75,6 +71,7 @@
 
     public void setLockTimeout(long timeout)
     {
+        log.debug("Set lock timeout to " + timeout + " ms");
         this.lockTimeout = timeout;
     }
 
@@ -85,6 +82,7 @@
 
     public void setBlockTimeout(long blockTimeout)
     {
+        log.debug("Set waiting block time to acquire a lock to " + blockTimeout + " ms");
         this.blockTimeout = blockTimeout;
     }
 
@@ -95,65 +93,83 @@
         msg.append("lock timeout: ").append(getLockTimeout()).append(" [ms]").append(eol);
         msg.append("block timeout: ").append(getBlockTimeout()).append(" [ms]").append(eol);
         msg.append("commons-tx lock-manger info ==> ").append(eol);
-        msg.append(lm);
+        msg.append(lm != null ? lm.toString() : "not initialized");
         return msg.toString();
     }
 
-    public boolean readLock(Object key, Object resourceId, int isolationLevel)
+    public boolean readLock(final Object owner, final Object resource, final int isolationLevel,
+                            final long lockTimeout, final long blockTimeout)
     {
-        return ignore(isolationLevel) || lm.readLock(key, resourceId, new Integer(isolationLevel),
blockTimeout);
+        return ignore(isolationLevel) || lm.readLock(owner, resource, new Integer(isolationLevel),
blockTimeout, lockTimeout);
     }
 
-    public boolean writeLock(Object key, Object resourceId, int isolationLevel)
+    public boolean readLock(final Object owner, final Object resource, final int isolationLevel)
     {
-        return ignore(isolationLevel) || lm.writeLock(key, resourceId, new Integer(isolationLevel),
blockTimeout);
+        return readLock(owner, resource, isolationLevel, lockTimeout, blockTimeout);
     }
 
-    public boolean upgradeLock(Object key, Object resourceId, int isolationLevel)
+    public boolean writeLock(final Object owner, final Object resource, final int isolationLevel,
+                            final long lockTimeout, final long blockTimeout)
     {
-        return ignore(isolationLevel) || lm.upgradeLock(key, resourceId, new Integer(isolationLevel),
blockTimeout);
+        return ignore(isolationLevel) || lm.writeLock(owner, resource, new Integer(isolationLevel),
blockTimeout, lockTimeout);
     }
 
-    public boolean releaseLock(Object key, Object resourceId)
+    public boolean writeLock(final Object owner, final Object resource, final int isolationLevel)
+    {
+        return writeLock(owner, resource, isolationLevel, lockTimeout, blockTimeout);
+    }
+
+    public boolean upgradeLock(final Object owner, final Object resource, final int isolationLevel,
+                            final long lockTimeout, final long blockTimeout)
+    {
+        return ignore(isolationLevel) || lm.upgradeLock(owner, resource, new Integer(isolationLevel),
blockTimeout, lockTimeout);
+    }
+
+    public boolean upgradeLock(final Object owner, final Object resource, final int isolationLevel)
+    {
+        return upgradeLock(owner, resource, isolationLevel, lockTimeout, blockTimeout);
+    }
+
+    public boolean releaseLock(Object owner, Object resourceId)
     {
         boolean result = true;
         try
         {
-            lm.release(key, resourceId);
+            lm.release(owner, resourceId);
         }
         catch(RuntimeException e)
         {
-            log.error("Can't release lock for owner key " + key + ", on resource " + resourceId,
e);
+            log.error("Can't release lock for owner " + owner + ", on resource " + resourceId,
e);
             result = false;
         }
         return result;
     }
 
-    public void releaseLocks(Object key)
+    public void releaseLocks(Object owner)
     {
         try
         {
-            lm.releaseAll(key);
+            lm.releaseAll(owner);
         }
         catch(RuntimeException e)
         {
-            log.error("Can't release all locks for owner key " + key, e);
+            log.error("Can't release all locks for owner " + owner, e);
         }
     }
 
-    public boolean hasRead(Object key, Object resourceId)
+    public boolean hasRead(Object owner, Object resourceId)
     {
-        return lm.hasRead(key, resourceId);
+        return lm.hasRead(owner, resourceId);
     }
 
-    public boolean hasWrite(Object key, Object resourceId)
+    public boolean hasWrite(Object owner, Object resourceId)
     {
-        return lm.hasWrite(key, resourceId);
+        return lm.hasWrite(owner, resourceId);
     }
 
-    public boolean hasUpgrade(Object key, Object resourceId)
+    public boolean hasUpgrade(Object owner, Object resourceId)
     {
-        return lm.hasUpgrade(key, resourceId);
+        return lm.hasUpgrade(owner, resourceId);
     }
 
 
@@ -167,10 +183,10 @@
      */
     final class OJBLockManager extends CommonsOJBLockManager
     {
-        public OJBLockManager(LoggerFacade logger, long timeoutMSecs, long checkThreshholdMSecs)
+        public OJBLockManager(LoggerFacade logger, long globalLockTimeoutMSecs, long checkThreshholdMSecs)
                 throws IllegalArgumentException
         {
-            super(logger, timeoutMSecs, checkThreshholdMSecs);
+            super(logger, globalLockTimeoutMSecs, checkThreshholdMSecs);
         }
 
         private CommonsOJBLockManager.OJBLock lookupLock(Object resourceId)
@@ -178,7 +194,7 @@
             return (CommonsOJBLockManager.OJBLock) getLock(resourceId);
         }
 
-        boolean readLock(Object key, Object resourceId, Integer isolationLevel, long timeout)
+        boolean readLock(Object owner, Object resourceId, Integer isolationLevel, long blockTimeout,
long lockTimeout)
         {
             /*
             arminw: Not sure what's the best way to go
@@ -191,48 +207,55 @@
             So I chose the 'tryLock' call for read locks which immediately return.
             */
             int lockLevel = mapLockLevelDependendOnIsolationLevel(isolationLevel, COMMON_READ_LOCK);
-            return tryLock(key, resourceId, lockLevel, true, isolationLevel);
+            boolean result = tryLock(owner, resourceId, lockLevel, true, isolationLevel);
+            if(result)
+            {
+                startGlobalTimeout(owner, lockTimeout);
+            }
+            return result;
         }
 
-        boolean writeLock(Object key, Object resourceId, Integer isolationLevel, long timeout)
+        boolean writeLock(Object owner, Object resourceId, Integer isolationLevel, long blockTimeout,
long lockTimeout)
         {
             try
             {
                 int lockLevel = mapLockLevelDependendOnIsolationLevel(isolationLevel, COMMON_WRITE_LOCK);
-                lock(key, resourceId, lockLevel, GenericLock.COMPATIBILITY_REENTRANT,
-                        false, timeout, isolationLevel);
+                lock(owner, resourceId, lockLevel, GenericLock.COMPATIBILITY_REENTRANT,
+                        false, blockTimeout, isolationLevel);
+                startGlobalTimeout(owner, lockTimeout);
                 return true;
             }
             catch(LockException e)
             {
-                if(log.isEnabledFor(Logger.INFO)) log.info("Can't get write lock for " +
key, e);
+                if(log.isEnabledFor(Logger.INFO)) log.info("Can't get write lock for " +
owner + ", " + e.getReason(), e);
                 return false;
             }
         }
 
-        boolean upgradeLock(Object key, Object resourceId, Integer isolationLevel, long timeout)
+        boolean upgradeLock(Object owner, Object resourceId, Integer isolationLevel, long
blockTimeout, long lockTimeout)
         {
             try
             {
                 int lockLevel = mapLockLevelDependendOnIsolationLevel(isolationLevel, COMMON_UPGRADE_LOCK);
-                lock(key, resourceId, lockLevel, GenericLock.COMPATIBILITY_REENTRANT,
-                        false, timeout, isolationLevel);
+                lock(owner, resourceId, lockLevel, GenericLock.COMPATIBILITY_REENTRANT,
+                        false, blockTimeout, isolationLevel);
+                startGlobalTimeout(owner, lockTimeout);
                 return true;
             }
             catch(LockException e)
             {
-                if(log.isEnabledFor(Logger.INFO)) log.info("Can't get upgrade lock for "
+ key, e);
+                if(log.isEnabledFor(Logger.INFO)) log.info("Can't get upgrade lock for "
+ owner + ", " + e.getReason(), e);
                 return false;
             }
         }
 
-        boolean hasRead(Object key, Object resourceId)
+        boolean hasRead(Object owner, Object resourceId)
         {
             CommonsOJBLockManager.OJBLock lock = lookupLock(resourceId);
             boolean result = false;
             if(lock != null)
             {
-                result = lock.hasRead(key);
+                result = lock.hasRead(owner);
             }
             return result;
         }
@@ -248,15 +271,20 @@
             return result;
         }
 
-        boolean hasUpgrade(Object key, Object resourceId)
+        boolean hasUpgrade(Object owner, Object resourceId)
         {
             CommonsOJBLockManager.OJBLock lock = lookupLock(resourceId);
             boolean result = false;
             if(lock != null)
             {
-                result = lock.hasUpgrade(key);
+                result = lock.hasUpgrade(owner);
             }
             return result;
+        }
+
+        public synchronized String toString()
+        {
+            return "[" + this.getClass().getName() + "] " + super.toString();
         }
     }
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java?view=diff&rev=518416&r1=518415&r2=518416
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java
Wed Mar 14 18:13:07 2007
@@ -81,7 +81,12 @@
         {
             throw new ConfigurationException("Invalid LockServlet Url was specified: " +
url, e);
         }
+    }
 
+    /** noop */
+    public void setBlockTimeout(long timeout)
+    {
+        log.info("Can't set global block-timeout, it's managed by the lock-servlet");
     }
 
     /**
@@ -91,7 +96,7 @@
      */
     public void setLockTimeout(long timeout)
     {
-        log.info("Can't set lock-timeout, it's managed by the lock-servlet");
+        log.info("Can't set global lock-timeout, it's managed by the lock-servlet");
     }
 
     public long getLockTimeout()
@@ -131,12 +136,6 @@
         }
     }
 
-    /** noop */
-    public void setBlockTimeout(long timeout)
-    {
-        log.info("Can't set lock-timeout, it's managed by the lock-servlet");
-    }
-
     public String getLockInfo()
     {
         LockInfo info = new LockInfo(METHOD_LOCK_INFO);
@@ -151,9 +150,16 @@
         }
     }
 
-    public boolean readLock(Object key, Object resourceId, int isolationLevel)
+    public boolean readLock(final Object owner, final Object resource, final int isolationLevel)
     {
-        LockInfo info = new LockInfo(key, resourceId, isolationLevel, METHOD_READ_LOCK);
+        return readLock(owner, resource, isolationLevel, 0, 0);
+    }
+
+    public boolean readLock(final Object owner, final Object resource, final int isolationLevel,
+                            final long lockTimeout, final long blockTimeout)
+    {
+        LockInfo info = new LockInfo(owner, resource, isolationLevel, METHOD_READ_LOCK,
+                lockTimeout, blockTimeout);
         try
         {
             byte[] requestBarr = serialize(info);
@@ -161,14 +167,14 @@
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot check read lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot get read lock for resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
-    public boolean releaseLock(Object key, Object resourceId)
+    public boolean releaseLock(final Object owner, final Object resource)
     {
-        LockInfo info = new LockInfo(key, resourceId, METHOD_RELEASE_SINGLE_LOCK);
+        LockInfo info = new LockInfo(owner, resource, METHOD_RELEASE_SINGLE_LOCK);
         try
         {
             byte[] requestBarr = serialize(info);
@@ -176,14 +182,14 @@
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot remove write lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot remove write lock for resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
-    public void releaseLocks(Object key)
+    public void releaseLocks(final Object owner)
     {
-        LockInfo info = new LockInfo(key, null, METHOD_RELEASE_LOCKS);
+        LockInfo info = new LockInfo(owner, null, METHOD_RELEASE_LOCKS);
         try
         {
             byte[] requestBarr = serialize(info);
@@ -191,13 +197,20 @@
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot release locks using owner key '" + key
+ "'", t);
+            throw new LockRuntimeException("Cannot release locks using owner '" + owner +
"'", t);
         }
     }
 
-    public boolean writeLock(Object key, Object resourceId, int isolationLevel)
+    public boolean writeLock(final Object owner, final Object resource, final int isolationLevel)
     {
-        LockInfo info = new LockInfo(key, resourceId, isolationLevel, METHOD_WRITE_LOCK);
+        return writeLock(owner, resource, isolationLevel, 0, 0);
+    }
+
+    public boolean writeLock(final Object owner, final Object resource, final int isolationLevel,
+                             final long lockTimeout, final long blockTimeout)
+    {
+        LockInfo info = new LockInfo(owner, resource, isolationLevel, METHOD_WRITE_LOCK,
+                lockTimeout, blockTimeout);
         try
         {
             byte[] requestBarr = serialize(info);
@@ -205,14 +218,21 @@
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot set write lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot set write lock for resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
-    public boolean upgradeLock(Object key, Object resourceId, int isolationLevel)
+    public boolean upgradeLock(final Object owner, final Object resource, final int isolationLevel)
+    {
+        return upgradeLock(owner, resource, isolationLevel, 0, 0);
+    }
+
+    public boolean upgradeLock(final Object owner, final Object resource, final int isolationLevel,
+                               final long lockTimeout, final long blockTimeout)
     {
-        LockInfo info = new LockInfo(key, resourceId, isolationLevel, METHOD_UPGRADE_LOCK);
+        LockInfo info = new LockInfo(owner, resource, isolationLevel, METHOD_UPGRADE_LOCK,
+                lockTimeout, blockTimeout);
         try
         {
             byte[] requestBarr = serialize(info);
@@ -220,50 +240,50 @@
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot set write lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot upgrade lock on resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
-    public boolean hasRead(Object key, Object resourceId)
+    public boolean hasRead(Object owner, Object resource)
     {
         try
         {
-            byte[] requestBarr = serialize(new LockInfo(key, resourceId, METHOD_CHECK_READ));
+            byte[] requestBarr = serialize(new LockInfo(owner, resource, METHOD_CHECK_READ));
             return performRequest(requestBarr);
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot check read lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot check read lock for resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
-    public boolean hasWrite(Object key, Object resourceId)
+    public boolean hasWrite(Object owner, Object resource)
     {
         try
         {
-            byte[] requestBarr = serialize(new LockInfo(key, resourceId, METHOD_CHECK_WRITE));
+            byte[] requestBarr = serialize(new LockInfo(owner, resource, METHOD_CHECK_WRITE));
             return performRequest(requestBarr);
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot check write lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot check write lock for resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
-    public boolean hasUpgrade(Object key, Object resourceId)
+    public boolean hasUpgrade(Object owner, Object resource)
     {
         try
         {
-            byte[] requestBarr = serialize(new LockInfo(key, resourceId, METHOD_CHECK_UPGRADE));
+            byte[] requestBarr = serialize(new LockInfo(owner, resource, METHOD_CHECK_UPGRADE));
             return performRequest(requestBarr);
         }
         catch(Throwable t)
         {
-            throw new LockRuntimeException("Cannot check write lock for '"
-                    + resourceId + "' using key '" + key + "'", t);
+            throw new LockRuntimeException("Cannot check write lock for resource '"
+                    + resource + "' using owner '" + owner + "'", t);
         }
     }
 
@@ -396,29 +416,34 @@
 
     public static final class LockInfo implements Serializable
     {
-        public String key;
+        public String owner;
         public String resourceId;
         public int isolationLevel;
         public byte methodName;
+        public long blockTimeout;
+        public long lockTimeout;
 
-        public LockInfo(byte methodName)
+        public LockInfo(final byte methodName)
         {
             this.methodName = methodName;
         }
 
-        public LockInfo(Object key, Object resourceId, byte methodName)
+        public LockInfo(final Object owner, final Object resourceId, final byte methodName)
         {
-            this.key = key != null ? key.toString() : null;
+            this.owner = owner != null ? owner.toString() : null;
             this.resourceId = resourceId != null ? resourceId.toString() : null;
             this.methodName = methodName;
         }
 
-        public LockInfo(Object key, Object resourceId, int isolationLevel, byte methodName)
+        public LockInfo(final Object owner, final Object resourceId, final int isolationLevel,
+                        final byte methodName, final long lockTimeout, final long blockTimeout)
         {
-            this.key = key != null ? key.toString() : null;
+            this.owner = owner != null ? owner.toString() : null;
             this.resourceId = resourceId != null ? resourceId.toString() : null;
             this.isolationLevel = isolationLevel;
             this.methodName = methodName;
+            this.lockTimeout = lockTimeout;
+            this.blockTimeout = blockTimeout;
         }
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java?view=diff&rev=518416&r1=518415&r2=518416
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java
Wed Mar 14 18:13:07 2007
@@ -43,12 +43,12 @@
  */
 public class LockManagerServlet extends HttpServlet
 {
-    protected static LockManager lockmanager;
     static final String STR_LOCK_TIMEOUT = "lockTimeout";
     static final String STR_BLOCK_TIMEOUT = "blockTimeout";
     static final String STR_LOCK_MANAGER = "lockManager";
     private static final String prefix = "[ojb-lockserver] ";
 
+    protected static LockManager lockmanager;
     private static long numRequests;
     private static Throwable lastError = null;
 
@@ -82,7 +82,7 @@
                 {
                     Long lockTimeout = NumberUtils.createLong(strTimeout);
                     lockmanager.setLockTimeout(lockTimeout.longValue());
-                    System.out.println(prefix + "Set lock-timeout=" + lockTimeout);
+                    //System.out.println(prefix + "Set lock-timeout=" + lockTimeout);
                 }
                 catch(Exception e)
                 {
@@ -101,7 +101,7 @@
                 {
                     Long blockTimeout = NumberUtils.createLong(strBlock);
                     lockmanager.setBlockTimeout(blockTimeout.longValue());
-                    System.out.println(prefix + "Set block-timeout=" + blockTimeout);
+                    //System.out.println(prefix + "Set block-timeout=" + blockTimeout);
                 }
                 catch(Exception e)
                 {
@@ -190,44 +190,49 @@
                 {
                     case LockManagerRemoteImpl.METHOD_READ_LOCK:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.readLock(info.key,
info.resourceId, info.isolationLevel));
+                        result = BooleanUtils.toBooleanObject(lockmanager.readLock(info.owner,
info.resourceId, info.isolationLevel,
+                                info.lockTimeout > 0 ? info.lockTimeout : lockmanager.getLockTimeout(),
+                                info.blockTimeout > 0 ? info.blockTimeout : lockmanager.getBlockTimeout()));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_RELEASE_SINGLE_LOCK:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.releaseLock(info.key,
info.resourceId));
+                        result = BooleanUtils.toBooleanObject(lockmanager.releaseLock(info.owner,
info.resourceId));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_RELEASE_LOCKS:
                     {
-                        lockmanager.releaseLocks(info.key);
+                        lockmanager.releaseLocks(info.owner);
                         result = Boolean.TRUE;
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_WRITE_LOCK:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.writeLock(info.key,
info.resourceId,
-                                info.isolationLevel));
+                        result = BooleanUtils.toBooleanObject(lockmanager.writeLock(info.owner,
info.resourceId, info.isolationLevel,
+                                info.lockTimeout > 0 ? info.lockTimeout : lockmanager.getLockTimeout(),
+                                info.blockTimeout > 0 ? info.blockTimeout : lockmanager.getBlockTimeout()));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_UPGRADE_LOCK:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.upgradeLock(info.key,
info.resourceId, info.isolationLevel));
+                        result = BooleanUtils.toBooleanObject(lockmanager.upgradeLock(info.owner,
info.resourceId, info.isolationLevel,
+                                info.lockTimeout > 0 ? info.lockTimeout : lockmanager.getLockTimeout(),
+                                info.blockTimeout > 0 ? info.blockTimeout : lockmanager.getBlockTimeout()));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_CHECK_READ:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.hasRead(info.key,
info.resourceId));
+                        result = BooleanUtils.toBooleanObject(lockmanager.hasRead(info.owner,
info.resourceId));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_CHECK_WRITE:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.hasWrite(info.key,
info.resourceId));
+                        result = BooleanUtils.toBooleanObject(lockmanager.hasWrite(info.owner,
info.resourceId));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_CHECK_UPGRADE:
                     {
-                        result = BooleanUtils.toBooleanObject(lockmanager.hasUpgrade(info.key,
info.resourceId));
+                        result = BooleanUtils.toBooleanObject(lockmanager.hasUpgrade(info.owner,
info.resourceId));
                         break;
                     }
                     case LockManagerRemoteImpl.METHOD_LOCK_INFO:

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/web.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/web.xml?view=diff&rev=518416&r1=518415&r2=518416
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/web.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/web.xml Wed Mar 14 18:13:07 2007
@@ -31,13 +31,15 @@
         <init-param>
             <param-name>lockManager</param-name>
             <param-value>org.apache.ojb.broker.locking.LockManagerInMemoryImpl</param-value>
+            <!--<param-value>org.apache.ojb.broker.locking.LockManagerCommonsImpl</param-value>-->
         </init-param>
         <init-param>
             <param-name>lockTimeout</param-name>
-            <!-- set lock timeout to 10 minutes (setting in [ms]) -->
-            <param-value>600000</param-value>
+            <!-- set lock timeout to 2 minutes (setting in [ms]) -->
+            <param-value>120000</param-value>
         </init-param>
         <init-param>
+            <!-- set block timeout to 1 sec (setting in [ms], if supported by the Impl.)
-->
             <param-name>blockTimeout</param-name>
             <param-value>1000</param-value>
         </init-param>



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


Mime
View raw message