activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r679436 - /activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java
Date Thu, 24 Jul 2008 15:29:31 GMT
Author: jstrachan
Date: Thu Jul 24 08:29:30 2008
New Revision: 679436

URL: http://svn.apache.org/viewvc?rev=679436&view=rev
Log:
cleaned up the tryLock() a bit to ensure we always unlock properly on errors and exceptions
etc

Modified:
    activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java

Modified: activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java?rev=679436&r1=679435&r2=679436&view=diff
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java
(original)
+++ activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java
Thu Jul 24 08:29:30 2008
@@ -92,22 +92,29 @@
     }
 
     public boolean tryLock() {
-        if (threadLock.tryLock()) {
-            while (true) {
+        boolean unlockThreadLock = false;
+        try {
+            if (threadLock.tryLock()) {
+                unlockThreadLock = true;
                 try {
-                    if (protocol.isOwner()) {
+                    if (protocol.isOwner() || protocol.acquire()) {
+                        unlockThreadLock = false;
                         return true;
                     }
-                    return protocol.acquire();
                 } catch (KeeperException e) {
-                    threadLock.unlock();
                     throw new RuntimeKeeperException("Failed to acquire remote lock: " +
e, e);
                 } catch (InterruptedException e) {
+                    // lets continue through the while loop
                     LOG.debug("Caught: " + e, e);
                 }
             }
+            return false;
+        }
+        finally {
+            if (unlockThreadLock) {
+                threadLock.unlock();
+            }
         }
-        return false;
     }
 
     public boolean tryLock(long timeout, TimeUnit timeUnit) throws InterruptedException {



Mime
View raw message