You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2014/11/04 01:11:08 UTC

[1/5] git commit: CURATOR-140: Allow InterProcessReadWriteLock consumer to set lock node data.

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 <br...@Briens-MacBook-Pro.local>
Authored: Fri Oct 24 12:33:16 2014 -0400
Committer: Brien Wheeler <br...@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()
             {


[4/5] git commit: Merge branch 'CURATOR-140' of https://github.com/sqrrldata/curator into CURATOR-140

Posted by ca...@apache.org.
Merge branch 'CURATOR-140' of https://github.com/sqrrldata/curator into CURATOR-140


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

Branch: refs/heads/master
Commit: 256affe4095dea464e7a4c149adef50d3104e93f
Parents: fe87931 b468f42
Author: Cameron McKenzie <ca...@unico.com.au>
Authored: Tue Nov 4 07:46:25 2014 +1100
Committer: Cameron McKenzie <ca...@unico.com.au>
Committed: Tue Nov 4 07:46:25 2014 +1100

----------------------------------------------------------------------
 .../locks/TestInterProcessReadWriteLock.java    | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
----------------------------------------------------------------------



[5/5] git commit: Merge branch 'CURATOR-140'

Posted by ca...@apache.org.
Merge branch 'CURATOR-140'


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

Branch: refs/heads/master
Commit: 1cd052245b1b4a25658cf3202b5dba520d997d78
Parents: 3e46262 256affe
Author: Cameron McKenzie <ca...@unico.com.au>
Authored: Tue Nov 4 11:10:08 2014 +1100
Committer: Cameron McKenzie <ca...@unico.com.au>
Committed: Tue Nov 4 11:10:08 2014 +1100

----------------------------------------------------------------------
 .../locks/InterProcessReadWriteLock.java        | 34 +++++++++++++++++---
 .../locks/TestInterProcessReadWriteLock.java    | 33 +++++++++++++++++++
 2 files changed, 62 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[2/5] git commit: Merge branch 'CURATOR-140' of https://github.com/sqrrldata/curator into CURATOR-140

Posted by ca...@apache.org.
Merge branch 'CURATOR-140' of https://github.com/sqrrldata/curator into CURATOR-140


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

Branch: refs/heads/master
Commit: fe879313d638f70be8911499a244f85ddbe7af9a
Parents: 1c194b4 77a1afb
Author: Cameron McKenzie <ca...@unico.com.au>
Authored: Thu Oct 30 09:32:32 2014 +1100
Committer: Cameron McKenzie <ca...@unico.com.au>
Committed: Thu Oct 30 09:32:32 2014 +1100

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



[3/5] git commit: Add unit test for setting node data in InterProcessReadWriteLock.

Posted by ca...@apache.org.
Add unit test for setting node data in InterProcessReadWriteLock.


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

Branch: refs/heads/master
Commit: b468f42382ab2d4813137215c20de9c36ef117c1
Parents: 77a1afb
Author: Brien Wheeler <br...@Briens-MacBook-Pro.local>
Authored: Mon Nov 3 14:46:17 2014 -0500
Committer: Brien Wheeler <br...@Briens-MacBook-Pro.local>
Committed: Mon Nov 3 14:46:17 2014 -0500

----------------------------------------------------------------------
 .../locks/TestInterProcessReadWriteLock.java    | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/b468f423/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessReadWriteLock.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessReadWriteLock.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessReadWriteLock.java
index 23c9eca..f7636ed 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessReadWriteLock.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessReadWriteLock.java
@@ -261,6 +261,39 @@ public class TestInterProcessReadWriteLock extends BaseClassForTests
         Assert.assertTrue(maxConcurrentCount.get() > 1);
     }
 
+    @Test
+    public void     testSetNodeData() throws Exception
+    {
+        CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+
+        try
+        {
+            client.start();
+
+            final byte[] nodeData = new byte[] { 1, 2, 3, 4 };
+
+            InterProcessReadWriteLock   lock = new InterProcessReadWriteLock(client, "/lock", nodeData);
+
+            // mutate passed-in node data, lock has made copy
+            nodeData[0] = 5;
+
+            lock.writeLock().acquire();
+
+            List<String> children = client.getChildren().forPath("/lock");
+            Assert.assertEquals(1, children.size());
+
+            byte dataInZk[] = client.getData().forPath("/lock/" + children.get(0));
+            Assert.assertNotNull(dataInZk);
+            Assert.assertEquals(new byte[] { 1, 2, 3, 4 }, dataInZk);
+
+            lock.writeLock().release();
+        }
+        finally
+        {
+            CloseableUtils.closeQuietly(client);
+        }
+    }
+
     private void doLocking(InterProcessLock lock, AtomicInteger concurrentCount, AtomicInteger maxConcurrentCount, Random random, int maxAllowed) throws Exception
     {
         try