org.apache.curator.framework.EnsureContainers Java Examples

The following examples show how to use org.apache.curator.framework.EnsureContainers. 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: TestEnsureContainers.java    From xian with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        EnsureContainers ensureContainers = new EnsureContainers(client, "/one/two/three");
        ensureContainers.ensure();

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example #2
Source File: TestEnsureContainers.java    From xian with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleExecution() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        EnsureContainers ensureContainers = new EnsureContainers(client, "/one/two/three");
        ensureContainers.ensure();

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        client.delete().forPath("/one/two/three");
        ensureContainers.ensure();
        Assert.assertNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example #3
Source File: TestEnsureContainers.java    From curator with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        EnsureContainers ensureContainers = new EnsureContainers(client, "/one/two/three");
        ensureContainers.ensure();

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example #4
Source File: TestEnsureContainers.java    From curator with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleExecution() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();

        EnsureContainers ensureContainers = new EnsureContainers(client, "/one/two/three");
        ensureContainers.ensure();

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        client.delete().forPath("/one/two/three");
        ensureContainers.ensure();
        Assert.assertNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
Example #5
Source File: ModeledCacheImpl.java    From curator with Apache License 2.0 6 votes vote down vote up
ModeledCacheImpl(CuratorFramework client, ModelSpec<T> modelSpec, ExecutorService executor)
{
    if ( !modelSpec.path().isResolved() && !modelSpec.path().isRoot() && modelSpec.path().parent().isResolved() )
    {
        modelSpec = modelSpec.parent(); // i.e. the last item is a parameter
    }

    basePath = modelSpec.path();
    this.serializer = modelSpec.serializer();
    CuratorCacheBridgeBuilder bridgeBuilder = CuratorCache.bridgeBuilder(client, basePath.fullPath()).withDataNotCached().withExecutorService(executor);
    if ( modelSpec.createOptions().contains(CreateOption.compress) )
    {
        bridgeBuilder = bridgeBuilder.withOptions(CuratorCache.Options.COMPRESSED_DATA);
    }
    cache = bridgeBuilder.build();
    cache.listenable().addListener(CuratorCacheListener.builder().forTreeCache(client, this).build());

    if ( modelSpec.createOptions().contains(CreateOption.createParentsIfNeeded) || modelSpec.createOptions().contains(CreateOption.createParentsAsContainers) )
    {
        ensureContainers = new EnsureContainers(client, basePath.fullPath());
    }
    else
    {
        ensureContainers = null;
    }
}
 
Example #6
Source File: ServiceCacheImpl.java    From curator with Apache License 2.0 6 votes vote down vote up
ServiceCacheImpl(ServiceDiscoveryImpl<T> discovery, String name, ExecutorService executorService)
{
    Preconditions.checkNotNull(discovery, "discovery cannot be null");
    Preconditions.checkNotNull(name, "name cannot be null");

    this.discovery = discovery;

    String path = discovery.pathForName(name);
    cache = CuratorCache.bridgeBuilder(discovery.getClient(), path)
        .withExecutorService(executorService)
        .withDataNotCached()
        .build();
    CuratorCacheListener listener = CuratorCacheListener.builder()
        .forPathChildrenCache(path, discovery.getClient(), this)
        .forInitialized(this::initialized)
        .build();
    cache.listenable().addListener(listener);
    ensureContainers = new EnsureContainers(discovery.getClient(), path);
}
 
Example #7
Source File: PathChildrenCache.java    From xian with Apache License 2.0 5 votes vote down vote up
/**
 * @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 #8
Source File: SimpleDistributedQueue.java    From xian with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #9
Source File: PathChildrenCache.java    From curator with Apache License 2.0 5 votes vote down vote up
/**
 * @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 #10
Source File: SimpleDistributedQueue.java    From curator with Apache License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #11
Source File: SimpleQueue.java    From workflow with Apache License 2.0 5 votes vote down vote up
SimpleQueue(CuratorFramework client, TaskRunner taskRunner, Serializer serializer, String queuePath, String lockPath, TaskMode mode, boolean idempotent)
{
    this.client = client;
    this.taskRunner = taskRunner;
    this.serializer = serializer;
    this.path = queuePath;
    this.lockPath = lockPath;
    this.idempotent = idempotent;
    ensurePath = new EnsureContainers(client, path);
    nodeFunc = nodeFuncs.getOrDefault(mode, nodeFuncs.get(TaskMode.STANDARD));
    keyFunc = keyFuncs.getOrDefault(mode, keyFuncs.get(TaskMode.STANDARD));
}