You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by GitBox <gi...@apache.org> on 2020/05/14 07:23:27 UTC

[GitHub] [curator] chevaris commented on a change in pull request #366: [CURATOR-569] API TO HANDLE PROTECTED MODE ZNODE NAMES

chevaris commented on a change in pull request #366:
URL: https://github.com/apache/curator/pull/366#discussion_r424922714



##########
File path: curator-framework/src/main/java/org/apache/curator/framework/imps/ProtectedUtils.java
##########
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.imps;
+
+import java.util.UUID;
+
+import org.apache.curator.framework.api.CreateBuilderMain;
+
+/**
+ * Utility class to handle ZNode names when using {@link CreateBuilderMain#withProtection()}
+ */
+public final class ProtectedUtils {
+
+    private ProtectedUtils() {
+        throw new RuntimeException("Protected Utils is a helper class");
+    }
+
+    /**
+     * First 3 characters in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final String PROTECTED_PREFIX = "_c_";
+
+    /**
+     * Last character used in the prefix on ZNode names when using {@link CreateBuilderMain#withProtection()}
+     */
+    public static final char PROTECTED_SEPARATOR = '-';
+
+    /**
+     * Prefix length on ZNode name when using {@link #withProtection()}
+     */
+    public static final int PROTECTED_PREFIX_WITH_UUID_LENGTH = 
+            PROTECTED_PREFIX.length() 
+            + 36 // UUID canonical text representation produced by {@link UUID#toString()}
+            + 1; // Separator length
+
+    /**
+     * Provides a prefix to be appended to a ZNode name when protected. The method assumes that the provided string
+     * adjusts to the required format
+     * 
+     * @param protectedId canonical text representation of a UUID
+     * @return string that concatenates {@value #PROTECTED_PREFIX}, the given id and {@value #PROTECTED_SEPARATOR}
+     */
+    static String getProtectedPrefix(final String protectedId)

Review comment:
       Thx for the explanation. Let me explain my reasoning.
   
   When building libraries, I like to think in this way:
   End user interest -> public APIs
   Library developers Interest -> reduce visibility as much as possible (protected/private APIs)
   
   This method is only interesting for interface implementations, because end users will limit to use withProtection() method. Other methods (normalize...) are interesting for end users to potentially remove non semantic part of the name when watching a ZNode.
   I think that there is no way (maybe I am wrong) for the end user to provide an implementation of the CreateBuilderMain interface.
   
   I will make the methods public, unless I have convinced you :) and you say the opposite




----------------------------------------------------------------
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:
users@infra.apache.org