本文整理汇总了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);
}
}
}