当前位置: 首页>>代码示例>>Java>>正文


Java PathChildrenCacheListener类代码示例

本文整理汇总了Java中org.apache.curator.framework.recipes.cache.PathChildrenCacheListener的典型用法代码示例。如果您正苦于以下问题:Java PathChildrenCacheListener类的具体用法?Java PathChildrenCacheListener怎么用?Java PathChildrenCacheListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PathChildrenCacheListener类属于org.apache.curator.framework.recipes.cache包,在下文中一共展示了PathChildrenCacheListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listen

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的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

示例2: addChildPathCache

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的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

示例3: createPathCache

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的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

示例4: listen

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的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

示例5: pathChildrenCacheListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
private PathChildrenCacheListener pathChildrenCacheListener(final ClusterListener listener) {
    return (client, event) -> {
        log.debug("Event {} generated on cluster", event);
        switch (event.getType()) {
            case CHILD_ADDED:
                log.info("Node {} added to cluster", getServerName(event));
                listener.onEvent(HOST_ADDED, (Host) SerializationUtils.deserialize(event.getData().getData()));
                break;
            case CHILD_REMOVED:
                log.info("Node {} removed from cluster", getServerName(event));
                listener.onEvent(HOST_REMOVED, (Host) SerializationUtils.deserialize(event.getData().getData()));
                break;
            case CHILD_UPDATED:
                log.warn("Invalid usage: Node {} updated externally for cluster", getServerName(event));
                break;
            case CONNECTION_LOST:
                log.error("Connection lost with Zookeeper");
                listener.onEvent(ERROR, null);
                break;
            //$CASES-OMITTED$
            default:
                log.warn("Received unknown event {}", event.getType());
        }
    };
}
 
开发者ID:pravega,项目名称:pravega,代码行数:26,代码来源:ClusterZKImpl.java

