org.apache.curator.framework.recipes.cache.PathChildrenCache.StartMode Java Examples
The following examples show how to use
org.apache.curator.framework.recipes.cache.PathChildrenCache.StartMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetaServerAssignmentHolder.java From hermes with Apache License 2.0 | 6 votes |
private void initPathChildrenCache() throws InitializationException { m_pathChildrenCache = new PathChildrenCache(m_zkClient.get(), ZKPathUtils.getMetaServerAssignmentRootZkPath(), true); m_pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED || event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED || event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) { String topic = ZKPathUtils.lastSegment(event.getData().getPath()); m_topiAssignmentCache.invalidate(topic); } } }); try { m_pathChildrenCache.start(StartMode.BUILD_INITIAL_CACHE); } catch (Exception e) { throw new InitializationException("Init metaServerAssignmentHolder failed.", e); } }
Example #2
Source File: RefreshableTransportPool.java From jigsaw-payment with Apache License 2.0 | 6 votes |
public void start() throws Exception { if (this.cache == null) { if (this.executorService == null) { this.cache = new PathChildrenCache(client, path, cacheData); } else { this.cache = new PathChildrenCache(client, path, cacheData, dataIsCompressed, this.executorService); } } this.cache.getListenable().addListener(this); this.cache.start(StartMode.POST_INITIALIZED_EVENT); //this.prepareInstances(); // call super to initialize the pool; super.start(); LOG.info("transport pooling factory started. "); }
Example #3
Source File: TransactorCache.java From fluo with Apache License 2.0 | 6 votes |
public TransactorCache(Environment env) { final FluoConfiguration conf = env.getConfiguration(); timeoutCache = CacheBuilder.newBuilder().maximumSize(FluoConfigurationImpl.getTransactorMaxCacheSize(conf)) .expireAfterAccess( FluoConfigurationImpl.getTransactorCacheTimeout(conf, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .concurrencyLevel(10).build(); this.env = env; cache = new PathChildrenCache(env.getSharedResources().getCurator(), ZookeeperPath.TRANSACTOR_NODES, true); try { cache.start(StartMode.BUILD_INITIAL_CACHE); status = TcStatus.OPEN; } catch (Exception e) { throw new RuntimeException(e); } }
Example #4
Source File: ClusterStateHolder.java From hermes with Apache License 2.0 | 5 votes |
private void startLeaderLatchPathChildrenCache() throws InitializationException { try { m_leaderLatchPathChildrenCache = new PathChildrenCache(m_client.get(), ZKPathUtils.getMetaServersZkPath(), true); m_leaderLatchPathChildrenCache.getListenable().addListener( new PathChildrenCacheListener() { @Override public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED || event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED || event.getType() == PathChildrenCacheEvent.Type.CHILD_UPDATED) { updateLeaderInfo(); } } }, Executors.newSingleThreadExecutor(HermesThreadFactory.create( "LeaderLatchPathChildrenCacheListenerExecutor", true))); m_leaderLatchPathChildrenCache.start(StartMode.BUILD_INITIAL_CACHE); } catch (Exception e) { throw new InitializationException("Init metaServer leaderLatch parent pathChildrenCache failed.", e); } updateLeaderInfo(); }
Example #5
Source File: PartitionManager.java From fluo with Apache License 2.0 | 5 votes |
PartitionManager(Environment env, long minSleepTime, long maxSleepTime) { try { this.curator = env.getSharedResources().getCurator(); this.env = env; this.minSleepTime = minSleepTime; this.maxSleepTime = maxSleepTime; this.retrySleepTime = minSleepTime; groupSize = env.getConfiguration().getInt(FluoConfigurationImpl.WORKER_PARTITION_GROUP_SIZE, FluoConfigurationImpl.WORKER_PARTITION_GROUP_SIZE_DEFAULT); myESNode = new PersistentNode(curator, CreateMode.EPHEMERAL_SEQUENTIAL, false, ZookeeperPath.FINDERS + "/" + ZK_FINDER_PREFIX, ("" + groupSize).getBytes(UTF_8)); myESNode.start(); myESNode.waitForInitialCreate(1, TimeUnit.MINUTES); childrenCache = new PathChildrenCache(curator, ZookeeperPath.FINDERS, true); childrenCache.getListenable().addListener(new FindersListener()); childrenCache.start(StartMode.BUILD_INITIAL_CACHE); schedExecutor = Executors.newScheduledThreadPool(1, new FluoThreadFactory("Fluo worker partition manager")); schedExecutor.scheduleWithFixedDelay(new CheckTabletsTask(), 0, maxSleepTime, TimeUnit.MILLISECONDS); scheduleUpdate(); } catch (Exception e) { throw new RuntimeException(e); } }
Example #6
Source File: CuratorKafkaMonitor.java From Kafdrop with Apache License 2.0 | 4 votes |
public CuratorKafkaMonitor(CuratorFramework curatorFramework, CuratorKafkaMonitorProperties properties, ObjectMapper objectMapper) throws Exception { this.curatorFramework = curatorFramework; this.properties = properties; this.objectMapper = objectMapper; try { kafkaVersion = new Version(properties.getKafkaVersion()); } catch (Exception ex) { throw new IllegalStateException("Invalid kafka version: " + properties.getKafkaVersion(), ex); } threadPool = new ForkJoinPool(properties.getThreadPoolSize()); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(properties.getRetry().getBackoffMillis()); final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(properties.getRetry().getMaxAttempts(), ImmutableMap.of(InterruptedException.class, false, Exception.class, true)); retryTemplate = new RetryTemplate(); retryTemplate.setBackOffPolicy(backOffPolicy); retryTemplate.setRetryPolicy(retryPolicy); cacheInitCounter.set(4); brokerPathCache = new PathChildrenCache(curatorFramework, ZkUtils.BrokerIdsPath(), true); brokerPathCache.getListenable().addListener(new BrokerListener()); brokerPathCache.getListenable().addListener((f, e) -> { if (e.getType() == PathChildrenCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Broker cache initialized"); } }); brokerPathCache.start(StartMode.POST_INITIALIZED_EVENT); topicConfigPathCache = new PathChildrenCache(curatorFramework, ZkUtils.TopicConfigPath(), true); topicConfigPathCache.getListenable().addListener((f, e) -> { if (e.getType() == PathChildrenCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Topic configuration cache initialized"); } }); topicConfigPathCache.start(StartMode.POST_INITIALIZED_EVENT); topicTreeCache = new TreeCache(curatorFramework, ZkUtils.BrokerTopicsPath()); topicTreeCache.getListenable().addListener((client, event) -> { if (event.getType() == TreeCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Topic tree cache initialized"); } }); topicTreeCache.start(); consumerTreeCache = new TreeCache(curatorFramework, ZkUtils.ConsumersPath()); consumerTreeCache.getListenable().addListener((client, event) -> { if (event.getType() == TreeCacheEvent.Type.INITIALIZED) { cacheInitCounter.decrementAndGet(); LOG.info("Consumer tree cache initialized"); } }); consumerTreeCache.start(); controllerNodeCache = new NodeCache(curatorFramework, ZkUtils.ControllerPath()); controllerNodeCache.getListenable().addListener(this::updateController); controllerNodeCache.start(true); updateController(); }
Example #7
Source File: BaragonAuthUpdater.java From Baragon with Apache License 2.0 | 4 votes |
@Override public void start() throws Exception { pathChildrenCache.start(StartMode.BUILD_INITIAL_CACHE); pathChildrenCache.getListenable().addListener(this); }