org.apache.curator.framework.listen.ListenerContainer Java Examples

The following examples show how to use org.apache.curator.framework.listen.ListenerContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZookeeperSyncToNacosServiceImplTest.java    From nacos-sync with Apache License 2.0 6 votes vote down vote up
public boolean mockSync(TaskDO taskDO) throws Exception {
    List<ChildData> childDataList = spy(ArrayList.class);
    ListenerContainer<PathChildrenCacheListener> listeners = mock(ListenerContainer.class);
    childDataList.add(new ChildData(TEST_PATH, null, null));
    when(taskDO.getTaskId()).thenReturn(TEST_TASK_ID);
    when(taskDO.getSourceClusterId()).thenReturn(TEST_SOURCE_CLUSTER_ID);
    when(taskDO.getDestClusterId()).thenReturn(TEST_DEST_CLUSTER_ID);
    CuratorFramework curatorFramework = mock(CuratorFramework.class);
    doReturn(curatorFramework).when(zookeeperServerHolder).get(any(), any());
    doReturn(destNamingService).when(nacosServerHolder).get(any(), any());
    doReturn(pathChildrenCache).when(zookeeperSyncToNacosService).getPathCache(any());
    when(pathChildrenCache.getCurrentData()).thenReturn(childDataList);
    doReturn(ClusterTypeEnum.ZK).when(skyWalkerCacheServices).getClusterType(any());
    when(pathChildrenCache.getListenable()).thenReturn(listeners);
    return zookeeperSyncToNacosService.sync(taskDO);
}
 
Example #2
Source File: BaragonStateWatcher.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@Inject
public BaragonStateWatcher(final BaragonStateFetcher stateFetcher,
                           Set<BaragonStateListener> listeners,
                           @Baragon PersistentWatcher watcher) {
  this.stateFetcher = stateFetcher;
  this.listenerContainer = new ListenerContainer<>();
  this.executor = newExecutor();
  this.versionQueue = new LinkedTransferQueue<>();
  for (BaragonStateListener listener : listeners) {
    listenerContainer.addListener(listener);
  }

  watcher.getEventListenable().addListener(new EventListener() {

    @Override
    public void newEvent(Event event) {
      switch (event.getType()) {
        case NODE_UPDATED:
          int version = event.getStat().getVersion();
          versionQueue.add(version);
          executor.submit(new Runnable() {

            @Override
            public void run() {
              updateToLatestVersion();
            }
          });
          break;
        case NODE_DELETED:
          LOG.warn("Baragon state node was deleted");
          break;
        default:
          LOG.warn("Unrecognized event type {}", event.getType());
          break;
      }
    }
  }, executor);

  watcher.start();
}
 
Example #3
Source File: NodeCache.java    From xian with Apache License 2.0 5 votes vote down vote up
/**
 * Return the cache listenable
 *
 * @return listenable
 */
public ListenerContainer<NodeCacheListener> getListenable()
{
    Preconditions.checkState(state.get() != State.CLOSED, "Closed");

    return listeners;
}
 
