use of com.linkedin.d2.discovery.event.PropertyEventSubscriber in project rest.li by linkedin.
the class ZooKeeperPermanentStoreStrawMan method main.
public static void main(String[] args) throws IOException, InterruptedException, PropertyStoreException {
ZKConnection zkClient = new ZKConnection("localhost:2181", 1000);
Set<String> listenTos = new HashSet<String>();
ZooKeeperPermanentStore<String> zk = new ZooKeeperPermanentStore<String>(zkClient, new PropertyStringSerializer(), "/test/lb/test-property");
listenTos.add("foo12");
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
PropertyEventBus<String> bus = new PropertyEventBusImpl<String>(executorService, zk);
bus.register(listenTos, new PropertyEventSubscriber<String>() {
@Override
public void onAdd(String propertyName, String propertyValue) {
System.err.println("onAdd: " + propertyName + "\t" + propertyValue);
}
@Override
public void onInitialize(String propertyName, String propertyValue) {
System.err.println("onInitialize: " + propertyName + "\t" + propertyValue);
}
@Override
public void onRemove(String propertyName) {
System.err.println("onRemove: " + propertyName);
}
});
zk.put("foo12", "TEST1");
zk.put("foo12", "TEST2");
zk.put("foo12", "TEST3");
zk.put("foo12", "TEST4");
zk.put("foo12", "TEST5");
zk.remove("foo12");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
zkClient.getZooKeeper().close();
executorService.shutdown();
}
Aggregations