Package org.apache.curator.framework.recipes.nodes

Examples of org.apache.curator.framework.recipes.nodes.PersistentEphemeralNode


        Timing timing = new Timing();
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
        try
        {
            client.start();
            PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
            node.start();

            final CountDownLatch connectedLatch = new CountDownLatch(1);
            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
            final AtomicReference<ConnectionState> lastState = new AtomicReference<ConnectionState>();
            ConnectionStateListener listener = new ConnectionStateListener()
            {
                @Override
                public void stateChanged(CuratorFramework client, ConnectionState newState)
                {
                    lastState.set(newState);
                    if ( newState == ConnectionState.CONNECTED )
                    {
                        connectedLatch.countDown();
                    }
                    if ( newState == ConnectionState.RECONNECTED )
                    {
                        reconnectedLatch.countDown();
                    }
                }
            };
            client.getConnectionStateListenable().addListener(listener);
            timing.sleepABit();
            server = new TestingServer(server.getPort());
            Assert.assertTrue(timing.awaitLatch(connectedLatch));
            timing.sleepABit();
            Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
            server.close();
            timing.sleepABit();
            server = new TestingServer(server.getPort());
            timing.sleepABit();
            Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
View Full Code Here


        Timing timing = new Timing();
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(timing.milliseconds()));
        try
        {
            client.start();
            PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
            node.start();

            final BlockingQueue<ConnectionState> stateVector = Queues.newLinkedBlockingQueue(1);
            ConnectionStateListener listener = new ConnectionStateListener()
            {
                @Override
View Full Code Here

   */
  @Test
  public void testAtomicRecursiveDeleteWithPersistentENode() throws Exception {
    final String path = "/foo/bar/baz/faz/fooz";

    PersistentEphemeralNode node =
        new PersistentEphemeralNode(mZKClient, Mode.EPHEMERAL, path, new byte[0]);
    try {
      node.start();
      node.waitForInitialCreate(5, TimeUnit.SECONDS);
      Assert.assertTrue(ZooKeeperUtils.atomicRecursiveDelete(mZKClient, "/foo"));
      Thread.sleep(1000); // Give ephemeral node time to recreate itself
      Assert.assertNotNull(mZKClient.checkExists().forPath("/foo"));
    } finally {
      node.close();
    }
  }
View Full Code Here

      String systemVersion) {
    mInstanceURI = instanceURI;
    String path = ZooKeeperUtils.getInstanceUsersDir(mInstanceURI).getPath();
    String node = ZooKeeperUtils.makeZKNodeName(userID, systemVersion);

    mNode = new PersistentEphemeralNode(zkClient, Mode.EPHEMERAL, path + "/" + node, new byte[] {});

    LOG.debug("Creating instance user registration for instance {}.", mInstanceURI);
  }
View Full Code Here

              .append(ZooKeeperUtils.getTableUsersDir(mTableURI))
              .append("/")
              .append(ZooKeeperUtils.makeZKNodeName(mUserID, layoutID))
              .toString();

      mNode = new PersistentEphemeralNode(mZKClient, Mode.EPHEMERAL, path, new byte[]{});
      mNode.start();
      try {
        mNode.waitForInitialCreate(42, TimeUnit.DAYS); // Wait forever
      } catch (InterruptedException e) {
        LOG.info("Interrupted while attempting to register table user.");
View Full Code Here

        Timing timing = new Timing();
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
        try
        {
            client.start();
            PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
            node.start();

            final CountDownLatch connectedLatch = new CountDownLatch(1);
            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
            final AtomicReference<ConnectionState> lastState = new AtomicReference<ConnectionState>();
            ConnectionStateListener listener = new ConnectionStateListener()
            {
                @Override
                public void stateChanged(CuratorFramework client, ConnectionState newState)
                {
                    lastState.set(newState);
                    if ( newState == ConnectionState.CONNECTED )
                    {
                        connectedLatch.countDown();
                    }
                    if ( newState == ConnectionState.RECONNECTED )
                    {
                        reconnectedLatch.countDown();
                    }
                }
            };
            client.getConnectionStateListenable().addListener(listener);
            timing.sleepABit();
            server = new TestingServer(server.getPort());
            Assert.assertTrue(timing.awaitLatch(connectedLatch));
            timing.sleepABit();
            Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
            server.close();
            timing.sleepABit();
            server = new TestingServer(server.getPort());
            timing.sleepABit();
            Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
View Full Code Here

        Timing timing = new Timing();
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(timing.milliseconds()));
        try
        {
            client.start();
            PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
            node.start();

            final BlockingQueue<ConnectionState> stateVector = Queues.newLinkedBlockingQueue(1);
            ConnectionStateListener listener = new ConnectionStateListener()
            {
                @Override
View Full Code Here

    {
        try
        {
            CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);

            final PersistentEphemeralNode node = new PersistentEphemeralNode(entry.getClient(), PersistentEphemeralNode.Mode.valueOf(mode.name()), path, data);
            node.start();

            Closer closer = new Closer()
            {
                @Override
                public void close()
                {
                    try
                    {
                        node.close();
                    }
                    catch ( Exception e )
                    {
                        log.error("Could not release left-over persistent ephemeral node for path: " + path, e);
                    }
View Full Code Here

        Timing timing = new Timing();
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
        try
        {
            client.start();
            PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
            node.start();

            final CountDownLatch connectedLatch = new CountDownLatch(1);
            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
            final AtomicReference<ConnectionState> lastState = new AtomicReference<ConnectionState>();
            ConnectionStateListener listener = new ConnectionStateListener()
            {
                @Override
                public void stateChanged(CuratorFramework client, ConnectionState newState)
                {
                    lastState.set(newState);
                    if ( newState == ConnectionState.CONNECTED )
                    {
                        connectedLatch.countDown();
                    }
                    if ( newState == ConnectionState.RECONNECTED )
                    {
                        reconnectedLatch.countDown();
                    }
                }
            };
            client.getConnectionStateListenable().addListener(listener);
            timing.sleepABit();
            server = new TestingServer(server.getPort());
            Assert.assertTrue(timing.awaitLatch(connectedLatch));
            timing.sleepABit();
            Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
            server.close();
            timing.sleepABit();
            server = new TestingServer(server.getPort());
            timing.sleepABit();
            Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
View Full Code Here

        Timing timing = new Timing();
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(timing.milliseconds()));
        try
        {
            client.start();
            PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
            node.start();

            final BlockingQueue<ConnectionState> stateVector = Queues.newLinkedBlockingQueue(1);
            ConnectionStateListener listener = new ConnectionStateListener()
            {
                @Override
View Full Code Here

TOP

Related Classes of org.apache.curator.framework.recipes.nodes.PersistentEphemeralNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.