當前位置: 首頁>>代碼示例>>Java>>正文


Java PathChildrenCache類代碼示例

本文整理匯總了Java中org.apache.curator.framework.recipes.cache.PathChildrenCache的典型用法代碼示例。如果您正苦於以下問題:Java PathChildrenCache類的具體用法?Java PathChildrenCache怎麽用?Java PathChildrenCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PathChildrenCache類屬於org.apache.curator.framework.recipes.cache包,在下文中一共展示了PathChildrenCache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@PostConstruct
public void init() {
  log.info("Initializing...");
  Assert.hasLength(zkUrl, MiscUtils.missingProperty("zk.url"));
  Assert.notNull(zkRetryInterval, MiscUtils.missingProperty("zk.retry_interval_ms"));
  Assert.notNull(zkConnectionTimeout, MiscUtils.missingProperty("zk.connection_timeout_ms"));
  Assert.notNull(zkSessionTimeout, MiscUtils.missingProperty("zk.session_timeout_ms"));

  log.info("Initializing discovery service using ZK connect string: {}", zkUrl);

  zkNodesDir = zkDir + "/nodes";
  try {
    client = CuratorFrameworkFactory.newClient(zkUrl, zkSessionTimeout, zkConnectionTimeout,
        new RetryForever(zkRetryInterval));
    client.start();
    client.blockUntilConnected();
    cache = new PathChildrenCache(client, zkNodesDir, true);
    cache.getListenable().addListener(this);
    cache.start();
  } catch (Exception e) {
    log.error("Failed to connect to ZK: {}", e.getMessage(), e);
    CloseableUtils.closeQuietly(client);
    throw new RuntimeException(e);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:26,代碼來源:ZkDiscoveryService.java

示例2: ZooKeeperCommandExecutor

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
private ZooKeeperCommandExecutor(String replicaId, CommandExecutor delegate, CuratorFramework curator,
                                 String zkPath, boolean createPathIfNotExist, File revisionFile,
                                 int numWorkers, int maxLogCount, long minLogAgeMillis) {
    super(replicaId);

    this.delegate = delegate;
    this.revisionFile = revisionFile;
    this.curator = curator;
    this.zkPath = zkPath;
    this.createPathIfNotExist = createPathIfNotExist;
    this.maxLogCount = maxLogCount;
    this.minLogAgeMillis = minLogAgeMillis;

    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
            numWorkers, numWorkers,
            60, TimeUnit.SECONDS, new LinkedTransferQueue<>(),
            new DefaultThreadFactory("zookeeper-command-executor", true));
    executor.allowCoreThreadTimeOut(true);
    this.executor = executor;

    logWatcher = new PathChildrenCache(curator, absolutePath(LOG_PATH), true);
    logWatcher.getListenable().addListener(this, MoreExecutors.directExecutor());
    oldLogRemover = new OldLogRemover();
    leaderSelector = new LeaderSelector(curator, absolutePath(LEADER_PATH), oldLogRemover);
    leaderSelector.autoRequeue();
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:27,代碼來源:ZooKeeperCommandExecutor.java

示例3: watchSlave

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@Override
public void watchSlave() {
    if(client==null){
        throw new IllegalArgumentException("param illegal with client={null}");
    }
    try {
        initSlaveNode();
        PathChildrenCache watcher = new PathChildrenCache(
                client,
                ZkNode.ROOT_NODE_PATH,
                true
        );
        watcher.getListenable().addListener(new SlaveNodeWatcher());
        watcher.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
    }catch(Exception e){
        LOGGER.error("watchSlave error cause:",e);
    }
}
 
開發者ID:all4you,項目名稱:redant,代碼行數:19,代碼來源:DefaultServiceDiscovery.java

示例4: start

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
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. ");
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:17,代碼來源:RefreshableTransportPool.java

示例5: addChildPathCache

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
public  static void addChildPathCache(  String path ,PathChildrenCacheListener listener )
{
    NameableExecutor businessExecutor = MycatServer.getInstance().getBusinessExecutor();
    ExecutorService executor = businessExecutor ==null?Executors.newFixedThreadPool(5):
            businessExecutor;

    try {
        /**
         * 監聽子節點的變化情況
         */
        final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
        childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
        childrenCache.getListenable().addListener(listener,executor);
    } catch (Exception e) {
       throw new RuntimeException(e);
    }
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:18,代碼來源:ZKUtils.java

示例6: listenerPathChildrenCache

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
/**
     * 設置子節點更改監聽
     *
     * @param path
     * @throws Exception
     */
    public boolean listenerPathChildrenCache(String path, BiConsumer<CuratorFramework, PathChildrenCacheEvent> biConsumer) {

        if (!ObjectUtils.allNotNull(zkClient, path, biConsumer)) {
            return Boolean.FALSE;
        }
        try {
            Stat stat = exists(path);
            if (stat != null) {
                PathChildrenCache watcher = new PathChildrenCache(zkClient, path, true);
                watcher.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
                //該模式下 watcher在重連的時候會自動 rebuild 否則需要重新rebuild
                watcher.getListenable().addListener(biConsumer::accept, pool);
                if (!pathChildrenCaches.contains(watcher)) {
                    pathChildrenCaches.add(watcher);
                }
//                else{
//                    watcher.rebuild();
//                }
                return Boolean.TRUE;
            }
        } catch (Exception e) {
            log.error("listen path children cache fail! path:{} , error:{}", path, e);
        }
        return Boolean.FALSE;
    }
 
開發者ID:lee123lee123,項目名稱:GoPush,代碼行數:32,代碼來源:ZkUtils.java

示例7: createPathCache

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@Override
public PathChildrenCache createPathCache(String type, boolean cacheData, PathChildrenCacheListener listener,
	StartMode startMode)
{
	try
	{
		PathChildrenCache cache = new PathChildrenCache(client, getParentPath(type), cacheData);
		if( listener != null )
		{
			cache.getListenable().addListener(listener);
		}
		cache.start(startMode);
		return cache;
	}
	catch( Exception e )
	{
		throw Throwables.propagate(e);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:20,代碼來源:ZookeeperServiceImpl.java

示例8: ZkAbstractStore

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
public ZkAbstractStore(CuratorFramework framework, PStoreConfig<V> config)
    throws IOException {
  this.parent = "/" + config.getName();
  this.prefix = parent + "/";
  this.framework = framework;
  this.config = config;

  // make sure the parent node exists.
  try {
    if (framework.checkExists().forPath(parent) == null) {
      framework.create().withMode(CreateMode.PERSISTENT).forPath(parent);
    }

    this.childrenCache = new PathChildrenCache(framework, parent, true);
    this.childrenCache.start(StartMode.BUILD_INITIAL_CACHE);

  } catch (Exception e) {
    throw new RuntimeException("Failure while accessing Zookeeper for PStore: " + e.getMessage(), e);
  }

}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:22,代碼來源:ZkAbstractStore.java

示例9: close

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
/**
 * Close the trigger.
 */
@Override
public void close() {
    // Close each of the caches that we originally opened
    for (PathChildrenCache cache : caches) {
        try {
            cache.close();
        } catch (IOException ex) {
            logger.error("Unable to close cache {}", ex);
        }
    }

    if (curator != null) {
        curator.close();
        curator = null;
        curatorHelper = null;
    }

    isOpen = false;
}
 
開發者ID:salesforce,項目名稱:storm-dynamic-spout,代碼行數:23,代碼來源:ZookeeperWatchTrigger.java

示例10: ServiceCacheImplProxy

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
public ServiceCacheImplProxy(ServiceDiscoveryImpl<T> discovery, String name, ThreadFactory threadFactory) {
    this.serviceCacheImpl = new ServiceCacheImpl<T>(discovery, name, threadFactory);

    try {
        Field privateListenerContainerField = ServiceCacheImpl.class.getDeclaredField("listenerContainer");
        privateListenerContainerField.setAccessible(true);
        this.listenerContainer = (ListenerContainer)privateListenerContainerField.get(serviceCacheImpl);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        log.error("Failed to construct Service Cache. Container listeners is null.");
    }

    Preconditions.checkNotNull(discovery, "discovery cannot be null");
    Preconditions.checkNotNull(name, "name cannot be null");
    Preconditions.checkNotNull(threadFactory, "threadFactory cannot be null");
    Preconditions.checkNotNull(this.listenerContainer, "container of listeners can not be null");


    this.discovery = discovery;
    this.cache = new PathChildrenCache(discovery.getClient(), discovery.pathForName(name), true, threadFactory);
    this.cache.getListenable().addListener(this);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:22,代碼來源:ServiceCacheImplProxy.java

示例11: start

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@Override
public void start(final PathChildrenCache.StartMode startMode) throws DataSourceConnectorException {
    if (useCache || useCacheWhenNotConnectedToDataSource) {
        if (! connector.isConnected()) {
            throw new DataSourceConnectorException("Failed to start cache for path=" + path + " due to no connection");
        }
        try {
            cache.start(startMode);
            allowUseCache();

            log.debug("Successfully started cache for path={}", path);
        } catch (Exception e) {
            log.error("Failed to start cache for path={}", path, e);
        }
    }
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:17,代碼來源:ZkPathChildrenCacheWrapper.java

示例12: applyChangesToHostCaches

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
void applyChangesToHostCaches(Set<XreStackPath> allStackPaths) {
    List<XreStackPath> keysToRemove = hostCaches.keySet().stream().filter(xreStackPath -> !allStackPaths.contains(xreStackPath)).collect(Collectors.toList());
    keysToRemove.forEach(key -> {
        closeCache(key);
        hostCaches.remove(key);
    });

    allStackPaths.stream()
        .filter(path -> ! hostCaches.keySet().contains(path))
        .forEach(xreStackPath -> {
            PathChildrenCache cache = new PathChildrenCache(curator, getAbsolutePath(xreStackPath.getPath()), true);
            cache.getListenable().addListener((client, event) -> listenersNotifier.notifyListeners());
            try {
                cache.start();
            } catch (Exception e) {
                log.error("Failed to start cache for discovered xreStackPath=" + xreStackPath.getPath(), e.getMessage());
            }

            hostCaches.put(xreStackPath, cache);
        });
    log.info("DiscoveredStacksCount=" + allStackPaths.size() + " and AppliedStacksCount=" + hostCaches.size());
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:23,代碼來源:ServiceDiscovery.java

示例13: watchService

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@Override
    public void watchService() {
        logger.info("watchService {}", path);
        cache =new PathChildrenCache(curatorFramework, path
                ,true);
        cache.getListenable().addListener((client,event)->{
            switch (event.getType()) {
                case CHILD_ADDED:
                    dealAdd(event);
                    break;
                case CHILD_REMOVED:
                    dealRemove(event);
                    break;
                default:
                    break;
            }
        });
        try {
//          PathChildrenCache.StartMode.POST_INITIALIZED_EVENT
            cache.start();
//            countDownLatch.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
開發者ID:somewhereMrli,項目名稱:albedo-thrift,代碼行數:26,代碼來源:ZookeeperServiceDiscover.java

示例14: listen

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@PostConstruct
public void listen() throws Exception {
    StandbyApiFactory standbyApiFactory = new StandbyApiFactoryImpl(client);
    PathChildrenCache pathChildrenCache = new PathChildrenCache(client, standbyApiFactory.pathApi().getJobPath(), true);
    pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
        @Override
        public synchronized void childEvent(CuratorFramework clientInner, PathChildrenCacheEvent event) throws Exception {
            if (!EventHelper.isChildUpdateEvent(event) && !EventHelper.isChildAddEvent(event)) {
                return;
            }
            StandbyJobData standbyJobData = new StandbyJobData(event.getData());
            if (!standbyJobData.getData().isOperated()) {
                return;
            }
            LoggerHelper.info("begin update standby job summary " + standbyJobData.getData());
            standbyJobSummaryService.updateJobSummary(standbyJobData.getData());
            standbyJobLogService.updateJobLog(standbyJobData.getData());
            LoggerHelper.info("update standby job summary successfully " + standbyJobData.getData());
        }
    });
    pathChildrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
}
 
開發者ID:xiaolongzuo,項目名稱:niubi-job,代碼行數:23,代碼來源:StandbyJobSummaryListener.java

示例15: listen

import org.apache.curator.framework.recipes.cache.PathChildrenCache; //導入依賴的package包/類
@PostConstruct
public void listen() throws Exception {
    MasterSlaveApiFactory masterSlaveApiFactory = new MasterSlaveApiFactoryImpl(client);
    PathChildrenCache pathChildrenCache = new PathChildrenCache(client, masterSlaveApiFactory.pathApi().getJobPath(), true);
    pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
        @Override
        public synchronized void childEvent(CuratorFramework clientInner, PathChildrenCacheEvent event) throws Exception {
            if (!EventHelper.isChildUpdateEvent(event) && !EventHelper.isChildAddEvent(event)) {
                return;
            }
            MasterSlaveJobData masterSlaveJobData = new MasterSlaveJobData(event.getData());
            if (!masterSlaveJobData.getData().isOperated()) {
                return;
            }
            LoggerHelper.info("begin update master-slave job summary " + masterSlaveJobData.getData());
            masterSlaveJobSummaryService.updateJobSummary(masterSlaveJobData.getData());
            masterSlaveJobLogService.updateJobLog(masterSlaveJobData.getData());
            LoggerHelper.info("update master-slave job summary successfully " + masterSlaveJobData.getData());
        }
    });
    pathChildrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
}
 
開發者ID:xiaolongzuo,項目名稱:niubi-job,代碼行數:23,代碼來源:MasterSlaveJobSummaryListener.java


注:本文中的org.apache.curator.framework.recipes.cache.PathChildrenCache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。