You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2007/03/15 02:13:42 UTC
svn commit: r518417 - in /db/ojb/trunk/src:
java/org/apache/ojb/broker/locking/ test/org/apache/ojb/
Author: arminw
Date: Wed Mar 14 18:13:42 2007
New Revision: 518417
URL: http://svn.apache.org/viewvc?view=rev&rev=518417
Log:
add new methods to locking-api, adapt and improve existing LockManager-impl classes
Modified:
db/ojb/trunk/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java
db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManager.java
db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java
db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java
db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java
db/ojb/trunk/src/test/org/apache/ojb/web.xml
Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java?view=diff&rev=518417&r1=518416&r2=518417
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/locking/CommonsOJBLockManager.java Wed Mar 14 18:13:42 2007
@@ -1,12 +1,6 @@
package org.apache.ojb.broker.locking;
-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;
-
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +15,14 @@
* limitations under the License.
*/
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+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;
+
/**
* Extension of {@link org.apache.commons.transaction.locking.GenericLockManager} to
* support all locking isolation level defined in OJB locking api and a provider of
@@ -32,7 +34,6 @@
* {@link #createIsolationLevel(Object, IsolationLevels, 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,12 +42,20 @@
static final int COMMON_WRITE_LOCK = 107;
static final int COMMON_UPGRADE_LOCK = 113;
- private final Object sync = new Object();
-
- 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();
}
/**
@@ -149,7 +158,7 @@
*/
public OJBLock atomicGetOrCreateLock(Object resourceId, Object isolationLevel)
{
- synchronized(sync)
+ synchronized(globalLocks)
{
MultiLevelLock lock = getLock(resourceId);
if(lock == null)
@@ -170,7 +179,7 @@
protected GenericLock createLock(Object resourceId, IsolationLevels isolationLevel)
{
- synchronized(sync)
+ synchronized(globalLocks)
{
if(isolationLevel != null)
{
Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManager.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManager.java?view=diff&rev=518417&r1=518416&r2=518417
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManager.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManager.java Wed Mar 14 18:13:42 2007
@@ -87,82 +87,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, IsolationLevels isolationLevel);
+ public boolean readLock(Object owner, Object resource, IsolationLevels 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, IsolationLevels 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, IsolationLevels 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, IsolationLevels 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, IsolationLevels isolationLevel);
+ public boolean upgradeLock(Object owner, Object resource, IsolationLevels 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, IsolationLevels isolationLevel);
+ public boolean upgradeLock(Object owner, Object resource, IsolationLevels 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/trunk/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java?view=diff&rev=518417&r1=518416&r2=518417
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerCommonsImpl.java Wed Mar 14 18:13:42 2007
@@ -62,6 +62,7 @@
public void setLockTimeout(long timeout)
{
+ log.debug("Set lock timeout to " + timeout + " ms");
this.lockTimeout = timeout;
}
@@ -72,74 +73,94 @@
public void setBlockTimeout(long blockTimeout)
{
+ log.debug("Set waiting block time to acquire a lock to " + blockTimeout + " ms");
this.blockTimeout = blockTimeout;
}
public String getLockInfo()
{
String eol = SystemUtils.LINE_SEPARATOR;
- StringBuffer msg = new StringBuffer("Class: " + LockManagerCommonsImpl.class.getName() + eol)
- .append("lock timeout: ").append(getLockTimeout()).append(" [ms]").append(eol)
- .append("block timeout: ").append(getBlockTimeout()).append(" [ms]").append(eol)
- .append("commons-tx lock-manger info ==> ").append(eol).append(lm);
+ StringBuffer msg = new StringBuffer("Class: " + LockManagerCommonsImpl.class.getName() + eol);
+ 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 != null ? lm.toString() : "not initialized");
return msg.toString();
}
- public boolean readLock(Object key, Object resourceId, IsolationLevels isolationLevel)
+ public boolean readLock(final Object owner, final Object resource, final IsolationLevels isolationLevel,
+ final long lockTimeout, final long blockTimeout)
{
- return isolationLevel.ignoreForLock() || lm.readLock(key, resourceId, isolationLevel, blockTimeout);
+ return isolationLevel.ignoreForLock() || lm.readLock(owner, resource, isolationLevel, blockTimeout, lockTimeout);
}
- public boolean writeLock(Object key, Object resourceId, IsolationLevels isolationLevel)
+ public boolean readLock(final Object owner, final Object resource, final IsolationLevels isolationLevel)
{
- return isolationLevel.ignoreForLock() || lm.writeLock(key, resourceId,isolationLevel, blockTimeout);
+ return readLock(owner, resource, isolationLevel, lockTimeout, blockTimeout);
}
- public boolean upgradeLock(Object key, Object resourceId, IsolationLevels isolationLevel)
+ public boolean writeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel,
+ final long lockTimeout, final long blockTimeout)
{
- return isolationLevel.ignoreForLock() || lm.upgradeLock(key, resourceId, isolationLevel, blockTimeout);
+ return isolationLevel.ignoreForLock() || lm.writeLock(owner, resource, isolationLevel, blockTimeout, lockTimeout);
}
- public boolean releaseLock(Object key, Object resourceId)
+ public boolean writeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel)
+ {
+ return writeLock(owner, resource, isolationLevel, lockTimeout, blockTimeout);
+ }
+
+ public boolean upgradeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel,
+ final long lockTimeout, final long blockTimeout)
+ {
+ return isolationLevel.ignoreForLock() || lm.upgradeLock(owner, resource, isolationLevel, blockTimeout, lockTimeout);
+ }
+
+ public boolean upgradeLock(final Object owner, final Object resource, final IsolationLevels 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);
}
@@ -153,10 +174,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)
@@ -164,7 +185,7 @@
return (CommonsOJBLockManager.OJBLock) getLock(resourceId);
}
- boolean readLock(Object key, Object resourceId, IsolationLevels isolationLevel, long timeout)
+ boolean readLock(Object owner, Object resourceId, IsolationLevels isolationLevel, long blockTimeout, long lockTimeout)
{
/*
arminw: Not sure what's the best way to go
@@ -177,48 +198,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, IsolationLevels isolationLevel, long timeout)
+ boolean writeLock(Object owner, Object resourceId, IsolationLevels 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, IsolationLevels isolationLevel, long timeout)
+ boolean upgradeLock(Object owner, Object resourceId, IsolationLevels 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;
}
@@ -234,15 +262,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/trunk/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java?view=diff&rev=518417&r1=518416&r2=518417
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerRemoteImpl.java Wed Mar 14 18:13:42 2007
@@ -84,6 +84,12 @@
}
}
+ /** noop */
+ public void setBlockTimeout(long timeout)
+ {
+ log.info("Can't set global block-timeout, it's managed by the lock-servlet");
+ }
+
/**
* noop
*
@@ -91,7 +97,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 +137,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,15 +151,16 @@
}
}
- public boolean readLock(Object key, Object resourceId, IsolationLevels isolationLevel)
+ public boolean readLock(final Object owner, final Object resource, final IsolationLevels isolationLevel)
{
- if(isolationLevel.ignoreForLock())
- {
- return true;
+ return readLock(owner, resource, isolationLevel, 0, 0);
}
- else
+
+ public boolean readLock(final Object owner, final Object resource, final IsolationLevels isolationLevel,
+ final long lockTimeout, final long blockTimeout)
{
- LockInfo info = new LockInfo(key, resourceId, isolationLevel.getValue(), METHOD_READ_LOCK);
+ LockInfo info = new LockInfo(owner, resource, isolationLevel, METHOD_READ_LOCK,
+ lockTimeout, blockTimeout);
try
{
byte[] requestBarr = serialize(info);
@@ -167,15 +168,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);
@@ -183,14 +183,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);
@@ -198,19 +198,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, IsolationLevels isolationLevel)
+ public boolean writeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel)
{
- if(isolationLevel.ignoreForLock())
- {
- return true;
+ return writeLock(owner, resource, isolationLevel, 0, 0);
}
- else
+
+ public boolean writeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel,
+ final long lockTimeout, final long blockTimeout)
{
- LockInfo info = new LockInfo(key, resourceId, isolationLevel.getValue(), METHOD_WRITE_LOCK);
+ LockInfo info = new LockInfo(owner, resource, isolationLevel, METHOD_WRITE_LOCK,
+ lockTimeout, blockTimeout);
try
{
byte[] requestBarr = serialize(info);
@@ -218,21 +219,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, IsolationLevels isolationLevel)
+ public boolean upgradeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel)
{
- if(isolationLevel.ignoreForLock())
- {
- return true;
+ return upgradeLock(owner, resource, isolationLevel, 0, 0);
}
- else
+
+ public boolean upgradeLock(final Object owner, final Object resource, final IsolationLevels isolationLevel,
+ final long lockTimeout, final long blockTimeout)
{
- LockInfo info = new LockInfo(key, resourceId, isolationLevel.getValue(), METHOD_UPGRADE_LOCK);
+ LockInfo info = new LockInfo(owner, resource, isolationLevel, METHOD_UPGRADE_LOCK,
+ lockTimeout, blockTimeout);
try
{
byte[] requestBarr = serialize(info);
@@ -240,51 +241,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);
}
}
@@ -417,29 +417,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 IsolationLevels 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.isolationLevel = isolationLevel.getValue();
this.methodName = methodName;
+ this.lockTimeout = lockTimeout;
+ this.blockTimeout = blockTimeout;
}
}
}
Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java?view=diff&rev=518417&r1=518416&r2=518417
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/locking/LockManagerServlet.java Wed Mar 14 18:13:42 2007
@@ -35,16 +35,20 @@
/**
- * @author Thomas Mahler
+ * OJB's locking server servlet used to perform distributed lock requests from different
+ * nodes - internal this class use a {@link LockManagerInMemoryImpl} instance
+ * to manage the lock objects.
+ *
+ * @version $Id: $
*/
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;
@@ -78,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)
{
@@ -97,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)
{
@@ -186,45 +190,49 @@
{
case LockManagerRemoteImpl.METHOD_READ_LOCK:
{
- result = BooleanUtils.toBooleanObject(lockmanager.readLock(info.key, info.resourceId, IsolationLevels.getEnum(info.isolationLevel)));
+ result = BooleanUtils.toBooleanObject(lockmanager.readLock(info.owner, info.resourceId, IsolationLevels.getEnum(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,
- IsolationLevels.getEnum(info.isolationLevel)));
+ result = BooleanUtils.toBooleanObject(lockmanager.writeLock(info.owner, info.resourceId, IsolationLevels.getEnum(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, IsolationLevels.getEnum(info.isolationLevel)));
+ result = BooleanUtils.toBooleanObject(lockmanager.upgradeLock(info.owner, info.resourceId, IsolationLevels.getEnum(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/trunk/src/test/org/apache/ojb/web.xml
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/web.xml?view=diff&rev=518417&r1=518416&r2=518417
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/web.xml (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/web.xml Wed Mar 14 18:13:42 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