curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammcken...@apache.org
Subject [1/5] git commit: CURATOR-140: Allow InterProcessReadWriteLock consumer to set lock node data.
Date Tue, 04 Nov 2014 00:11:08 GMT
Repository: curator
Updated Branches:
  refs/heads/master 3e4626237 -> 1cd052245


CURATOR-140: Allow InterProcessReadWriteLock consumer to set lock node data.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/77a1afbc
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/77a1afbc
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/77a1afbc

Branch: refs/heads/master
Commit: 77a1afbcc074d9ef87ba3bfc7d3cb641ad2f727e
Parents: 1e9b76e
Author: Brien Wheeler <brien@Briens-MacBook-Pro.local>
Authored: Fri Oct 24 12:33:16 2014 -0400
Committer: Brien Wheeler <brien@Briens-MacBook-Pro.local>
Committed: Fri Oct 24 12:33:16 2014 -0400

----------------------------------------------------------------------
 .../locks/InterProcessReadWriteLock.java        | 34 +++++++++++++++++---
 1 file changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/77a1afbc/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessReadWriteLock.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessReadWriteLock.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessReadWriteLock.java
index d5b0036..3a0dc44 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessReadWriteLock.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessReadWriteLock.java
@@ -22,6 +22,8 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import org.apache.curator.framework.CuratorFramework;
+
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -74,11 +76,13 @@ public class InterProcessReadWriteLock
     private static class InternalInterProcessMutex extends InterProcessMutex
     {
         private final String lockName;
+        private final byte[] lockData;
 
-        InternalInterProcessMutex(CuratorFramework client, String path, String lockName,
int maxLeases, LockInternalsDriver driver)
+        InternalInterProcessMutex(CuratorFramework client, String path, String lockName,
byte[] lockData, int maxLeases, LockInternalsDriver driver)
         {
             super(client, path, lockName, maxLeases, driver);
             this.lockName = lockName;
+            this.lockData = lockData;
         }
 
         @Override
@@ -99,19 +103,38 @@ public class InterProcessReadWriteLock
             );
             return ImmutableList.copyOf(filtered);
         }
+
+        @Override
+        protected byte[] getLockNodeBytes()
+        {
+            return lockData;
+        }
     }
 
-    /**
-     * @param client the client
-     * @param basePath path to use for locking
-     */
+  /**
+    * @param client the client
+    * @param basePath path to use for locking
+    */
     public InterProcessReadWriteLock(CuratorFramework client, String basePath)
     {
+        this(client, basePath, null);
+    }
+
+  /**
+    * @param client the client
+    * @param basePath path to use for locking
+    * @param lockData the data to store in the lock nodes
+    */
+    public InterProcessReadWriteLock(CuratorFramework client, String basePath, byte[] lockData)
+    {
+        lockData = (lockData == null) ? null : Arrays.copyOf(lockData, lockData.length);
+
         writeMutex = new InternalInterProcessMutex
         (
             client,
             basePath,
             WRITE_LOCK_NAME,
+            lockData,
             1,
             new SortingLockInternalsDriver()
             {
@@ -128,6 +151,7 @@ public class InterProcessReadWriteLock
             client,
             basePath,
             READ_LOCK_NAME,
+            lockData,
             Integer.MAX_VALUE,
             new SortingLockInternalsDriver()
             {


Mime
View raw message