當前位置: 首頁>>代碼示例>>Java>>正文


Java IZkChildListener類代碼示例

本文整理匯總了Java中org.I0Itec.zkclient.IZkChildListener的典型用法代碼示例。如果您正苦於以下問題:Java IZkChildListener類的具體用法?Java IZkChildListener怎麽用?Java IZkChildListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IZkChildListener類屬於org.I0Itec.zkclient包,在下文中一共展示了IZkChildListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ProcessMonitor

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public ProcessMonitor(Long pipelineId){
    super(pipelineId);
    processListener = new IZkChildListener() {

        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
            if (currentChilds != null) {
                initProcess(currentChilds);
            }
        }
    };

    String path = StagePathUtils.getProcessRoot(getPipelineId());
    List<String> childs = zookeeper.subscribeChildChanges(path, processListener);
    initProcess(childs);
    // syncStage();
    MonitorScheduler.register(this);
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:18,代碼來源:ProcessMonitor.java

示例2: StageMonitor

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public StageMonitor(Long pipelineId){
    super(pipelineId);

    processListener = new IZkChildListener() {

        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
            if (currentChilds != null) {
                initStage(currentChilds);
            }
        }
    };

    String path = StagePathUtils.getProcessRoot(getPipelineId());
    List<String> childs = zookeeper.subscribeChildChanges(path, processListener);
    initStage(childs);
    // syncStage();
    MonitorScheduler.register(this);
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:19,代碼來源:StageMonitor.java

示例3: TerminMonitor

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public TerminMonitor(Long pipelineId){
    super(pipelineId);
    childListener = new IZkChildListener() {

        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
            if (currentChilds != null) {
                initTermin(currentChilds);
            }
        }
    };

    String path = StagePathUtils.getTerminRoot(getPipelineId());
    List<String> childs = zookeeper.subscribeChildChanges(path, childListener);
    initTermin(childs);
    MonitorScheduler.register(this);
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:17,代碼來源:TerminMonitor.java

示例4: NodeMonitor

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public NodeMonitor(){
    childListener = new IZkChildListener() {

        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
            if (currentChilds != null) {
                initNodes(currentChilds);
            }
        }
    };
    List<String> childs = zookeeper.subscribeChildChanges(ArbitrateConstants.NODE_NID_ROOT, childListener);
    if (childs == null) {//如果為null,代表係統節點為初始化
        try {
            zookeeper.createPersistent(ArbitrateConstants.NODE_NID_ROOT, true);
        } catch (ZkNodeExistsException e) {
            //ignore 
        }

        childs = zookeeper.getChildren(ArbitrateConstants.NODE_NID_ROOT);
    }

    initNodes(childs);
    // syncNodes();// 開始監視node節點的變化
    MonitorScheduler.register(this);
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:25,代碼來源:NodeMonitor.java

