當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。