Search in sources :

Example 1 with PropertyStringMerger

use of com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStoreTest.PropertyStringMerger in project rest.li by linkedin.

the class ZooKeeperEphemeralStoreStrawMan method main.

public static void main(String[] args) throws IOException, InterruptedException, PropertyStoreException {
    ZKConnection zkClient = new ZKConnection("localhost:2181", 30000);
    PropertyStringMerger merger = new PropertyStringMerger();
    Set<String> listenTos = new HashSet<String>();
    ZooKeeperEphemeralStore<String> zk = new ZooKeeperEphemeralStore<String>(zkClient, new PropertyStringSerializer(), merger, "/test/lb/test-property-ephemeral", false, true);
    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");
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    zk.remove("foo12");
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    zkClient.getZooKeeper().close();
    executorService.shutdown();
}
Also used : PropertyStringMerger(com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStoreTest.PropertyStringMerger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) PropertyEventBusImpl(com.linkedin.d2.discovery.event.PropertyEventBusImpl) HashSet(java.util.HashSet)

Example 2 with PropertyStringMerger

use of com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStoreTest.PropertyStringMerger in project rest.li by linkedin.

the class ZooKeeperEphemeralStoreTest method getStore.

public ZooKeeperEphemeralStore<String> getStore() throws IOException, PropertyStoreException, InterruptedException, ExecutionException {
    ZKConnection client = new ZKConnection("localhost:" + _port, 5000);
    client.start();
    ZooKeeperEphemeralStore<String> store = new ZooKeeperEphemeralStore<String>(client, new PropertyStringSerializer(), new PropertyStringMerger(), "/test-path", false, true);
    FutureCallback<None> callback = new FutureCallback<None>();
    store.start(callback);
    callback.get();
    return store;
}
Also used : None(com.linkedin.common.util.None) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) FutureCallback(com.linkedin.common.callback.FutureCallback)

Aggregations

PropertyStringSerializer (com.linkedin.d2.discovery.stores.PropertyStringSerializer)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 PropertyEventBusImpl (com.linkedin.d2.discovery.event.PropertyEventBusImpl)1 PropertyStringMerger (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStoreTest.PropertyStringMerger)1 HashSet (java.util.HashSet)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1