org.apache.curator.utils.PathUtils Java Examples
The following examples show how to use
org.apache.curator.utils.PathUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultZooKeeperClient.java From helios with Apache License 2.0 | 6 votes |
@Override /** {@inheritDoc} */ public void ensurePath(final String path, final boolean excludingLast) throws KeeperException { PathUtils.validatePath(path); assertClusterIdFlagTrue(); final String[] parts = path.substring(1).split(Pattern.quote("/")); final int end = excludingLast ? parts.length - 1 : parts.length; String current = ""; for (int i = 0; i < end; i++) { current += "/" + parts[i]; if (exists(current) == null) { create(current); } } }
Example #2
Source File: NamespaceImpl.java From xian with Apache License 2.0 | 6 votes |
NamespaceImpl(CuratorFrameworkImpl client, String namespace) { if ( namespace != null ) { try { PathUtils.validatePath("/" + namespace); } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException("Invalid namespace: " + namespace + ", " + e.getMessage()); } } this.client = client; this.namespace = namespace; ensurePathNeeded = new AtomicBoolean(namespace != null); }
Example #3
Source File: ZookeeperWatcher.java From Thunder with Apache License 2.0 | 6 votes |
public void usingWatcher(ZookeeperWatcherType watcherType, String path) throws Exception { if (watcherType == null) { throw new ZookeeperException("Watcher type is null"); } PathUtils.validatePath(path); this.watcherType = watcherType; this.path = path; switch (watcherType) { case EXISTS: usingWatcher(client.checkExists().usingWatcher(this), path); break; case GET_CHILDREN: usingWatcher(client.getChildren().usingWatcher(this), path); break; case GET_DATA: usingWatcher(client.getData().usingWatcher(this), path); break; } }
Example #4
Source File: LeaderSelector.java From xian with Apache License 2.0 | 6 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param executorService thread pool to use * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, CloseableExecutorService executorService, LeaderSelectorListener listener) { Preconditions.checkNotNull(client, "client cannot be null"); PathUtils.validatePath(leaderPath); Preconditions.checkNotNull(listener, "listener cannot be null"); this.client = client; this.listener = new WrappedListener(this, listener); hasLeadership = false; this.executorService = executorService; mutex = new InterProcessMutex(client, leaderPath) { @Override protected byte[] getLockNodeBytes() { return (id.length() > 0) ? getIdBytes(id) : null; } }; }
Example #5
Source File: NamespaceImpl.java From curator with Apache License 2.0 | 6 votes |
NamespaceImpl(CuratorFrameworkImpl client, String namespace) { if ( namespace != null ) { try { PathUtils.validatePath("/" + namespace); } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException("Invalid namespace: " + namespace + ", " + e.getMessage()); } } this.client = client; this.namespace = namespace; ensurePathNeeded = new AtomicBoolean(namespace != null); }
Example #6
Source File: LeaderSelector.java From curator with Apache License 2.0 | 6 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param executorService thread pool to use * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, CloseableExecutorService executorService, LeaderSelectorListener listener) { Preconditions.checkNotNull(client, "client cannot be null"); PathUtils.validatePath(leaderPath); Preconditions.checkNotNull(listener, "listener cannot be null"); this.client = client; this.listener = new WrappedListener(this, listener); hasLeadership = false; this.executorService = executorService; mutex = new InterProcessMutex(client, leaderPath) { @Override protected byte[] getLockNodeBytes() { return (id.length() > 0) ? getIdBytes(id) : null; } }; }
Example #7
Source File: ZookeeperInvoker.java From Thunder with Apache License 2.0 | 5 votes |
public <T> T getObject(String path, Class<T> clazz) throws Exception { validateStartedStatus(); PathUtils.validatePath(path); byte[] data = client.getData().forPath(path); return getObject(data, clazz); }
Example #8
Source File: LeaderLatch.java From xian with Apache License 2.0 | 5 votes |
/** * @param client the client * @param latchPath the path for this leadership group * @param id participant ID * @param closeMode behaviour of listener on explicit close. */ public LeaderLatch(CuratorFramework client, String latchPath, String id, CloseMode closeMode) { this.client = Preconditions.checkNotNull(client, "client cannot be null"); this.latchPath = PathUtils.validatePath(latchPath); this.id = Preconditions.checkNotNull(id, "id cannot be null"); this.closeMode = Preconditions.checkNotNull(closeMode, "closeMode cannot be null"); }
Example #9
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param executorService Closeable ExecutorService to use for the PathChildrenCache's background thread. This getGroup should be single threaded, otherwise the cache may see inconsistent results. */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService) { this.client = client; this.path = PathUtils.validatePath(path); this.cacheData = cacheData; this.dataIsCompressed = dataIsCompressed; this.executorService = executorService; ensureContainers = new EnsureContainers(client, path); }
Example #10
Source File: QueueBuilder.java From xian with Apache License 2.0 | 5 votes |
private QueueBuilder(CuratorFramework client, QueueConsumer<T> consumer, QueueSerializer<T> serializer, String queuePath) { this.client = client; this.consumer = consumer; this.serializer = serializer; this.queuePath = PathUtils.validatePath(queuePath); factory = defaultThreadFactory; executor = MoreExecutors.directExecutor(); }
Example #11
Source File: DistributedDoubleBarrier.java From xian with Apache License 2.0 | 5 votes |
/** * Creates the barrier abstraction. <code>memberQty</code> is the number of members in the * barrier. When {@link #enter()} is called, it blocks until all members have entered. When * {@link #leave()} is called, it blocks until all members have left. * * @param client the client * @param barrierPath path to use * @param memberQty the number of members in the barrier. NOTE: more than <code>memberQty</code> * can enter the barrier. <code>memberQty</code> is a threshold, not a limit */ public DistributedDoubleBarrier(CuratorFramework client, String barrierPath, int memberQty) { Preconditions.checkState(memberQty > 0, "memberQty cannot be 0"); this.client = client; this.barrierPath = PathUtils.validatePath(barrierPath); this.memberQty = memberQty; ourPath = ZKPaths.makePath(barrierPath, UUID.randomUUID().toString()); readyPath = ZKPaths.makePath(barrierPath, READY_NODE); }
Example #12
Source File: QueueSafety.java From xian with Apache License 2.0 | 5 votes |
/** * @param lockPath ZKPath to use for locking purposes * @param consumer the message consumer */ public QueueSafety(String lockPath, QueueConsumer<T> consumer) { this.lockPath = PathUtils.validatePath(lockPath); this.consumer = consumer; this.queue = null; }
Example #13
Source File: NodeCache.java From xian with Apache License 2.0 | 5 votes |
/** * @param client curztor client * @param path the full path to the node to cache * @param dataIsCompressed if true, data in the path is compressed */ public NodeCache(CuratorFramework client, String path, boolean dataIsCompressed) { this.client = client; this.path = PathUtils.validatePath(path); this.dataIsCompressed = dataIsCompressed; }
Example #14
Source File: SharedValue.java From xian with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path the shared path - i.e. where the shared value is stored * @param seedValue the initial value for the value if/f the path has not yet been created */ public SharedValue(CuratorFramework client, String path, byte[] seedValue) { this.client = client; this.path = PathUtils.validatePath(path); this.seedValue = Arrays.copyOf(seedValue, seedValue.length); currentValue = new AtomicReference<VersionedValue<byte[]>>(new VersionedValue<byte[]>(UNINITIALIZED_VERSION, Arrays.copyOf(seedValue, seedValue.length))); }
Example #15
Source File: DistributedDoubleBarrier.java From curator with Apache License 2.0 | 5 votes |
/** * Creates the barrier abstraction. <code>memberQty</code> is the number of members in the * barrier. When {@link #enter()} is called, it blocks until all members have entered. When * {@link #leave()} is called, it blocks until all members have left. * * @param client the client * @param barrierPath path to use * @param memberQty the number of members in the barrier. NOTE: more than <code>memberQty</code> * can enter the barrier. <code>memberQty</code> is a threshold, not a limit */ public DistributedDoubleBarrier(CuratorFramework client, String barrierPath, int memberQty) { Preconditions.checkState(memberQty > 0, "memberQty cannot be 0"); this.client = client; this.barrierPath = PathUtils.validatePath(barrierPath); this.memberQty = memberQty; ourPath = ZKPaths.makePath(barrierPath, UUID.randomUUID().toString()); readyPath = ZKPaths.makePath(barrierPath, READY_NODE); }
Example #16
Source File: ZookeeperCacheListener.java From Thunder with Apache License 2.0 | 5 votes |
public ZookeeperCacheListener(CuratorFramework client, String path) { if (client == null) { throw new ZookeeperException("Zookeeper client is null"); } PathUtils.validatePath(path); this.client = client; this.path = path; }
Example #17
Source File: ZookeeperInvoker.java From Thunder with Apache License 2.0 | 5 votes |
public Stat getPathStat(String path) throws Exception { validateStartedStatus(); PathUtils.validatePath(path); ExistsBuilder builder = client.checkExists(); if (builder == null) { return null; } Stat stat = builder.forPath(path); return stat; }
Example #18
Source File: ZookeeperInvoker.java From Thunder with Apache License 2.0 | 5 votes |
public void createPath(String path, Serializable object) throws Exception { validateStartedStatus(); PathUtils.validatePath(path); byte[] data = getData(object); client.create().creatingParentsIfNeeded().forPath(path, data); }
Example #19
Source File: ZookeeperInvoker.java From Thunder with Apache License 2.0 | 5 votes |
public void createPath(String path, Serializable object, CreateMode mode) throws Exception { validateStartedStatus(); PathUtils.validatePath(path); byte[] data = getData(object); client.create().creatingParentsIfNeeded().withMode(mode).forPath(path, data); }
Example #20
Source File: ZookeeperInvoker.java From Thunder with Apache License 2.0 | 5 votes |
public void setData(String path, Serializable object) throws Exception { validateStartedStatus(); PathUtils.validatePath(path); byte[] data = getData(object); client.setData().forPath(path, data); }
Example #21
Source File: LockInternals.java From curator with Apache License 2.0 | 5 votes |
LockInternals(CuratorFramework client, LockInternalsDriver driver, String path, String lockName, int maxLeases) { this.driver = driver; this.lockName = lockName; this.maxLeases = maxLeases; this.client = client.newWatcherRemoveCuratorFramework(); this.basePath = PathUtils.validatePath(path); this.path = ZKPaths.makePath(path, lockName); }
Example #22
Source File: LeaderLatch.java From curator with Apache License 2.0 | 5 votes |
/** * @param client the client * @param latchPath the path for this leadership group * @param id participant ID * @param closeMode behaviour of listener on explicit close. */ public LeaderLatch(CuratorFramework client, String latchPath, String id, CloseMode closeMode) { this.client = Preconditions.checkNotNull(client, "client cannot be null").newWatcherRemoveCuratorFramework(); this.latchPath = PathUtils.validatePath(latchPath); this.id = Preconditions.checkNotNull(id, "id cannot be null"); this.closeMode = Preconditions.checkNotNull(closeMode, "closeMode cannot be null"); }
Example #23
Source File: SharedValue.java From curator with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path the shared path - i.e. where the shared value is stored * @param seedValue the initial value for the value if/f the path has not yet been created */ public SharedValue(CuratorFramework client, String path, byte[] seedValue) { this.client = client.newWatcherRemoveCuratorFramework(); this.path = PathUtils.validatePath(path); this.seedValue = Arrays.copyOf(seedValue, seedValue.length); this.watcher = new SharedValueCuratorWatcher(); currentValue = new AtomicReference<VersionedValue<byte[]>>(new VersionedValue<byte[]>(UNINITIALIZED_VERSION, Arrays.copyOf(seedValue, seedValue.length))); }
Example #24
Source File: SharedValue.java From curator with Apache License 2.0 | 5 votes |
@VisibleForTesting protected SharedValue(WatcherRemoveCuratorFramework client, String path, byte[] seedValue, CuratorWatcher watcher) { this.client = client; this.path = PathUtils.validatePath(path); this.seedValue = Arrays.copyOf(seedValue, seedValue.length); // inject watcher for testing this.watcher = watcher; currentValue = new AtomicReference<VersionedValue<byte[]>>(new VersionedValue<byte[]>(UNINITIALIZED_VERSION, Arrays.copyOf(seedValue, seedValue.length))); }
Example #25
Source File: PersistentNode.java From curator with Apache License 2.0 | 5 votes |
/** * @param givenClient client instance * @param mode creation mode * @param useProtection if true, call {@link CreateBuilder#withProtection()} * @param basePath the base path for the node * @param initData data for the node * @param ttl for ttl modes, the ttl to use */ public PersistentNode(CuratorFramework givenClient, final CreateMode mode, boolean useProtection, final String basePath, byte[] initData, long ttl) { this.useProtection = useProtection; this.client = Preconditions.checkNotNull(givenClient, "client cannot be null").newWatcherRemoveCuratorFramework(); this.basePath = PathUtils.validatePath(basePath); this.mode = Preconditions.checkNotNull(mode, "mode cannot be null"); this.ttl = ttl; final byte[] data = Preconditions.checkNotNull(initData, "data cannot be null"); backgroundCallback = new BackgroundCallback() { @Override public void processResult(CuratorFramework dummy, CuratorEvent event) throws Exception { if ( isActive() ) { processBackgroundCallback(event); } else { processBackgroundCallbackClosedState(event); } } }; this.data.set(Arrays.copyOf(data, data.length)); }
Example #26
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param executorService Closeable ExecutorService to use for the PathChildrenCache's background thread. This service should be single threaded, otherwise the cache may see inconsistent results. */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService) { this.client = client.newWatcherRemoveCuratorFramework(); this.path = PathUtils.validatePath(path); this.cacheData = cacheData; this.dataIsCompressed = dataIsCompressed; this.executorService = executorService; ensureContainers = new EnsureContainers(client, path); }
Example #27
Source File: NodeCache.java From curator with Apache License 2.0 | 5 votes |
/** * @param client curator client * @param path the full path to the node to cache * @param dataIsCompressed if true, data in the path is compressed */ public NodeCache(CuratorFramework client, String path, boolean dataIsCompressed) { this.client = client.newWatcherRemoveCuratorFramework(); this.path = PathUtils.validatePath(path); this.dataIsCompressed = dataIsCompressed; }
Example #28
Source File: QueueSafety.java From curator with Apache License 2.0 | 5 votes |
/** * @param lockPath ZKPath to use for locking purposes * @param consumer the message consumer */ public QueueSafety(String lockPath, QueueConsumer<T> consumer) { this.lockPath = PathUtils.validatePath(lockPath); this.consumer = consumer; this.queue = null; }
Example #29
Source File: QueueBuilder.java From curator with Apache License 2.0 | 5 votes |
private QueueBuilder(CuratorFramework client, QueueConsumer<T> consumer, QueueSerializer<T> serializer, String queuePath) { this.client = client; this.consumer = consumer; this.serializer = serializer; this.queuePath = PathUtils.validatePath(queuePath); factory = defaultThreadFactory; executor = MoreExecutors.directExecutor(); }
Example #30
Source File: SimpleDistributedQueue.java From curator with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to store queue nodes */ public SimpleDistributedQueue(CuratorFramework client, String path) { this.client = client; this.path = PathUtils.validatePath(path); ensureContainers = new EnsureContainers(client, path); }