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 2015/08/25 06:08:25 UTC

[05/50] curator git commit: Don't directly link to CreateMode.CONTAINER. Get it via reflection to avoid link issues with different versions of ZooKeeper

Don't directly link to CreateMode.CONTAINER. Get it via reflection to avoid link issues with different versions of ZooKeeper


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

Branch: refs/heads/CURATOR-167
Commit: d492f8c1ab6243b49f30b27754bf6a1cff3b80fe
Parents: 04ae811
Author: randgalt <ra...@apache.org>
Authored: Tue May 19 14:56:30 2015 -0700
Committer: randgalt <ra...@apache.org>
Committed: Tue May 19 14:56:30 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/curator/utils/ZKPaths.java  | 36 ++++++++++++++++++--
 1 file changed, 33 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/d492f8c1/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
index 3a68b5b..526f705 100644
--- a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
+++ b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
@@ -26,6 +26,8 @@ import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.ACL;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import java.util.Collections;
 import java.util.List;
 
@@ -35,8 +37,31 @@ public class ZKPaths
      * Zookeeper's path separator character.
      */
     public static final String PATH_SEPARATOR = "/";
-    
-    
+
+    private static class CreatModeHolder
+    {
+        private static final Logger log = LoggerFactory.getLogger(ZKPaths.class);
+        private static final CreateMode containerCreateMode;
+
+        static
+        {
+            CreateMode localCreateMode = CreateMode.PERSISTENT;
+            for ( CreateMode createMode : CreateMode.class.getEnumConstants() )
+            {
+                if ( createMode.name().equals("CONTAINER") )
+                {
+                    localCreateMode = createMode;
+                    break;
+                }
+            }
+            if ( localCreateMode == CreateMode.PERSISTENT )
+            {
+                log.warn("The version of ZooKeeper being used doesn't support Container nodes. CreateMode.PERSISTENT will be used instead");
+            }
+            containerCreateMode = localCreateMode;
+        }
+    }
+
     /**
      * Apply the namespace to the given path
      *
@@ -246,7 +271,7 @@ public class ZKPaths
                     {
                         acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
                     }
-                    zookeeper.create(subPath, new byte[0], acl, asContainers ? CreateMode.CONTAINER : CreateMode.PERSISTENT);
+                    zookeeper.create(subPath, new byte[0], acl, getCreateMode(asContainers));
                 }
                 catch ( KeeperException.NodeExistsException e )
                 {
@@ -414,4 +439,9 @@ public class ZKPaths
     private ZKPaths()
     {
     }
+
+    private static CreateMode getCreateMode(boolean asContainers)
+    {
+        return asContainers ? CreatModeHolder.containerCreateMode : CreateMode.PERSISTENT;
+    }
 }