示例5: processDataOrChildChange

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
    final String path = event.getPath();

    if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated
        || event.getType() == EventType.NodeDeleted) {
        Set<IZkChildListener> childListeners = _childListener.get(path);
        if (childListeners != null && !childListeners.isEmpty()) {
            fireChildChangedEvents(path, childListeners);
        }
    }

    if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
        || event.getType() == EventType.NodeCreated) {
        Set<IZkDataListener> listeners = _dataListener.get(path);
        if (listeners != null && !listeners.isEmpty()) {
            fireDataChangedEvents(event.getPath(), listeners);
        }
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:20,代碼來源:ZkClientx.java

示例6: doSubscribe

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
@Override
protected void doSubscribe(final URL url, final NotifyListener listener) {
    try {
        clientLock.lock();

        ConcurrentHashMap<NotifyListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
        if (childChangeListeners == null) {
            serviceListeners.putIfAbsent(url, new ConcurrentHashMap<NotifyListener, IZkChildListener>());
            childChangeListeners = serviceListeners.get(url);
        }
        IZkChildListener zkChildListener = childChangeListeners.get(listener);
        if (zkChildListener == null) {
            childChangeListeners.putIfAbsent(listener, new IZkChildListener() {
                @Override
                public void handleChildChange(String parentPath, List<String> currentChilds) {

                    listener.notify(getUrl(), childrenNodeToUrls(parentPath, currentChilds));
                    logger.info(String.format("[ZookeeperRegistry] service list change: path=%s, currentChilds=%s", parentPath, currentChilds.toString()));
                }
            });
            zkChildListener = childChangeListeners.get(listener);
        }

        // 防止舊節點未正常注銷
        removeNode(url, ZkNodeType.CLIENT);
        createNode(url, ZkNodeType.CLIENT);

        String serverTypePath = ZkUtils.toNodeTypePath(url, ZkNodeType.SERVER);
        zkClient.subscribeChildChanges(serverTypePath, zkChildListener);
        logger.info(String.format("[ZookeeperRegistry] subscribe service: path=%s, info=%s", ZkUtils.toNodePath(url, ZkNodeType.SERVER), url.toFullUri()));
    } catch (Throwable e) {
        throw new RpcFrameworkException(String.format("Failed to subscribe %s to zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e);
    } finally {
        clientLock.unlock();
    }
}
 
開發者ID:TFdream,項目名稱:mango,代碼行數:37,代碼來源:ZookeeperRegistry.java

示例7: doUnsubscribe

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
@Override
protected void doUnsubscribe(URL url, NotifyListener listener) {
    try {
        clientLock.lock();
        Map<NotifyListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
        if (childChangeListeners != null) {
            IZkChildListener zkChildListener = childChangeListeners.get(listener);
            if (zkChildListener != null) {
                zkClient.unsubscribeChildChanges(ZkUtils.toNodeTypePath(url, ZkNodeType.CLIENT), zkChildListener);
                childChangeListeners.remove(listener);
            }
        }
    } catch (Throwable e) {
        throw new RpcFrameworkException(String.format("Failed to unsubscribe service %s to zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e);
    } finally {
        clientLock.unlock();
    }
}
 
開發者ID:TFdream,項目名稱:mango,代碼行數:19,代碼來源:ZookeeperRegistry.java

示例8: startListener

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public void startListener() {
	LOG.info("Starting Kafka ZK node listener...");
	exec.execute(new Runnable() {

		@Override
		public void run() {
			ZKUtils.getZKClient().subscribeChildChanges(ZkUtils.BrokerIdsPath(), new IZkChildListener() {

				@Override
				public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
					
				}
				
			});
		}

	});
}
 
開發者ID:chickling,項目名稱:kmanager,代碼行數:19,代碼來源:KafkaNodeListener.java

示例9: unsubscribeService

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
@Override
protected void unsubscribeService(URL url, ServiceListener serviceListener) {
    try {
        clientLock.lock();
        Map<ServiceListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
        if (childChangeListeners != null) {
            IZkChildListener zkChildListener = childChangeListeners.get(serviceListener);
            if (zkChildListener != null) {
                client.unsubscribeChildChanges(ZkUtils.toNodeTypePath(url, ZkNodeType.CLIENT), zkChildListener);
                childChangeListeners.remove(serviceListener);
            }
        }
    } catch (Throwable e) {
        throw new FrameworkException(new Status(UNSUBSCRIBE_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e);
    } finally {
        clientLock.unlock();
    }
}
 
開發者ID:networknt,項目名稱:light-4j,代碼行數:19,代碼來源:ZooKeeperRegistry.java

示例10: monitor

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
private static void monitor() {
    ZkClient zc=new ZkClient("localhost:2181",1000);
    //創建監控節點
    if(!zc.exists("/monitor"))
    zc.create("/monitor",null, CreateMode.PERSISTENT);

    if(!zc.exists("/monitor/client"))
    zc.create("/monitor/client",null, CreateMode.PERSISTENT);

    zc.subscribeChildChanges("/monitor/client",new IZkChildListener(){
        @Override
        public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
            System.out.println("------------客戶端發生變化---------childPath="+parentPath );
            currentChilds.forEach((String childPath)->{
                System.out.println("parentPath = [" + parentPath + "], currentChilds = [" + currentChilds + "]");
            });
        }
    });



}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:23,代碼來源:ServerManagerMonitor.java

示例11: processDataOrChildChange

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
private void processDataOrChildChange(WatchedEvent event) {
  final String path = event.getPath();

  if (event.getType() == EventType.NodeChildrenChanged || event.getType() == EventType.NodeCreated
      || event.getType() == EventType.NodeDeleted) {
    Set<IZkChildListener> childListeners = _childListener.get(path);
    if (childListeners != null && !childListeners.isEmpty()) {
      fireChildChangedEvents(path, childListeners);
    }
  }

  if (event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
      || event.getType() == EventType.NodeCreated) {
    Set<IZkDataListener> listeners = _dataListener.get(path);
    if (listeners != null && !listeners.isEmpty()) {
      fireDataChangedEvents(event.getPath(), listeners);
    }
  }
}
 
開發者ID:apache,項目名稱:helix,代碼行數:20,代碼來源:ZkClient.java

示例12: subscribe

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
@Override
public void subscribe() {
    List<String> children = zkClient.subscribeChildChanges(rootPath, new IZkChildListener() {
        @Override
        public void handleChildChange(String parentPath, List<String> currentChildren) throws Exception {
            directory.notify(currentChildren);
        }
    });
    directory.notify(children);
}
 
開發者ID:justice-code,項目名稱:star-map,代碼行數:11,代碼來源:ZookeeperRegistry.java

示例13: createTargetChildListener

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public IZkChildListener createTargetChildListener(String path, final ChildListener listener) {
	return new IZkChildListener() {
		public void handleChildChange(String parentPath, List<String> currentChilds)
				throws Exception {
			listener.childChanged(parentPath, currentChilds);
		}
	};
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:9,代碼來源:ZkclientZookeeperClient.java

示例14: subscribeChildChanges

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public List<String> subscribeChildChanges(String path, IZkChildListener listener) {
    synchronized (_childListener) {
        Set<IZkChildListener> listeners = _childListener.get(path);
        if (listeners == null) {
            listeners = new CopyOnWriteArraySet<IZkChildListener>();
            _childListener.put(path, listeners);
        }
        listeners.add(listener);
    }
    return watchForChilds(path);
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:12,代碼來源:ZkClientx.java

示例15: unsubscribeChildChanges

import org.I0Itec.zkclient.IZkChildListener; //導入依賴的package包/類
public void unsubscribeChildChanges(String path, IZkChildListener childListener) {
    synchronized (_childListener) {
        final Set<IZkChildListener> listeners = _childListener.get(path);
        if (listeners != null) {
            listeners.remove(childListener);
        }
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:9,代碼來源:ZkClientx.java


注:本文中的org.I0Itec.zkclient.IZkChildListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。