@Override public ControlNodeInfo getControlServerInfo() { if (controlCache != null && controlCache.getCurrentData() != null) { return extractControlServerInfo(controlCache.getCurrentData()); } else { return null; } }
@Override public void nodeChanged() throws Exception { ChildData currentData = controlCache.getCurrentData(); if (currentData == null) { LOG.warn("Control service node died!"); onNoMaster(); } else { LOG.warn("Control service node changed!"); onMasterChange(currentData); } } });
@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); } } };
@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); } } };
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()); }
private OptionalLong getExpireBefore() { ChildData data = cache.getCurrentData(); if (data == null) { return OptionalLong.empty(); } byte[] bytes = data.getData(); if (bytes == null || bytes.length != Long.BYTES) { return OptionalLong.empty(); } return OptionalLong.of(Bytes.toLong(bytes)); }
@Override public void nodeChanged() { String configInfo = null; ChildData childData = nodeCache.getCurrentData(); if (null != childData && childData.getData() != null) { configInfo = new String(childData.getData()); } RecordLog.info(String.format("[ZookeeperDataSource] New property value received for (%s, %s): %s", serverAddr, path, configInfo)); T newValue = ZookeeperDataSource.this.parser.convert(configInfo); // Update the new value to the property. getProperty().updateValue(newValue); } };
@Override public void nodeChanged() throws Exception { log.info("config changed, update"); ChildData data = cache.getCurrentData(); if (null != data) { String config = new String(cache.getCurrentData().getData()); updateConfig(config); } else { log.warn("node is deleted"); } } };
@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); } });
private String loadKeyFromNodeCache(final String key) throws Exception { NodeCache nodeCache = nodeCacheMap.get(key); if (nodeCache == null) { nodeCache = newNodeCache(key); nodeCacheMap.put(key, nodeCache); } byte[] data = nodeCache.getCurrentData().getData(); return new String(data, Constants.DEFAULT_CHARSET); }
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; }
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() {
private String getCurrentTSOInfoFoundInZK(String currentTsoPath) { ChildData currentTSOData = currentTSOZNode.getCurrentData(); if (currentTSOData == null) { throw new IllegalStateException("No data found in ZKNode " + currentTsoPath); } byte[] currentTSOAndEpochAsBytes = currentTSOData.getData(); if (currentTSOAndEpochAsBytes == null) { throw new IllegalStateException("No data found for current TSO in ZKNode " + currentTsoPath); } return new String(currentTSOAndEpochAsBytes, Charsets.UTF_8); }
private String getCurrentTSOInfoFoundInZK(String currentTsoPath) { ChildData currentTSOData = currentTSOZNode.getCurrentData(); if (currentTSOData == null) { throw new IllegalStateException("No data found in ZKNode " + currentTsoPath); } byte[] currentTSOAndEpochAsBytes = currentTSOData.getData(); if (currentTSOAndEpochAsBytes == null) { throw new IllegalStateException("No data found for current TSO in ZKNode " + currentTsoPath); } return new String(currentTSOAndEpochAsBytes, Charsets.UTF_8); }
public String getData(){ ChildData child = node.getCurrentData(); return child == null ? null : new String(child.getData()); }
@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"); } });
@Override public void nodeChanged() throws Exception { ChildData node = nodeCache.getCurrentData(); if (node == null || !uuid.equals(new String(node.getData(), StandardCharsets.UTF_8))) { Halt.halt("Fluo Application UUID has changed or disappeared"); } } });
@Override public void nodeChanged() { final String jobStr = new String(jobCache.getCurrentData().getData()); final JobSlice slice = genJobSlice(jobStr); service.run(slice); }
@Override public void nodeChanged() throws Exception { ChildData data = node.getCurrentData(); if (data != null){ listener.onUpdate(data.getData()); } else { listener.onDelete(); } } });
@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; }