java - How to check programmatically if Zookeeper is running? -



java - How to check programmatically if Zookeeper is running? -

i using curatorframework (i'm still newbie) in order connect zookeeper instance. import configuration before test programme able connect zookeeper. far have that:

public boolean zookeeperrunning() { curatorframework curatorframework = curatorframeworkfactory.newclient(zookeeperconn, new retryonetime(1)); curatorframework.start(); curatorzookeeperclient zkclient = curatorframework.getzookeeperclient(); homecoming zkclient.isconnected(); }

i've started zookeeper on local machine , checked connection zkcli , client able connect it. zookeepercon variable set "127.0.0.1:2181" (i tried localhost:2181 well). problem above method returns false despite fact zkserver n running. probably, syntax not right not find solution online. please help me why above code cannot find zkserver , running?

you can utilize builder create configured client , setup listener monitor zk instance's state:

// start client client = curatorframeworkfactory.builder() .connectstring("localhost:2181") .retrypolicy(new exponentialbackoffretry(1000, 3)) .namespace("heavenize") .build(); client.getconnectionstatelistenable().addlistener(new connectionstatelistener() { @override public void statechanged(curatorframework client, connectionstate newstate) { log.info("state changed to: "+newstate); } }); }

java zookeeper curator

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -