ozeigermann 2005/01/07 04:26:14
Modified: transaction/src/java/org/apache/commons/transaction/locking
GenericLockManager.java
Log:
Reset effective timeout when releasing all locks. Otherwise no further
operations would have been possible.
Revision Changes Path
1.11 +20 -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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- GenericLockManager.java 23 Dec 2004 15:42:34 -0000 1.10
+++ GenericLockManager.java 7 Jan 2005 12:26:14 -0000 1.11
@@ -52,7 +52,10 @@
/** Maps resourceId to lock. */
protected Map globalLocks = new HashMap();
- /** Maps onwerId to global time outs. */
+ /** Maps onwerId to global effective time outs (i.e. the time the lock
will time out). */
+ protected Map effectiveGlobalTimeouts = Collections.synchronizedMap(new
HashMap());
+
+ /** Maps onwerId to global time outs (i.e. the miliseconds before
timeout). */
protected Map globalTimeouts = Collections.synchronizedMap(new
HashMap());
protected Set timedOutOwners = Collections.synchronizedSet(new
HashSet());
@@ -115,7 +118,8 @@
public void setGlobalTimeout(Object ownerId, long timeoutMSecs) {
long now = System.currentTimeMillis();
long timeout = now + timeoutMSecs;
- globalTimeouts.put(ownerId, new Long(timeout));
+ effectiveGlobalTimeouts.put(ownerId, new Long(timeout));
+ globalTimeouts.put(ownerId, new Long(timeoutMSecs));
}
/**
@@ -284,6 +288,11 @@
}
// reset time out status for this owner
timedOutOwners.remove(ownerId);
+ // and start a new time out cycle
+ Long timeOut = (Long) globalTimeouts.get(ownerId);
+ if (timeOut != null) {
+ setGlobalTimeout(ownerId, timeOut.longValue());
+ }
}
/**
@@ -367,8 +376,8 @@
protected boolean releaseTimedOutOwners() {
boolean released = false;
- synchronized (globalTimeouts) {
- for (Iterator it = globalTimeouts.entrySet().iterator();
it.hasNext();) {
+ synchronized (effectiveGlobalTimeouts) {
+ for (Iterator it =
effectiveGlobalTimeouts.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Object ownerId = entry.getKey();
long timeout = ((Long)entry.getValue()).longValue();
@@ -384,7 +393,7 @@
}
protected boolean timeOut(Object ownerId) {
- Long timeout = (Long)globalTimeouts.get(ownerId);
+ Long timeout = (Long)effectiveGlobalTimeouts.get(ownerId);
long now = System.currentTimeMillis();
if (timeout != null && timeout.longValue() < now) {
releaseAll(ownerId);
@@ -399,8 +408,8 @@
long minTimeout = -1;
long now = System.currentTimeMillis();
if (conflicts != null) {
- synchronized (globalTimeouts) {
- for (Iterator it = globalTimeouts.entrySet().iterator();
it.hasNext();) {
+ synchronized (effectiveGlobalTimeouts) {
+ for (Iterator it =
effectiveGlobalTimeouts.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Object ownerId = entry.getKey();
if (conflicts.contains(ownerId)) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]