Example #4
Source File: CuratorFrameworkImpl.java    From xian with Apache License 2.0 5 votes vote down vote up
public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder)
{
    ZookeeperFactory localZookeeperFactory = makeZookeeperFactory(builder.getZookeeperFactory());
    this.client = new CuratorZookeeperClient(localZookeeperFactory, builder.getEnsembleProvider(), builder.getSessionTimeoutMs(), builder.getConnectionTimeoutMs(), new Watcher()
    {
        @Override
        public void process(WatchedEvent watchedEvent)
        {
            CuratorEvent event = new CuratorEventImpl(CuratorFrameworkImpl.this, CuratorEventType.WATCHED, watchedEvent.getState().getIntValue(), unfixForNamespace(watchedEvent.getPath()), null, null, null, null, null, watchedEvent, null);
            processEvent(event);
        }
    }, builder.getRetryPolicy(), builder.canBeReadOnly());

    listeners = new ListenerContainer<CuratorListener>();
    unhandledErrorListeners = new ListenerContainer<UnhandledErrorListener>();
    backgroundOperations = new DelayQueue<OperationAndData<?>>();
    namespace = new NamespaceImpl(this, builder.getNamespace());
    threadFactory = getThreadFactory(builder);
    maxCloseWaitMs = builder.getMaxCloseWaitMs();
    connectionStateManager = new ConnectionStateManager(this, builder.getThreadFactory());
    compressionProvider = builder.getCompressionProvider();
    aclProvider = builder.getAclProvider();
    state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);
    useContainerParentsIfAvailable = builder.useContainerParentsIfAvailable();

    byte[] builderDefaultData = builder.getDefaultData();
    defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0];
    authInfos = buildAuths(builder);

    failedDeleteManager = new FailedDeleteManager(this);
    namespaceFacadeCache = new NamespaceFacadeCache(this);
}
 
Example #5
Source File: BasePathChildrenCacheListener.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected BasePathChildrenCacheListener(long version, ListenerContainer<PathChildrenCacheListener> listenerContainer) {
	m_version = version;
	m_eventBus = PlexusComponentLocator.lookup(EventBus.class);
	m_clusterStateHolder = PlexusComponentLocator.lookup(ClusterStateHolder.class);
	m_listenerContainer = listenerContainer;
}
 
Example #6
Source File: DubboServiceDiscoveryAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
/**
 * Re-attach the {@link TreeCacheListener TreeCacheListeners}.
 */
private void reattachTreeCacheListeners() {

	TreeCache treeCache = zookeeperServiceWatch.getCache();

	Listenable<TreeCacheListener> listenable = treeCache.getListenable();

	/**
	 * All registered TreeCacheListeners except {@link ZookeeperServiceWatch}.
	 * Usually, "otherListeners" will be empty because Spring Cloud Zookeeper only
	 * adds "zookeeperServiceWatch" bean as {@link TreeCacheListener}.
	 */
	List<TreeCacheListener> otherListeners = new LinkedList<>();

	if (listenable instanceof ListenerContainer) {
		ListenerContainer<TreeCacheListener> listenerContainer = (ListenerContainer) listenable;
		listenerContainer.forEach(listener -> {
			/**
			 * Even though "listener" is an instance of
			 * {@link ZookeeperServiceWatch}, "zookeeperServiceWatch" bean that
			 * was enhanced by AOP is different from the former, thus it's
			 * required to exclude "listener".
			 */
			if (!(listener instanceof ZookeeperServiceWatch)) {
				otherListeners.add(listener);
			}
			return null;
		});

		// remove all TreeCacheListeners temporarily
		listenerContainer.clear();
		// re-store zookeeperServiceWatch, and make sure it's first one
		// now "beforeChildEvent" is available for Spring AOP
		listenerContainer.addListener(zookeeperServiceWatch);
		// re-store others
		otherListeners.forEach(listenerContainer::addListener);
	}
	else {
		if (logger.isWarnEnabled()) {
			logger.warn(
					"Tell me which version Curator framework current application used? I will do better :D");
		}
	}
}
 
Example #7
Source File: FollowerInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected LeaderMetaVersionListener(long version, ListenerContainer<NodeCacheListener> listenerContainer) {
	super(version, listenerContainer);
}
 
Example #8
Source File: FollowerInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected BaseMetaVersionListener(long version, ListenerContainer<NodeCacheListener> listenerContainer) {
	super(version, listenerContainer);
}
 
Example #9
Source File: FollowerInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected void loadAndAddLeaderMetaVersionListener(long version) {
	ListenerContainer<NodeCacheListener> listenerContainer = m_leaderMetaVersionCache.getListenable();
	listenerContainer
	      .addListener(new LeaderMetaVersionListener(version, listenerContainer), m_eventBus.getExecutor());
	loadLeaderMeta(version);
}
 