示例6: getDefaultListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
private static PathChildrenCacheListener getDefaultListener() {
    return
        (client, event) -> {
        switch (event.getType()) {

            case CHILD_ADDED : {
                LOGGER.info("Node added: [{}]", ZKPaths.getNodeFromPath(event.getData().getPath()));
                break;
            }

            case CHILD_REMOVED : {
                LOGGER.info("Node removed: [{}]", ZKPaths.getNodeFromPath(event.getData().getPath()));
                break;
            }

            default :
                break;
        }
    };
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:21,代码来源:ZKGroupMember.java

示例7: newListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
private PathChildrenCacheListener newListener(final EventType eventType, final GroupChangedListener delegate) {
    return
        (client, event) -> {
        switch (event.getType()) {

            case CHILD_ADDED : {
                String addedMemberId = ZKPaths.getNodeFromPath(event.getData().getPath());
                delegate.memberAdded(eventType, addedMemberId);
                break;
            }

            case CHILD_REMOVED : {
                final String removedMemberId = ZKPaths.getNodeFromPath(event.getData().getPath());
                delegate.memberRemoved(eventType, removedMemberId);
                break;
            }

            default :
                break;
        }
    };
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:23,代码来源:ZKConsumerGroupMember.java

示例8: testStoreRegistersDispatcherAndStartsItsClient

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
/**
 * This test ensures store subscribes to receive events from underlying client. Dispatcher tests ensures listeners
 * are fired on incoming events. These two sets of tests ensure observer pattern in {@code TransientStore} works fine.
 */
@Test
public void testStoreRegistersDispatcherAndStartsItsClient() throws Exception {
  final StoreWithMockClient<String> store = new StoreWithMockClient<>(config, curator);

  final PathChildrenCache cache = Mockito.mock(PathChildrenCache.class);
  final ZookeeperClient client = store.getClient();
  Mockito
      .when(client.getCache())
      .thenReturn(cache);

  final ListenerContainer<PathChildrenCacheListener> container = Mockito.mock(ListenerContainer.class);
  Mockito
      .when(cache.getListenable())
      .thenReturn(container);

  store.start();

  Mockito
      .verify(container)
      .addListener(store.dispatcher);

  Mockito
      .verify(client)
      .start();
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:30,代码来源:TestEphemeralStore.java

示例9: createPathChildrenCacheMock

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的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;
}
 
开发者ID:opennetworkinglab,项目名称:spring-open,代码行数:35,代码来源:ZookeeperRegistryTest.java

示例10: addDataListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
@Override
public void addDataListener(String path, DataListener listener) {
	try {
		// 第一步:获取-校验-创建监听器
		PathChildrenCacheListener pathChildrenCacheListener = dataListenerMap.get(listener);
		if(pathChildrenCacheListener != null){//已监听
			return;
		} else {
			// 添加外部监听器
			Set<DataListener> dataListenerSet = dataListenersMap.get(path);
			if(dataListenerSet == null){
				dataListenersMap.put(path, dataListenerSet = new ConcurrentHashSet<DataListener>());
			}
			dataListenerSet.add(listener);
			dataListenerMap.put(listener, pathChildrenCacheListener = new PathChildrenCacheListenerImpl(path));
		}
		
		// 第二步:获取-校验-创建子节点缓存连接
		PathChildrenCache pathChildrenCache = pathChildrenCacheMap.get(path);
		if(pathChildrenCache == null){
			pathChildrenCacheMap.put(path, pathChildrenCache = new PathChildrenCache(client, path, true));
			// 第三步:启动监听
			pathChildrenCache.start(StartMode.POST_INITIALIZED_EVENT);
		}
		
		// 第四步:添加监听器
        pathChildrenCache.getListenable().addListener(pathChildrenCacheListener);
	} catch (Exception e) {
		throw new IllegalStateException(e.getMessage(), e);
	}
}
 
开发者ID:yu120,项目名称:coon,代码行数:32,代码来源:CuratorZkTransporter.java

示例11: removeDataListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
@Override
public void removeDataListener(String path, DataListener listener) {
	try {
		// 第一步:移除dataListenerMap中的数据
		PathChildrenCacheListener pathChildrenCacheListener = dataListenerMap.get(listener);
		if(pathChildrenCacheListener == null){
			return;
		} else {
			dataListenerMap.remove(listener);
			
			// 第二步:移除Set<DataListener>中的数据
			Set<DataListener> dataListenerSet = dataListenersMap.get(path);
			if(dataListenerSet != null && dataListenerSet.contains(listener)){
				dataListenerSet.remove(listener);
			}

			// 第三步:移除dataListenersMap和childDataMap中的数据
			if(dataListenerSet == null || dataListenerSet.isEmpty()){
				dataListenersMap.remove(path);
				childDataMap.remove(path);
			}
		}
		
		// 第四步:取消监听,并移除pathChildrenCacheMap中的数据
		PathChildrenCache pathChildrenCache = pathChildrenCacheMap.get(path);
		if(pathChildrenCache != null){
			pathChildrenCache.getListenable().removeListener(pathChildrenCacheListener);
			((PathChildrenCacheListenerImpl)listener).unwatch();
			if(pathChildrenCache.getListenable().size() == 0){
				pathChildrenCacheMap.remove(path);
				pathChildrenCache.close();
			}
		}
	} catch (Exception e) {
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
开发者ID:yu120,项目名称:coon,代码行数:38,代码来源:CuratorZkTransporter.java

示例12: addChildPathCache

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
public static void addChildPathCache(String path, PathChildrenCacheListener listener) {
    try {
        //watch the child status
        final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
        childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
        childrenCache.getListenable().addListener(listener);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:11,代码来源:ZKUtils.java

示例13: addViewPathCache

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
public static void addViewPathCache(String path, PathChildrenCacheListener listener) {
    try {
        //watch the child status
        final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
        childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
        childrenCache.getListenable().addListener(listener);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:11,代码来源:ZKUtils.java

示例14: addListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
private static void addListener(PathChildrenCache cache)
{
    // a PathChildrenCacheListener is optional. Here, it's used just to log changes
    PathChildrenCacheListener listener = new PathChildrenCacheListener()
    {
        @Override
        public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception
        {
            switch ( event.getType() )
            {
                case CHILD_ADDED:
                {
                    System.out.println("Node added: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
                    break;
                }

                case CHILD_UPDATED:
                {
                    System.out.println("Node changed: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
                    break;
                }

                case CHILD_REMOVED:
                {
                    System.out.println("Node removed: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
                    break;
                }
            }
        }
    };
    cache.getListenable().addListener(listener);
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:33,代码来源:PathCacheExample.java

示例15: registerBucketOwnershipListener

import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; //导入依赖的package包/类
@Override
@SneakyThrows
public void registerBucketOwnershipListener(BucketOwnershipListener listener) {
    Preconditions.checkNotNull(listener);

    PathChildrenCacheListener bucketListener = (client, event) -> {
        switch (event.getType()) {
            case CHILD_ADDED:
                // no action required
                break;
            case CHILD_REMOVED:
                int bucketId = Integer.parseInt(ZKPaths.getNodeFromPath(event.getData().getPath()));
                listener.notify(new BucketNotification(bucketId, BucketNotification.NotificationType.BucketAvailable));
                break;
            case CONNECTION_LOST:
                listener.notify(new BucketNotification(Integer.MIN_VALUE, BucketNotification.NotificationType.ConnectivityError));
                break;
            default:
                log.warn("Received unknown event {}", event.getType());
        }
    };

    bucketOwnershipCacheRef.compareAndSet(null, new PathChildrenCache(storeHelper.getClient(), ZKStoreHelper.BUCKET_OWNERSHIP_PATH, true));

    bucketOwnershipCacheRef.get().getListenable().addListener(bucketListener);
    bucketOwnershipCacheRef.get().start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
    log.info("bucket ownership listener registered");
}
 
开发者ID:pravega,项目名称:pravega,代码行数:29,代码来源:ZKStreamMetadataStore.java


注:本文中的org.apache.curator.framework.recipes.cache.PathChildrenCacheListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。