@@ -0,0 +1,2143 @@
+/**%0A * %0A */%0Apackage com.github.phantomthief.util;%0A%0Aimport java.util.Arrays;%0Aimport java.util.function.Function;%0Aimport java.util.function.Supplier;%0A%0Aimport org.apache.curator.framework.CuratorFramework;%0Aimport org.apache.zookeeper.data.Stat;%0A%0A/**%0A * @author w.vela%0A */%0Apublic final class CuratorUtils %7B%0A%0A    private static final int DEFAULT_RETRY_TIMES = 10;%0A%0A    private static final int LOG_THRESHOLD = 10;%0A%0A    private static final int LOG_FREQ = 10;%0A%0A    private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CuratorUtils.class);%0A%0A    private CuratorUtils() %7B%0A    %7D%0A%0A    public static final void setData(Supplier%3CCuratorFramework%3E clientSupplier, String zkPath,%0A            Function%3Cbyte%5B%5D, byte%5B%5D%3E updateOperation) %7B%0A        setData(clientSupplier, zkPath, updateOperation, DEFAULT_RETRY_TIMES);%0A    %7D%0A%0A    public static final void setData(Supplier%3CCuratorFramework%3E clientSupplier, String zkPath,%0A            Function%3Cbyte%5B%5D, byte%5B%5D%3E updateOperation, int maxRetryTimes) %7B%0A        int times = 0;%0A%0A        while (true) %7B%0A            try %7B%0A                Stat stat = new Stat();%0A                byte%5B%5D forPath = clientSupplier.get().getData().storingStatIn(stat).forPath(zkPath);%0A                if (forPath == null) %7B%0A                    throw new RuntimeException(%22there is no path for:%22 + zkPath);%0A                %7D%0A                byte%5B%5D newData = updateOperation.apply(forPath);%0A                if (newData == null %7C%7C Arrays.equals(forPath, newData)) %7B%0A                    break;%0A                %7D%0A                clientSupplier.get().setData().withVersion(stat.getVersion())%0A                        .forPath(zkPath, newData);%0A            %7D catch (Throwable e) %7B%0A                logger.error(%22fail to set data for %7B%7D%22, zkPath, e);%0A            %7D finally %7B%0A                if (times++ %3E LOG_THRESHOLD && times %25 LOG_FREQ == 0) %7B%0A                    logger.warn(%22fail to set data for %7B%7D for %7B%7D times.%22, zkPath, times);%0A                %7D%0A                if (times %3E maxRetryTimes) %7B%0A                    throw new RuntimeException(%22fail to set data for %7B%7D%22 + zkPath);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

add cas update utils.