@Override public TaskAnnouncement apply(ChildData input) { try { return jsonMapper.readValue(input.getData(), TaskAnnouncement.class); } catch (Exception e) { throw Throwables.propagate(e); } } };
/** * @param key e.g., {service}.configurators, {service}.tagrouters, {group}.dubbo.properties * @return */ @Override public Object getInternalProperty(String key) { ChildData childData = treeCache.getCurrentData(key); if (childData != null) { return new String(childData.getData(), StandardCharsets.UTF_8); } return null; }
/** * @param key e.g., {service}.configurators, {service}.tagrouters, {group}.dubbo.properties * @return */ @Override public Object getInternalProperty(String key) { ChildData childData = treeCache.getCurrentData(key); if (childData != null) { return new String(childData.getData(), StandardCharsets.UTF_8); } return null; }
private static String extractWorkerIdFromSlot(ChildData childData) { return new String(childData.getData(), SlotZnode.CHARSET); }
protected static byte[] getWorkerData(ChildData childData, String workerNodePrefix) { if (childData == null) return null; byte[] data = childData.getData(); if (data == null) return null; if (!extractNodeName(childData).startsWith(workerNodePrefix)) return null; return data; }
@Override public String get(final String key) { TreeCache cache = findTreeCache(key); if (null == cache) { return getDirectly(key); } ChildData resultInCache = cache.getCurrentData(key); if (null != resultInCache) { return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8); } return getDirectly(key); }
@Override public final void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception { ChildData childData = event.getData(); if (null == childData) { return; } String path = childData.getPath(); if (path.isEmpty()) { return; } dataChanged(path, event.getType(), null == childData.getData() ? "" : new String(childData.getData(), Charsets.UTF_8)); }
@Override public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws UnsupportedEncodingException { ChildData data = event.getData(); if (null == data || null == data.getPath()) { return; } ChangedType changedType = getChangedType(event); if (ChangedType.IGNORED != changedType) { dataChangedEventListener.onChange(new DataChangedEvent(data.getPath(), null == data.getData() ? null : new String(data.getData(), "UTF-8"), changedType)); } } });
private void processTokenRemoved(ChildData data) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(data.getData()); DataInputStream din = new DataInputStream(bin); TokenIdent ident = createIdentifier(); ident.readFields(din); synchronized (this) { currentTokens.remove(ident); // The cancel task might be waiting notifyAll(); } }
@Override public String get(final String key) { TreeCache cache = findTreeCache(key); if (null == cache) { return getDirectly(key); } ChildData resultInCache = cache.getCurrentData(key); if (null != resultInCache) { return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8); } return getDirectly(key); }
@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); } };
private void dumpDirectly(final String path, final List<String> result) { for (String each : regCenter.getChildrenKeys(path)) { String zkPath = path + "/" + each; String zkValue = regCenter.get(zkPath); if (null == zkValue) { zkValue = ""; } TreeCache treeCache = (TreeCache) regCenter.getRawCache("/" + jobName); ChildData treeCacheData = treeCache.getCurrentData(zkPath); String treeCachePath = null == treeCacheData ? "" : treeCacheData.getPath(); String treeCacheValue = null == treeCacheData ? "" : new String(treeCacheData.getData()); if (zkValue.equals(treeCacheValue) && zkPath.equals(treeCachePath)) { result.add(Joiner.on(" | ").join(zkPath, zkValue)); } else { result.add(Joiner.on(" | ").join(zkPath, zkValue, treeCachePath, treeCacheValue)); } dumpDirectly(zkPath, result); } }
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()); }
byte[] value = data.getData(); String key = pathToKey(data.getPath()); ConfigChangeType changeType;
byte[] value = data.getData(); String key = pathToKey(data.getPath()); ConfigChangeType changeType;
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 childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) { DataSegmentChangeRequest request = jsonMapper.readValue( event.getData().getData(), DataSegmentChangeRequest.class ); request.go(handler, null); } } }
private InstanceType extractServiceInstance( PathChildrenCacheEvent event, ChildData childData) { byte[] data = childData.getData(); if (data == null) return null; try { ServiceRecord srv = encoder.fromBytes(event.getData().getPath(), data); return createServiceInstance(srv); } catch (IOException e) { LOG.error("Unable to decode data for zknode: {}." + " Dropping notification of type: {}", childData.getPath(), event.getType()); return null; } }
@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); } } };