本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
}
示例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 {
}
});
}
});
}
示例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();
}
}
示例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 + "]");
});
}
});
}
示例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);
}
}
}
示例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);
}
示例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);
}
};
}
示例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);
}
示例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);
}
}
}