当前位置: 首页>>代码示例>>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;未经允许,请勿转载。