Refine search
@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()); } }
private void refreshConfiguration() throws IOException { LOGGER.info("Refreshing configuration from ZooKeeper"); byte[] data = null; ChildData childData = agentNodeCache.getCurrentData(); if (childData != null) { data = childData.getData(); } flumeConfiguration = configFromBytes(data); eventBus.post(getConfiguration()); }
@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(); }
public void startListener() { try { if (start.compareAndSet(false, true)) { nodeCache.start(true); nodeCache.getListenable().addListener(nodeCacheListener); } } catch (Exception e) { throw new ZkException(e); } }
private NodeCache newNodeCache(final String key) throws Exception { String path = getConfigPath(key); final NodeCache nodeCache = new NodeCache(client, path); nodeCache.getListenable().addListener(new NodeCacheListener() { @Override public void nodeChanged() throws Exception { String oldValue = keyMap.get(key); String newValue = new String(nodeCache.getCurrentData().getData()); keyMap.put(key, newValue); notifyListeners(key, oldValue, newValue); } }); nodeCache.start(true); keyMap.put(key, new String(nodeCache.getCurrentData().getData(), Constants.DEFAULT_CHARSET)); return nodeCache; }
@Override public void nodeChanged() throws Exception { String path = nodeCache.getCurrentData().getPath(); Object data = nodeCache.getCurrentData().getData(); if (data == null) { listener.dataDeleted(path); } else { listener.dataChange(path, data); } } };
@SneakyThrows(Exception.class) private NodeCache registerWatch(String watchPath) { NodeCache nodeCache = new NodeCache(zkStoreHelper.getClient(), watchPath); NodeCacheListener watchListener = () -> { currentBatch.set(nodeCache.getCurrentData().getStat().getVersion()); log.debug("Current batch for {} changed to {}", gcName, currentBatch.get()); }; nodeCache.getListenable().addListener(watchListener); nodeCache.start(); return nodeCache; }
@Override public void nodeChanged() throws Exception { System.out.println("the test node is change and result is :"); System.out.println("path : "+nodeCache.getCurrentData().getPath()); System.out.println("data : "+new String(nodeCache.getCurrentData().getData())); System.out.println("stat : "+nodeCache.getCurrentData().getStat()); } });
synchronized void start() throws Exception { _cache.getListenable().addListener(this); try { _cache.start(true); apply(_cache.getCurrentData()); } catch (ConnectionLossException e) { LOGGER.warn("Failed to connect to zookeeper, using mode {} until connection reestablished", _mode); } }
public void start() { try { ZooKeeperUtils.createDefault(curator, workerPath, null); cache.getListenable().addListener(this); cache.start(true); cache.rebuild(); } catch (Exception e) { throw FabricException.launderThrowable(e); } }
@Override public void addListener(NodeCacheListener listener) { wrapped.getListenable().addListener(listener); }
@Override public void nodeChanged() { LOGGER.info("ZktoxmlMain runWatch process path event start "); String notPath = cache.getCurrentData().getPath(); LOGGER.info("NodeCache changed, path is: " + notPath); // notify zkListen.notify(notPath); LOGGER.info("ZktoxmlMain runWatch process path event over"); } });
private void close() { if (cache != null) { try { cache.close(); } catch (IOException e) { // should not happen throw new AssertionError(e); } cache = null; } if (client != null) { client.close(); client = null; } }
public NodeListener(String path, final DataListener listener) { nodeCache = new NodeCache(client, path, false); nodeCacheListener = new NodeCacheListener() { @Override public void nodeChanged() throws Exception { String path = nodeCache.getCurrentData().getPath(); Object data = nodeCache.getCurrentData().getData(); if (data == null) { listener.dataDeleted(path); } else { listener.dataChange(path, data); } } }; }
/** * Start the cache. The cache is not started automatically. You must call this method. * * @throws Exception errors */ public void start() throws Exception { start(false); }
public void removeListener() { nodeCache.getListenable().removeListener(this); }
@Override public ControlNodeInfo getControlServerInfo() { if (controlCache != null && controlCache.getCurrentData() != null) { return extractControlServerInfo(controlCache.getCurrentData()); } else { return null; } }
public void start() throws Exception { if (client == null) { RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); client = CuratorFrameworkFactory.newClient(zkQuorum, retryPolicy); client.start(); } config = ConfigUtil.INSTANCE.read(client, root, new MaaSConfig(), MaaSConfig.class); cache = new NodeCache(client, root); cache.getListenable().addListener(() -> { byte[] data = cache.getCurrentData().getData(); Lock wLock= lock.writeLock(); wLock.lock(); try { config = _mapper.readValue(data, MaaSConfig.class); } finally { wLock.unlock(); } } ); discoverer = new ServiceDiscoverer(client, config.getServiceRoot()); discoverer.start(); } public ServiceDiscoverer getDiscoverer() {
@Override public void nodeChanged() throws Exception { String path = nodeCache.getCurrentData().getPath(); Object data = nodeCache.getCurrentData().getData(); if (data == null) { listener.dataDeleted(path); } else { listener.dataChange(path, data); } } };