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);
}