src/main/java/net/batchik/crdt/zookeeper/ZKServiceDiscovery.java
/**
     * Adds a listener to the given service to notice for changes to the cluster membership.
     * @param serviceListener the listener to call with the new nodes
     */
Adds a listener to the given service to notice for changes to the cluster membership.
@param serviceListener the listener to call with the new nodes
Adds a listener to the given service to notice for changes to the cluster membership . @param serviceListener the listener to call with the new nodes
public void addListener(final ZKServiceListener serviceListener) {
        cache.addListener(new ServiceCacheListener() {
            /**
             * Called when there is a state change in the connection
             *
             * @param client   the client
             * @param newState the new state
             */
            @Override
            public void stateChanged(CuratorFramework client, ConnectionState newState) {
            }
            /**
             * Called when the cache has changed (instances added/deleted, etc.)
             */
            @Override
            public void cacheChanged() {
                try {
                    for (ServiceInstance<String> instance : serviceDiscovery.queryForInstances(serviceName)) {
                        String address = instance.getAddress() + ":" + instance.getPort();
                        serviceListener.newPeer(address);
                    }
                } catch (Exception e) { }
            }
        }, Executors.newSingleThreadExecutor());
    }
public void addListener ( final ZKServiceListener serviceListener ) { cache . addListener ( new ServiceCacheListener ( ) { /**
             * Called when there is a state change in the connection
             *
             * @param client   the client
             * @param newState the new state
             */ @ Override public void stateChanged ( CuratorFramework client , ConnectionState newState ) { } /**
             * Called when the cache has changed (instances added/deleted, etc.)
             */ @ Override public void cacheChanged ( ) { try { for ( ServiceInstance < String > instance : serviceDiscovery . queryForInstances ( serviceName ) ) { String address = instance . getAddress ( ) + ":" + instance . getPort ( ) ; serviceListener . newPeer ( address ) ; } } catch ( Exception e ) { } } } , Executors . newSingleThreadExecutor ( ) ) ; }
Adds a listener to the given service to notice for changes to the cluster membership.
Adds a listener to the given service to notice for changes to the cluster membership .