Package org.I0Itec.zkclient

Examples of org.I0Itec.zkclient.ZkClient


    /**
     * The chroot znode *must* already exist.
     */

    public static ZkClient makeCustomChrootClient(String zkHosts, String chroot) {
        return new ZkClient(zkHosts + "/" + chroot, zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }
View Full Code Here


    public static ZkClient makeCustomChrootClient(String zkHosts, String chroot) {
        return new ZkClient(zkHosts + "/" + chroot, zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }

    public static ZkClient makeCustomChrootClient(String chroot) {
        return new ZkClient(zkHosts + "/" + chroot, zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }
View Full Code Here

            for (String backup : backups) {
                address.append(",");
                address.append(appendDefaultPort(backup));
            }
        }
        zkClient = new ZkClient(address.toString());
        zkClient.subscribeStateChanges(new IZkStateListener() {
            public void handleStateChanged(KeeperState state) throws Exception {
                ZookeeperRegistry.this.zkState = state;
            }
            public void handleNewSession() throws Exception {
View Full Code Here

  }

  @Test(enabled = false)
  private static void testChrootWithZkClient() throws Exception
  {
    ZkClient client = new ZkClient("localhost:2181/foo");
    IZkStateListener stateChangeListener = new IZkStateListener()
    {

      @Override
      public void handleStateChanged(KeeperState state) throws Exception
      {
        System.out
            .println("AppTest.main(...).new IZkStateListener() {...}.handleStateChanged()"
                + state);
      }

      @Override
      public void handleNewSession() throws Exception
      {
        System.out
            .println("AppTest.main(...).new IZkStateListener() {...}.handleNewSession()");
      }
    };
    client.subscribeStateChanges(stateChangeListener);
    boolean waitUntilConnected = client.waitUntilConnected(10000,
        TimeUnit.MILLISECONDS);
    System.out.println("Connected " + waitUntilConnected);
    client.waitForKeeperState(KeeperState.Disconnected, 20000,
        TimeUnit.MILLISECONDS);
    // server.start();
    client.waitUntilConnected();
    Thread.currentThread().join();
  }
View Full Code Here

    String dataDir = "/tmp/dataDir";
    String logDir = "/tmp/logDir";
    // ZkServer server = new ZkServer(dataDir, logDir, defaultNameSpace, 2181);
    // server.start();

    ZkClient client = new ZkClient("localhost:2181/foo");
    IZkStateListener stateChangeListener = new IZkStateListener()
    {

      @Override
      public void handleStateChanged(KeeperState state) throws Exception
      {
        System.out
            .println("AppTest.main(...).new IZkStateListener() {...}.handleStateChanged()"
                + state);
      }

      @Override
      public void handleNewSession() throws Exception
      {
        System.out
            .println("AppTest.main(...).new IZkStateListener() {...}.handleNewSession()");
      }
    };
    client.subscribeStateChanges(stateChangeListener);
    boolean waitUntilConnected = client.waitUntilConnected(10000,
        TimeUnit.MILLISECONDS);
    System.out.println("Connected " + waitUntilConnected);
    IZkChildListener listener1 = new IZkChildListener()
    {

      @Override
      public void handleChildChange(String parentPath,
          List<String> currentChilds) throws Exception
      {
        System.out.println("listener 1 Change at path:" + parentPath);
      }
    };
    IZkChildListener listener2 = new IZkChildListener()
    {
      @Override
      public void handleChildChange(String parentPath,
          List<String> currentChilds) throws Exception
      {
        System.out.println("listener2 Change at path:" + parentPath);
      }
    };

    client.subscribeChildChanges("/", listener1);
    client.subscribeChildChanges("/foo", listener2);

    // server.shutdown();
    client.waitForKeeperState(KeeperState.Disconnected, 20000,
        TimeUnit.MILLISECONDS);
    // server.start();
    client.waitUntilConnected();

    Thread.sleep(1000);
    client.setZkSerializer(new BytesPushThroughSerializer());
    client.create("/test", new byte[0], CreateMode.EPHEMERAL);
    Thread.sleep(1000);
  }
View Full Code Here

    protected void before() throws Throwable {
        tempDir.create();

        zkServer = new TestingServer();

        zkClient = new ZkClient("localhost:" + zkServer.getPort(), 20000, 20000, new ZkSerializer() {
            @Override
            public byte[] serialize(Object data) throws ZkMarshallingError {
                try {
                    return ((String)data).getBytes("UTF-8");
                } catch (UnsupportedEncodingException e) {
View Full Code Here

  private KafkaUtils() {
  }

  public static void maybeCreateTopic(String host, int port, String topic) {
    ZkClient zkClient = buildClient(host, port);
    if (AdminUtils.topicExists(zkClient, topic)) {
      log.info("No need to create topic {} as it already exists", topic);
    } else {
      log.info("Creating topic {}", topic);
      try {
        AdminUtils.createTopic(zkClient, topic, 1, 1, new Properties());
        log.info("Created Zookeeper topic {}", topic);
      } catch (TopicExistsException tee) {
        log.info("Zookeeper topic {} already exists", topic);
      } finally {
        zkClient.close();
      }
    }
  }
View Full Code Here

      }
    }
  }

  public static void deleteTopic(String host, int port, String topic) {
    ZkClient zkClient = buildClient(host, port);
    if (AdminUtils.topicExists(zkClient, topic)) {
      log.info("Deleting topic {}", topic);
      try {
        AdminUtils.deleteTopic(zkClient, topic);
        log.info("Deleted Zookeeper topic {}", topic);
      } catch (ZkNodeExistsException nee) {
        log.info("Delete was already scheduled for Zookeeper topic {}", topic);
      } finally {
        zkClient.close();
      }
    } else {
      log.info("No need to delete topic {} as it does not exist", topic);
    }
  }
View Full Code Here

      log.info("No need to delete topic {} as it does not exist", topic);
    }
  }

  private static ZkClient buildClient(String host, int port) {
    return new ZkClient(host + ':' + port,
                        ZK_TIMEOUT_MSEC,
                        ZK_TIMEOUT_MSEC,
                        ZKStringSerializer$.MODULE$);
  }
View Full Code Here

    protected ZkServer _zkServer;
    protected ZkClient _client;

    public void testToString() throws Exception {
        _zkServer = TestUtil.startZkServer("ZkPathUtilTest", 4711);
        _client = new ZkClient("localhost:4711", 5000);
        final String file1 = "/files/file1";
        final String file2 = "/files/file2";
        final String file3 = "/files/file2/file3";
        _client.createPersistent(file1, true);
        _client.createPersistent(file2, true);
View Full Code Here

TOP

Related Classes of org.I0Itec.zkclient.ZkClient

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.