[ 
https://issues.apache.org/jira/browse/CURATOR-569?focusedWorklogId=432624&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-432624
 ]

ASF GitHub Bot logged work on CURATOR-569:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/May/20 04:15
            Start Date: 11/May/20 04:15
    Worklog Time Spent: 10m 
      Work Description: TisonKun commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r422768298



##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/api/CreateBuilderMain.java
##########
@@ -27,6 +29,56 @@
     Compressible<CreateBackgroundModeStatACLable>,
     Statable<CreateProtectACLCreateModePathAndBytesable<String>>
 {
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link 
#withProtection()}
+     */
+    static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link 
#withProtection()}
+     */
+    static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link 
UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Utility method to determine if a given ZNode name starts with Curator's 
generated protected prefix.
+     * 
+     * @param znodeName ZNode name
+     * @return {@code true} if the given ZNode name starts with Curator's 
generated protected prefix
+     */
+    public static boolean isProtectedZNode(final String znodeName) {
+        if (znodeName.length() > PROTECTED_PREFIX_WITH_UUID_LENGTH
+                && znodeName.startsWith(PROTECTED_PREFIX)
+                && znodeName.charAt(PROTECTED_PREFIX_WITH_UUID_LENGTH-1) == 
PROTECTED_SEPARATOR
+           ) {
+            try {
+                UUID.fromString(znodeName.substring(PROTECTED_PREFIX.length(), 
PROTECTED_PREFIX_WITH_UUID_LENGTH-2));
+                return true;
+            } catch (IllegalArgumentException e) {
+                // Just false

Review comment:
       nit - (personal taste) explicitly return `false` does no harm and more 
expressive

##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/api/CreateBuilderMain.java
##########
@@ -27,6 +29,56 @@
     Compressible<CreateBackgroundModeStatACLable>,
     Statable<CreateProtectACLCreateModePathAndBytesable<String>>
 {
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link 
#withProtection()}
+     */
+    static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link 
#withProtection()}
+     */
+    static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link 
UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Utility method to determine if a given ZNode name starts with Curator's 
generated protected prefix.
+     * 
+     * @param znodeName ZNode name
+     * @return {@code true} if the given ZNode name starts with Curator's 
generated protected prefix
+     */
+    public static boolean isProtectedZNode(final String znodeName) {
+        if (znodeName.length() > PROTECTED_PREFIX_WITH_UUID_LENGTH
+                && znodeName.startsWith(PROTECTED_PREFIX)
+                && znodeName.charAt(PROTECTED_PREFIX_WITH_UUID_LENGTH-1) == 
PROTECTED_SEPARATOR
+           ) {
+            try {
+                UUID.fromString(znodeName.substring(PROTECTED_PREFIX.length(), 
PROTECTED_PREFIX_WITH_UUID_LENGTH-2));
+                return true;
+            } catch (IllegalArgumentException e) {
+                // Just false
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Utility method to remove Curator's generated protected prefix if present
+     * 
+     * @param znodeName ZNode name
+     * @return string without Curator's generated protected prefix if present; 
original string if prefix not present
+     */
+    public static String removeProtectedPrefix(final String znodeName) {

Review comment:
       What if returns `Optional<String>` which equals 
`isProtectedZNode(znodeName) ? 
Optional.of(znodeName.substring(PROTECTED_PREFIX_WITH_UUID_LENGTH)) : 
Optional.empty()`.
   
   For API semantic it fits in "if present" and user can easily get the 
original sting by `.orElse` but hard to filter non-protected znodes with this 
API(the user of this method seems interested in protected znodes only.)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 432624)
    Time Spent: 40m  (was: 0.5h)

> API TO HANDLE PROTECTED MODE ZNODE NAMES
> ----------------------------------------
>
>                 Key: CURATOR-569
>                 URL: https://issues.apache.org/jira/browse/CURATOR-569
>             Project: Apache Curator
>          Issue Type: Improvement
>          Components: Framework
>            Reporter: Chevaris
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Curator provides protectedMode to handle with some corner cases with 
> ephemeral nodes. When protectedMode is used, Curator appends a prefix to 
> provided name composed by a String concatenating:
>  * "_c_"
>  * Canonical text representation of a random generated UUID
>  * "-"
> Purpose of this ticket is:
>  * Improve Javadoc to fully specify the prefix used with protected Mode
>  * Provide method that allows to identify if a ZNode name has the protected 
> prefix
>  * Provide method that allows to separate the prefix name from the provided 
> name on Curator Framework when creating the node



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to