Randgalt commented on a change in pull request #366: URL: https://github.com/apache/curator/pull/366#discussion_r425153209
########## 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: I think you're making a huge assumption there. We really don't know how clients will use the library - I've been very surprised over the years. Further, I've had to go to great lengths to get around stuff that's hidden in ZooKeeper. Remember, this is Java, nothing is truly hidden. You can access anything via reflection. tbh - I'd also like to see a method: `public static String extractProtectId(String znodeName)`. Let's give people as many tools as possible. ---------------------------------------------------------------- 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]