Example #10
Source File: FollowerInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected void addBaseMetaVersionListener(long version) throws DalException {
	ListenerContainer<NodeCacheListener> listenerContainer = m_baseMetaVersionCache.getListenable();
	listenerContainer.addListener(new BaseMetaVersionListener(version, listenerContainer), m_eventBus.getExecutor());
}
 
Example #11
Source File: LeaderInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected MetaServerListListener(long version, ListenerContainer<PathChildrenCacheListener> listenerContainer) {
	super(version, listenerContainer);
}
 
Example #12
Source File: LeaderInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected BaseMetaVersionListener(long version, ListenerContainer<NodeCacheListener> listenerContainer) {
	super(version, listenerContainer);
}
 
Example #13
Source File: LeaderInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected void addMetaServerListListener(long version) throws Exception {
	ListenerContainer<PathChildrenCacheListener> listenerContainer = m_metaServerListCache.getListenable();
	listenerContainer.addListener(new MetaServerListListener(version, listenerContainer), m_eventBus.getExecutor());
}
 
Example #14
Source File: LeaderInitEventHandler.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected void addBaseMetaVersionListener(long version) throws DalException {
	ListenerContainer<NodeCacheListener> listenerContainer = m_baseMetaVersionCache.getListenable();
	listenerContainer.addListener(new BaseMetaVersionListener(version, listenerContainer), m_eventBus.getExecutor());
}
 
Example #15
Source File: BaseNodeCacheListener.java    From hermes with Apache License 2.0 4 votes vote down vote up
protected BaseNodeCacheListener(long version, ListenerContainer<NodeCacheListener> listenerContainer) {
	m_version = version;
	m_eventBus = PlexusComponentLocator.lookup(EventBus.class);
	m_clusterStateHolder = PlexusComponentLocator.lookup(ClusterStateHolder.class);
	m_listenerContainer = listenerContainer;
}
 
Example #16
Source File: DistributedPriorityQueue.java    From xian with Apache License 2.0 4 votes vote down vote up
/**
 * Return the manager for put listeners
 *
 * @return put listener container
 */
@Override
public ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
{
    return queue.getPutListenerContainer();
}
 
Example #17
Source File: DistributedQueue.java    From xian with Apache License 2.0 4 votes vote down vote up
/**
 * Return the manager for put listeners
 *
 * @return put listener container
 */
@Override
public ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
{
    return putListenerContainer;
}
 
Example #18
Source File: DistributedDelayQueue.java    From xian with Apache License 2.0 4 votes vote down vote up
/**
 * Return the manager for put listeners
 *
 * @return put listener container
 */
@Override
public ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
{
    return queue.getPutListenerContainer();
}
 
Example #19
Source File: DistributedIdQueue.java    From xian with Apache License 2.0 4 votes vote down vote up
@Override
public ListenerContainer<QueuePutListener<T>> getPutListenerContainer()
{
    return queue.getPutListenerContainer();
}
 
Example #20
Source File: ConnectionStateManager.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * Return the listenable
 *
 * @return listenable
 */
public ListenerContainer<ConnectionStateListener> getListenable()
{
    return listeners;
}
 
Example #21
Source File: QueueBase.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * Return the manager for put listeners
 *
 * @return put listener container
 */
ListenerContainer<QueuePutListener<T>> getPutListenerContainer();
 
Example #22
Source File: PathChildrenCache.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * Return the cache listenable
 *
 * @return listenable
 */
public ListenerContainer<PathChildrenCacheListener> getListenable()
{
    return listeners;
}
 
Example #23
Source File: SharedValueReader.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the listenable
 *
 * @return listenable
 */
public ListenerContainer<SharedValueListener> getListenable();
 
Example #24
Source File: SharedValue.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the listenable
 *
 * @return listenable
 */
public ListenerContainer<SharedValueListener> getListenable()
{
    return listeners;
}