change to use if statements; remove redundant isSequential method and define SEQUENTIAL_SUFFIX_DIGITS int constant
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/824b7272 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/824b7272 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/824b7272 Branch: refs/heads/master Commit: 824b72729a6168ce9775ccd86b88a08656dbc064 Parents: 8e4dba7 Author: nickhill <nickh...@us.ibm.com> Authored: Tue Nov 6 17:32:23 2018 -0800 Committer: nickhill <nickh...@us.ibm.com> Committed: Tue Nov 6 17:32:23 2018 -0800 ---------------------------------------------------------------------- .../framework/recipes/nodes/PersistentNode.java | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/824b7272/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java index 9c9b527..5fcbc64 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentNode.java @@ -422,6 +422,9 @@ public class PersistentNode implements Closeable } } + // Hardcoded in {@link org.apache.zookeeper.server.PrepRequestProcessor} + static final int SEQUENTIAL_SUFFIX_DIGITS = 10; + private void createNode() { if ( !isActive() ) @@ -444,9 +447,19 @@ public class PersistentNode implements Closeable try { - String existingPath = nodePath.get(); - String createPath = existingPath == null || (useProtection && !isSequential(mode)) ? basePath - : (useProtection ? basePath + existingPath.substring(existingPath.length()-10) : existingPath); + String existingPath = nodePath.get(), createPath; + if ( existingPath != null && !useProtection ) + { + createPath = existingPath; + } + else + { + createPath = basePath; + if ( useProtection && mode.isSequential() ) + { + createPath += existingPath.substring(existingPath.length()-SEQUENTIAL_SUFFIX_DIGITS); + } + } CreateModable<ACLBackgroundPathAndBytesable<String>> localCreateMethod = createMethod.get(); if ( localCreateMethod == null ) @@ -464,10 +477,6 @@ public class PersistentNode implements Closeable throw new RuntimeException("Creating node. BasePath: " + basePath, e); // should never happen unless there's a programming error - so throw RuntimeException } } - - private static boolean isSequential(CreateMode mode) { - return mode == CreateMode.EPHEMERAL_SEQUENTIAL || mode == CreateMode.PERSISTENT_SEQUENTIAL; - } private CreateMode getCreateMode(boolean pathIsSet) {