public PathChildrenListener(String path, final ChildListener listener) { childrenCache = new PathChildrenCache(client, path, true); childrenCacheListener = new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework c, PathChildrenCacheEvent event) throws Exception { switch (event.getType()) { case CHILD_ADDED: case CHILD_REMOVED: case CHILD_UPDATED: String childPath = event.getData().getPath(); String parentPath = childPath.substring(0, childPath.lastIndexOf("/")); List<String> children = client.getChildren().forPath(parentPath); listener.childChanged(parentPath, children); default: break; } } }; }
public PathChildrenListener(String path, final ChildListener listener) { childrenCache = new PathChildrenCache(client, path, true); childrenCacheListener = new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework c, PathChildrenCacheEvent event) throws Exception { switch (event.getType()) { case CHILD_ADDED: case CHILD_REMOVED: case CHILD_UPDATED: String childPath = event.getData().getPath(); String parentPath = childPath.substring(0, childPath.lastIndexOf("/")); List<String> children = client.getChildren().forPath(parentPath); listener.childChanged(parentPath, children); default: break; } } }; }
private void init() { endpointCache = new PathChildrenCache(zkClient, OPERATIONS_SERVER_NODE_PATH, true); bootstrapCache = new PathChildrenCache(zkClient, BOOTSTRAP_SERVER_NODE_PATH, true); endpointListeners = new CopyOnWriteArrayList<OperationsNodeListener>(); bootstrapListeners = new CopyOnWriteArrayList<BootstrapNodeListener>(); operationNodesStartTimes = new HashMap<String, Long>(); bootstrapNodesStartTimes = new HashMap<String, Long>(); }
public PathChildrenCache make(CuratorFramework curator, String path) { return new PathChildrenCache( curator, path, cacheData, compressed, new CloseableExecutorService(exec, shutdownExecutorOnClose) ); }
/** * @param client curator instance for connecting to the config ensemble * @param baseZPath the base path for config nodes * @param defaults default properties * @param hostname this JVM's hostname * @throws Exception errors */ public ZookeeperConfigProvider(CuratorFramework client, String baseZPath, Properties defaults, String hostname) throws Exception { this.client = client; this.defaults = defaults; this.hostname = hostname; configPath = ZKPaths.makePath(baseZPath, CONFIG_PATH); lockPath = ZKPaths.makePath(baseZPath, LOCK_PATH); cache = new PathChildrenCache(client, configPath, true); }
@Inject public WorkerTaskMonitor( ObjectMapper jsonMapper, TaskRunner taskRunner, TaskConfig taskConfig, CuratorFramework cf, WorkerCuratorCoordinator workerCuratorCoordinator, @IndexingService DruidLeaderClient overlordClient ) { super(jsonMapper, taskRunner, taskConfig, overlordClient); this.jsonMapper = jsonMapper; this.pathChildrenCache = new PathChildrenCache( cf, workerCuratorCoordinator.getTaskPathForWorker(), false, true, Execs.makeThreadFactory("TaskMonitorCache-%s") ); this.cf = cf; this.workerCuratorCoordinator = workerCuratorCoordinator; }
long sleepTimeMs = Math.min(16, clusterReadyTimeoutMs); while (true) { instancesCache = new PathChildrenCache(zooKeeperClient, workersPath, true); instancesCache.getListenable().addListener(new InstanceStateChangeListener(), tp); try {
@Override public Closeable watchLocks(String lockPathRoot, Executor executor, final Watcher watcher) { lockPathRoot = norm(lockPathRoot); PathChildrenCache cache = new PathChildrenCache(curator, lockPathRoot, true); try { cache.start(); cache.getListenable().addListener(new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { switch (event.getType()) { case CHILD_ADDED: watcher.onLock(event.getData().getPath(), new String(event.getData().getData(), StandardCharsets.UTF_8)); break; case CHILD_REMOVED: watcher.onUnlock(event.getData().getPath(), new String(event.getData().getData(), StandardCharsets.UTF_8)); break; default: break; } } }, executor); } catch (Exception ex) { logger.error("Error to watch lock path " + lockPathRoot, ex); } return cache; }
NodeTypeWatcher( ExecutorService listenerExecutor, CuratorFramework curatorFramework, String basePath, ObjectMapper jsonMapper, NodeType nodeType ) { this.listenerExecutor = listenerExecutor; this.curatorFramework = curatorFramework; this.nodeType = nodeType; this.jsonMapper = jsonMapper; // This is required to be single threaded from Docs in PathChildrenCache; this.cacheExecutor = Execs.singleThreaded(StringUtils.format("NodeTypeWatcher[%s]", nodeType)); this.cache = new PathChildrenCache( curatorFramework, ZKPaths.makePath(basePath, nodeType.toString()), true, true, cacheExecutor ); }
@Before public void setUp() throws Exception { setupServerAndCurator(); curator.start(); curator.blockUntilConnected(); curator.create().creatingParentsIfNeeded().forPath(LOAD_QUEUE_PATH); loadQueueCache = new PathChildrenCache( curator, LOAD_QUEUE_PATH, true, true, Execs.singleThreaded("load_queue_cache-%d") ); }
final String configPath = buildConfigPath(rootPath, config); PathChildrenCache pathChildrenCache = new PathChildrenCache(zkClient, configPath, true); pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() { @Override
final String configPath = buildConfigPath(rootPath, config); PathChildrenCache pathChildrenCache = new PathChildrenCache(zkClient, configPath, true); pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() { @Override
final AbstractInterfaceConfig registerConfig = getRegisterConfig(config); PathChildrenCache pathChildrenCache = new PathChildrenCache(zkClient, overridePath, true); pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() { @Override
final AbstractInterfaceConfig registerConfig = getRegisterConfig(config); PathChildrenCache pathChildrenCache = new PathChildrenCache(zkClient, overridePath, true); pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() { @Override
druidCoordinatorConfig ); final PathChildrenCache pathChildrenCacheCold = new PathChildrenCache( curator, loadPathCold,
private PathChildrenCache pathChildrenCache(String zNodePath) { final PathChildrenCache pathChildrenCache = new PathChildrenCache(client, zNodePath, true); pathChildrenCache.getListenable().addListener((c, event) -> { switch (event.getType()) { case CHILD_ADDED: addEndpoint(nodeValueCodec.decode(event.getData().getData())); break; case CHILD_REMOVED: removeEndpoint(nodeValueCodec.decode(event.getData().getData())); break; default: break; } }); return pathChildrenCache; }
new Duration("PT0s") ); sourceLoadQueueChildrenCache = new PathChildrenCache( curator, SOURCE_LOAD_PATH, Execs.singleThreaded("coordinator_test_path_children_cache_src-%d") ); destinationLoadQueueChildrenCache = new PathChildrenCache( curator, DESTINATION_LOAD_PATH,
new Duration("PT0s") ); pathChildrenCache = new PathChildrenCache( curator, LOADPATH,
providerObserver.addProviderListener(config, providerInfoListener); pathChildrenCache = new PathChildrenCache(zkClient, providerPath, true); final PathChildrenCache finalPathChildrenCache = pathChildrenCache; pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
final String liveSegmentsLocation = ZKPaths.makePath(zkPaths.getLiveSegmentsPath(), me.getName()); loadQueueCache = new PathChildrenCache( curator, loadQueueLocation,