Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C43B1183C6 for ; Mon, 17 Aug 2015 17:02:09 +0000 (UTC) Received: (qmail 79459 invoked by uid 500); 17 Aug 2015 17:02:09 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 79351 invoked by uid 500); 17 Aug 2015 17:02:09 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 79167 invoked by uid 99); 17 Aug 2015 17:02:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Aug 2015 17:02:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 236D7E0375; Mon, 17 Aug 2015 17:02:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dragonsinth@apache.org To: commits@curator.apache.org Date: Mon, 17 Aug 2015 17:02:10 -0000 Message-Id: In-Reply-To: <7ac50fe071104b4493121735a87f2dc8@git.apache.org> References: <7ac50fe071104b4493121735a87f2dc8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [02/41] 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-3.0 Commit: d492f8c1ab6243b49f30b27754bf6a1cff3b80fe Parents: 04ae811 Author: randgalt Authored: Tue May 19 14:56:30 2015 -0700 Committer: randgalt 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; + } }