当前位置: 首页>>代码示例>>Java>>正文


Java IZkDataListener类代码示例

本文整理汇总了Java中org.I0Itec.zkclient.IZkDataListener的典型用法代码示例。如果您正苦于以下问题:Java IZkDataListener类的具体用法?Java IZkDataListener怎么用?Java IZkDataListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IZkDataListener类属于org.I0Itec.zkclient包,在下文中一共展示了IZkDataListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processDataOrChildChange

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的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

示例2: fireDataChangedEvents

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
    for (final IZkDataListener listener : listeners) {
        _eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {

            @Override
            public void run() throws Exception {
                // reinstall watch
                exists(path, true);
                try {
                    Object data = readData(path, null, true);
                    listener.handleDataChange(path, data);
                } catch (ZkNoNodeException e) {
                    listener.handleDataDeleted(path);
                }
            }
        });
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:19,代码来源:ZkClientx.java

示例3: doAddDataListener

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public void doAddDataListener(String path, DataListener listener) {
	try {
		// 第一步:获取-校验-创建监听器
		IZkDataListener iZkDataListener = dataListenerMap.get(listener);
		if(iZkDataListener != 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, iZkDataListener = new IZkDataListenerImpl(path));
		}
		
		// 第二步:启动监听
		client.subscribeDataChanges(path, iZkDataListener);
	} catch (Exception e) {
		throw new IllegalStateException(e.getMessage(), e);
	}
}
 
开发者ID:yu120,项目名称:coon,代码行数:23,代码来源:ZkclientZkTransporter.java

示例4: processDataOrChildChange

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的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

示例5: fireDataChangedEvents

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
  for (final IZkDataListener listener : listeners) {
    _eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {

      @Override public void run() throws Exception {
        // reinstall watch
        exists(path, true);
        try {
          Object data = readData(path, null, true);
          listener.handleDataChange(path, data);
        } catch (ZkNoNodeException e) {
          listener.handleDataDeleted(path);
        }
      }
    });
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:18,代码来源:ZkClient.java

示例6: subscribeDataChanges

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public void subscribeDataChanges(String path, IZkDataListener listener) {
    Set<IZkDataListener> listeners;
    synchronized (_dataListener) {
        listeners = _dataListener.get(path);
        if (listeners == null) {
            listeners = new CopyOnWriteArraySet<IZkDataListener>();
            _dataListener.put(path, listeners);
        }
        listeners.add(listener);
    }
    watchForData(path);
    LOG.debug("Subscribed data changes for " + path);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:14,代码来源:ZkClientx.java

示例7: unsubscribeDataChanges

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public void unsubscribeDataChanges(String path, IZkDataListener dataListener) {
    synchronized (_dataListener) {
        final Set<IZkDataListener> listeners = _dataListener.get(path);
        if (listeners != null) {
            listeners.remove(dataListener);
        }
        if (listeners == null || listeners.isEmpty()) {
            _dataListener.remove(path);
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:12,代码来源:ZkClientx.java

示例8: hasListeners

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
private boolean hasListeners(String path) {
    Set<IZkDataListener> dataListeners = _dataListener.get(path);
    if (dataListeners != null && dataListeners.size() > 0) {
        return true;
    }
    Set<IZkChildListener> childListeners = _childListener.get(path);
    if (childListeners != null && childListeners.size() > 0) {
        return true;
    }
    return false;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:12,代码来源:ZkClientx.java

示例9: numberOfListeners

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public int numberOfListeners() {
    int listeners = 0;
    for (Set<IZkChildListener> childListeners : _childListener.values()) {
        listeners += childListeners.size();
    }
    for (Set<IZkDataListener> dataListeners : _dataListener.values()) {
        listeners += dataListeners.size();
    }
    listeners += _stateListener.size();

    return listeners;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:13,代码来源:ZkClientx.java

示例10: doRemoveDataListener

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public void doRemoveDataListener(String path, DataListener listener) {
	try {
		// 第一步:移除dataListenerMap中的数据
		IZkDataListener iZkDataListener = dataListenerMap.get(listener);
		if(iZkDataListener == 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);
			}
		}
		
		// 第四步:取消监听
		client.unsubscribeDataChanges(path, iZkDataListener);
	} catch (Exception e) {
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
开发者ID:yu120,项目名称:coon,代码行数:29,代码来源:ZkclientZkTransporter.java

示例11: readAndListen

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public static NamePairs readAndListen(String zkUrl, String path, IZkDataListener listener) {
	ZkClient client = ZkClientHolder.getZkClient(zkUrl);
	if (!client.exists(path)) {
		return null;
	}
	String data = ZkClientHolder.data2String(client.readData(path));
	if (listener != null) {
		client.subscribeDataChanges(path, listener);
	}
	return new NamePairs(data);
}
 
开发者ID:youtongluan,项目名称:sumk,代码行数:12,代码来源:ZKConfigHandler.java

示例12: ZkLeaderElector

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
@VisibleForTesting
public ZkLeaderElector(String processorIdStr,
                       ZkUtils zkUtils,
                       IZkDataListener previousProcessorChangeListener) {
  this.processorIdStr = processorIdStr;
  this.zkUtils = zkUtils;
  this.keyBuilder = zkUtils.getKeyBuilder();
  this.hostName = getHostName();
  this.previousProcessorChangeListener = previousProcessorChangeListener;
}
 
开发者ID:apache,项目名称:samza,代码行数:11,代码来源:ZkLeaderElector.java

示例13: subscribeDataChanges

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public void subscribeDataChanges(String path, IZkDataListener listener) {
  Set<IZkDataListener> listeners;
  synchronized (_dataListener) {
    listeners = _dataListener.get(path);
    if (listeners == null) {
      listeners = new CopyOnWriteArraySet<>();
      _dataListener.put(path, listeners);
    }
    listeners.add(listener);
  }
  watchForData(path);
  LOG.debug("Subscribed data changes for " + path);
}
 
开发者ID:apache,项目名称:helix,代码行数:14,代码来源:ZkClient.java

示例14: unsubscribeDataChanges

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
public void unsubscribeDataChanges(String path, IZkDataListener dataListener) {
  synchronized (_dataListener) {
    final Set<IZkDataListener> listeners = _dataListener.get(path);
    if (listeners != null) {
      listeners.remove(dataListener);
    }
    if (listeners == null || listeners.isEmpty()) {
      _dataListener.remove(path);
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:12,代码来源:ZkClient.java

示例15: hasListeners

import org.I0Itec.zkclient.IZkDataListener; //导入依赖的package包/类
private boolean hasListeners(String path) {
  Set<IZkDataListener> dataListeners = _dataListener.get(path);
  if (dataListeners != null && dataListeners.size() > 0) {
    return true;
  }
  Set<IZkChildListener> childListeners = _childListener.get(path);
  if (childListeners != null && childListeners.size() > 0) {
    return true;
  }
  return false;
}
 
开发者ID:apache,项目名称:helix,代码行数:12,代码来源:ZkClient.java


注:本文中的org.I0Itec.zkclient.IZkDataListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。