activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r679507 - /activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/locks/WriteLock.java
Date Thu, 24 Jul 2008 19:33:43 GMT
Author: jstrachan
Date: Thu Jul 24 12:33:42 2008
New Revision: 679507

URL: http://svn.apache.org/viewvc?rev=679507&view=rev
Log:
simplified the WriteLock code still further

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=679507&r1=679506&r2=679507&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 12:33:42 2008
@@ -64,7 +64,7 @@
     }
 
     protected void notifyMutex() {
-        synchronized(mutex) {
+        synchronized (mutex) {
             mutex.notify();
         }
     }
@@ -90,32 +90,25 @@
     }
 
     public boolean tryLock() {
-        boolean unlockThreadLock = false;
-        try {
-            if (threadLock.tryLock()) {
-                unlockThreadLock = true;
-                try {
-                    if (protocol.isOwner() || protocol.acquire()) {
-                        unlockThreadLock = false;
-                        return true;
-                    }
-                } catch (KeeperException e) {
-                    throw new RuntimeKeeperException("Failed to acquire remote lock: " +
e, e);
-                } catch (InterruptedException e) {
-                    // lets continue through the while loop
-                    LOG.debug("Caught: " + e, e);
-                }
+        if (threadLock.tryLock()) {
+            try {
+                return protocol.isOwner() || protocol.acquire();
+            } catch (KeeperException e) {
+                throw new RuntimeKeeperException("Failed to acquire remote lock: " + e, e);
+            } catch (InterruptedException e) {
+                LOG.debug("Caught: " + e, e);
+                return false;
             }
-            return false;
-        }
-        finally {
-            if (unlockThreadLock) {
-                threadLock.unlock();
+            finally {
+                if (!protocol.isOwner()) {
+                    threadLock.unlock();
+                }
             }
         }
+        return false;
     }
-    
-    
+
+
     public boolean tryLock(long timeout, TimeUnit timeUnit) throws InterruptedException {
         // TODO this implementation will typically wait too long!
         if (threadLock.tryLock(timeout, timeUnit)) {
@@ -126,20 +119,20 @@
                 if (protocol.acquire()) {
                     return true;
                 }
- 
+
                 // Wait till we get notified, we might become the owner
-                synchronized( mutex ) {
+                synchronized (mutex) {
                     mutex.wait(timeUnit.toMillis(timeout));
                     if (protocol.isOwner()) {
                         return true;
                     }
                 }
 
-           } catch (KeeperException e) {
+            } catch (KeeperException e) {
                 throw new RuntimeKeeperException("Failed to acquire remote lock: " + e, e);
-           } finally {
+            } finally {
                 if (!protocol.isOwner()) {
-                   threadLock.unlock();
+                    threadLock.unlock();
                 }
             }
         }



Mime
View raw message