本文整理汇总了Java中org.apache.curator.framework.recipes.cache.PathChildrenCache.start方法的典型用法代码示例。如果您正苦于以下问题:Java PathChildrenCache.start方法的具体用法?Java PathChildrenCache.start怎么用?Java PathChildrenCache.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.cache.PathChildrenCache
的用法示例。
在下文中一共展示了PathChildrenCache.start方法的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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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();
}
}
示例7: 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);
}
示例8: 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);
}
示例9: start
import org.apache.curator.framework.recipes.cache.PathChildrenCache; //导入方法依赖的package包/类
public void start() {
Preconditions.checkNotNull(nameSpace, "nameSpace can not be null");
Preconditions.checkNotNull(zkurl, "zkurl can not be null");
zkClient = RegisterHolder.getClient(zkurl);
pathChildrenCache = new PathChildrenCache(zkClient, "/" + nameSpace, true);
pathChildrenCache.getListenable().addListener(this);
try {
pathChildrenCache.start();
initDataFromZk();
} catch (Exception e) {
// zookeeper cluster 不可用时,load the conf from localfile
if (e instanceof ConnectionLossException) {
logger.error(" ConnectionLossException has happen ,start to laod the local confFile to mem");
}
}
}
示例10: 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);
}
}
示例11: doStart
import org.apache.curator.framework.recipes.cache.PathChildrenCache; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
CuratorFramework client = zkClient.get();
serversCache = new PathChildrenCache(client, MetaZkConfig.getMetaServerRegisterPath(), true,
XpipeThreadFactory.create(String.format("PathChildrenCache(%d)", currentServer.getServerId())));
serversCache.getListenable().addListener(new ChildrenChanged());
serversCache.start();
future = scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {
@Override
public void doRun() {
try {
childrenChanged();
} catch (Throwable th) {
logger.error("[doStart]", th);
}
}
}, 1000, metaServerConfig.getClusterServersRefreshMilli(), TimeUnit.MILLISECONDS);
}
示例12: setupCacheSync
import org.apache.curator.framework.recipes.cache.PathChildrenCache; //导入方法依赖的package包/类
private static PathChildrenCache setupCacheSync(final CuratorFramework zkClient) throws Exception {
try {
zkClient.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.PERSISTENT)
.forPath(ZKNODE_PATH);
} catch (final KeeperException.NodeExistsException expected) {
// silently do nothing since it means that the node is already there
}
final PathChildrenCache cacheSync = new PathChildrenCache(zkClient, ZKNODE_PATH, false);
// It is important to preload all data before specifying callback for updates, because otherwise preload won't
// give any effect - all changes will be removed.
cacheSync.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
return cacheSync;
}
示例13: setUpBeforeClass
import org.apache.curator.framework.recipes.cache.PathChildrenCache; //导入方法依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
org.apache.log4j.BasicConfigurator.configure();
MiniClusterController.Start(0);
controller_ = MiniClusterController.instance();
rand_ = new Random();
cf_ = CuratorFrameworkFactory.builder()
.connectString(testConnectionStr)
.connectionTimeoutMs(30 * 1000)
.aclProvider(new TestACLProvider())
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build();
cf_.start();
cache_ = new PathChildrenCache(cf_,
RecordServiceConfig.ZOOKEEPER_ZNODE_DEFAULT + "/planners", true);
cache_.start();
}
示例14: createPathChildrenCacheMock
import org.apache.curator.framework.recipes.cache.PathChildrenCache; //导入方法依赖的package包/类
/**
* Create mock {@link PathChildrenCache} using given controller ID and DPIDs.
*
* @param controllerId Controller ID to represent current data.
* @param paths List of HexString indicating switch's DPID.
* @param listener Callback object to be set as Listenable.
* @return Mock PathChildrenCache object
* @throws Exception
*/
private PathChildrenCache createPathChildrenCacheMock(
final String controllerId,
final String[] paths,
ListenerContainer<PathChildrenCacheListener> listener)
throws Exception {
PathChildrenCache pathChildrenCache = createMock(PathChildrenCache.class);
expect(pathChildrenCache.getListenable()).andReturn(listener).anyTimes();
pathChildrenCache.start(anyObject(StartMode.class));
expectLastCall().anyTimes();
List<ChildData> childs = new ArrayList<ChildData>();
for (String path : paths) {
childs.add(createChildDataMockForCurrentData(controllerId, path));
}
expect(pathChildrenCache.getCurrentData()).andReturn(childs).anyTimes();
pathChildrenCache.rebuild();
expectLastCall().anyTimes();
replay(pathChildrenCache);
return pathChildrenCache;
}
示例15: TransactorCache
import org.apache.curator.framework.recipes.cache.PathChildrenCache; //导入方法依赖的package包/类
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);
}
}