public void addListener(PathChildrenCacheListener listener) { statusCache.getListenable().addListener(listener); }
@Override public void close() { if (clusterId != null) { client.getConnectionStateListenable().removeListener(connectionStateListener); } client.close(); }
public void registerListener(TreeCacheListener listener) { cache.getListenable().addListener(listener); }
@Override public void close() throws Exception { if (this.nodeCache != null) { this.nodeCache.getListenable().removeListener(listener); this.nodeCache.close(); } if (this.zkClient != null) { this.zkClient.close(); } pool.shutdown(); }
/** * Adds a listener to the pathChildrenCache, initializes the cache, then starts the cache-management background * thread */ private void buildCache() throws Exception { this.treeCache = new TreeCache(client, rootPath); // create the watcher for future configuration updates treeCache.getListenable().addListener(cacheListener, executor); // it's not blocking, so we use an extra latch 'initializedLatch' to make sure cache fully initialized before use. treeCache.start(); initializedLatch.await(); } }
private void registerRunListener() { pathChildrenCache.getListenable().addListener( new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework curatorFramework, PathChildrenCacheEvent pathChildrenCacheEvent) throws Exception { if (pathChildrenCacheEvent.getType().equals(PathChildrenCacheEvent.Type.CHILD_ADDED)) { final Task task = jsonMapper.readValue( cf.getData().forPath(pathChildrenCacheEvent.getData().getPath()), Task.class ); assignTask(task); } } } ); }
@Override public void close() throws InterruptedException { // NOTE: the curator instance is NOT closed here CuratorListener localListener = listener.getAndSet(null); if ( localListener != null ) { curator.getCuratorListenable().removeListener(localListener); } }
public void stopListener() { try { if (start.compareAndSet(true, false)) { nodeCache.getListenable().removeListener(nodeCacheListener); nodeCache.close(); } } catch (IOException e) { throw new ZkException(e); } } }
/** * Adds a listener to the pathChildrenCache, initializes the cache, then starts the cache-management background * thread */ private void buildCache() throws Exception { this.treeCache = new TreeCache(client, rootPath); // create the watcher for future configuration updates treeCache.getListenable().addListener(cacheListener, executor); // it's not blocking, so we use an extra latch 'initializedLatch' to make sure cache fully initialized before use. treeCache.start(); initializedLatch.await(); } }
public void start() { try { cache.getListenable().addListener((client, event) -> handleChildEvent(event)); cache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT); } catch (Exception ex) { throw Throwables.propagate(ex); } }
@Override public void stateChanged(CuratorFramework client, ConnectionState newState) { if (newState == ConnectionState.CONNECTED) { initialConnection.countDown(); client.getConnectionStateListenable().removeListener(this); } }
public void stopListener() { try { if (start.compareAndSet(true, false)) { childrenCache.getListenable().removeListener(childrenCacheListener); childrenCache.clear(); childrenCache.close(); } } catch (IOException e) { throw new ZkException(e); } } }
/** * 注册数据监听器. * * @param listener 数据监听器 */ public void addDataListener(final TreeCacheListener listener) { TreeCache cache = (TreeCache) regCenter.getRawCache("/" + jobName); cache.getListenable().addListener(listener); }
public void startListener() { try { if (start.compareAndSet(false, true)) { childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT); childrenCache.getListenable().addListener(childrenCacheListener); } } catch (Exception e) { throw new ZkException(e); } }
/** * 注册连接状态监听器. * * @param listener 连接状态监听器 */ public void addConnectionStateListener(final ConnectionStateListener listener) { getClient().getConnectionStateListenable().addListener(listener); }
public void startListener() { try { if (start.compareAndSet(false, true)) { nodeCache.start(true); nodeCache.getListenable().addListener(nodeCacheListener); } } catch (Exception e) { throw new ZkException(e); } }
@Override public void start() { if (client.getState() != CuratorFrameworkState.STARTED) { client.start(); if (clusterId != null) { client.getConnectionStateListenable().addListener(connectionStateListener); checkClusterIdExists(clusterId, "start"); } } }
@SuppressWarnings("resource") private synchronized void startListen(String destination, BooleanMutex mutex) { try { String path = SYN_SWITCH_ZK_NODE + destination; CuratorFramework curator = curatorClient.getCurator(); NodeCache nodeCache = new NodeCache(curator, path); nodeCache.start(); nodeCache.getListenable().addListener(() -> initMutex(curator, destination, mutex)); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }
@Override public void start() { client.start(); client.getConnectionStateListenable().addListener( (client, newState) -> reporter.connectionStateChanged(newState)); }
public void afterPropertiesSet() throws Exception { if (this.initializeEnabled) { this.initializeIndexIfNecessary(); } this.curatorFramework.blockUntilConnected(); this.curatorFramework.getConnectionStateListenable().addListener(this); this.initializeClusterInstancesDirectory(); this.initializeClusterInstanceVersion(); this.initializeClusterInstanceConfig(true); }