本文整理了Java中org.linkedin.zookeeper.tracker.ZooKeeperTreeTracker
类的一些代码示例,展示了ZooKeeperTreeTracker
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperTreeTracker
类的具体详情如下:
包路径:org.linkedin.zookeeper.tracker.ZooKeeperTreeTracker
类名称:ZooKeeperTreeTracker
[英]The purpose of this class is to essentially keep a replica of ZooKeeper data in memory and be able to be notified when it changes.
[中]这个类的目的是在内存中保留ZooKeeper数据的副本,并在数据发生变化时能够得到通知。
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
public void track(NodeEventsListener<T> eventsListener)
throws InterruptedException, KeeperException
{
registerListener(eventsListener);
track();
}
代码示例来源:origin: org.fusesource.fabric/fabric-configadmin
public void destroy() throws Exception {
for (ZooKeeperTreeTracker<String> tree : trees.values()) {
tree.destroy();
}
trees.clear();
}
代码示例来源:origin: org.fusesource.fabric/fabric-configadmin
protected List<String> getChildren(ZooKeeperTreeTracker<String> tree, String node) {
List<String> children = new ArrayList<String>();
if (tree != null) {
Pattern p = Pattern.compile(node + "/[^/]*");
for (String c : tree.getTree().keySet()) {
if (p.matcher(c).matches()) {
children.add(c.substring(c.lastIndexOf('/') + 1));
}
}
}
return children;
}
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
private Map<String, TrackedNode<T>> handleNodeDataChanged(String path,
Collection<NodeEvent<T>> events)
throws InterruptedException, KeeperException
{
return trackNode(path,
new LinkedHashMap<String, TrackedNode<T>>(_tree),
events,
computeDepth(path));
}
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
public void track() throws InterruptedException, KeeperException
{
Collection<NodeEvent<T>> events = new ArrayList<NodeEvent<T>>();
synchronized(_lock)
{
_tree = trackNode(_root, new LinkedHashMap<String, TrackedNode<T>>(), events, 0);
}
raiseEvents(events);
}
代码示例来源:origin: org.fusesource.fabric/fabric-configadmin
protected ZooKeeperTreeTracker<String> track(String path) throws InterruptedException, KeeperException, IOException {
ZooKeeperTreeTracker<String> tree = trees.get(path);
if (tree == null) {
if (ZooKeeperUtils.exists(zooKeeper, path) != null) {
tree = new ZooKeeperTreeTracker<String>(zooKeeper, new ZKStringDataReader(), path);
trees.put(path, tree);
tree.track(this);
String[] parents = getParents(tree.getTree().get(path));
for (String parent : parents) {
track(ZkPath.CONFIG_VERSIONS_PROFILE.getPath(version, parent));
}
} else {
// If the node does not exist yet, we track the parent to make
// sure we receive the node creation event
String p = ZkPath.CONFIG_VERSIONS_PROFILES.getPath(version);
if (!trees.containsKey(p)) {
tree = new ZooKeeperTreeTracker<String>(zooKeeper, new ZKStringDataReader(), p, 1);
trees.put(p, tree);
tree.track(this);
}
return null;
}
}
return tree;
}
代码示例来源:origin: org.fusesource.insight/insight-graph
@Override
public void start() throws LifecycleException {
super.start();
try {
tracker.track();
} catch (Exception e) {
throw new LifecycleException(e.getMessage(), e);
}
}
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
private Map<String, TrackedNode<T>> handleNodeDeleted(String path,
Collection<NodeEvent<T>> events)
throws InterruptedException, KeeperException
{
Map<String, TrackedNode<T>> tree = _tree;
if(_tree.containsKey(path))
{
tree = new LinkedHashMap<String, TrackedNode<T>>(_tree);
TrackedNode<T> trackedNode = tree.remove(path);
events.add(new NodeEvent<T>(NodeEventType.DELETED,
trackedNode));
if(log.isDebugEnabled())
log.debug(logString(path, "stop tracking node"));
// after a delete event, we try to track the node again as a delete/add event could happen
// and be undetected otherwise!
trackNode(path, tree, events, trackedNode.getDepth());
}
return tree;
}
代码示例来源:origin: org.fusesource.insight/insight-graph
this.tracker = new ZooKeeperTreeTracker<OutputWriter>(collector.getZkClient(), reader, zkPath);
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
public ZooKeeperTreeTracker(IZKClient zk, ZKDataReader<T> zkDataReader, String root, int depth)
{
_zk = zk;
_zkDataReader = zkDataReader;
_root = root;
_rootDepth = computeAbsoluteDepth(_root);
_depth = depth;
}
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
log.debug(logString(event.getPath(), "Raising error to " +
LangUtils.identityString(listener)),
th);
log.warn(logString(event.getPath(), "Error in watcher while executing listener " +
LangUtils.identityString(listener) +
" (ignored)"),
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
private Map<String, TrackedNode<T>> handleNodeChildrenChanged(String path,
Collection<NodeEvent<T>> events)
throws InterruptedException, KeeperException
{
return trackNode(path,
new LinkedHashMap<String, TrackedNode<T>>(_tree),
events,
computeDepth(path));
}
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
log.debug(logString(path, "max depth reached ${depth}"));
trackNode(childPath, tree, events, depth + 1);
_lock.notifyAll();
if(log.isDebugEnabled())
log.debug(logString(path,
"start tracking " + (depth < _depth ? "": "leaf ") +
"node zkTxId=" + newTrackedNode.getZkTxId()));
log.debug(logString(path, "no such node"));
代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl
private int computeDepth(String path)
{
return computeAbsoluteDepth(path) - _rootDepth;
}
代码示例来源:origin: org.fusesource.insight/insight-graph
@Override
public void validateSetup(Query query) throws ValidationException {
Map<String, TrackedNode<OutputWriter>> tree = tracker.getTree();
for (Map.Entry<String, TrackedNode<OutputWriter>> entry : tree.entrySet()) {
String name = entry.getKey();
TrackedNode<OutputWriter> value = entry.getValue();
OutputWriter data = value.getData();
if (data != null) {
configureWriter(data);
data.validateSetup(query);
}
}
}
代码示例来源:origin: org.fusesource.insight/insight-graph
@Override
public void stop() throws LifecycleException {
tracker.destroy();
super.stop();
}
代码示例来源:origin: org.fusesource.insight/insight-graph
@Override
public void doWrite(Query query) throws Exception {
Map<String, TrackedNode<OutputWriter>> tree = tracker.getTree();
for (Map.Entry<String, TrackedNode<OutputWriter>> entry : tree.entrySet()) {
String name = entry.getKey();
TrackedNode<OutputWriter> value = entry.getValue();
OutputWriter data = value.getData();
if (data != null) {
configureWriter(data);
data.doWrite(query);
}
}
}
代码示例来源:origin: org.fusesource.fabric/fabric-configadmin
private void load(String pid, String node, Dictionary dict) throws KeeperException, InterruptedException, IOException {
ZooKeeperTreeTracker<String> tree = track(node);
TrackedNode<String> root = tree != null ? tree.getTree().get(node) : null;
String[] parents = getParents(root);
for (String parent : parents) {
load(pid, ZkProfiles.getPath(version, parent), dict);
}
TrackedNode<String> cfg = tree != null ? tree.getTree().get(node + "/" + pid + ".properties") : null;
if (cfg != null) {
//if (cfg != null && !DELETED.equals(cfg.getData())) {
Properties properties = toProperties(cfg.getData());
// clear out the dict if it had a deleted key.
if (properties.remove(DELETED) != null) {
Enumeration keys = dict.keys();
while (keys.hasMoreElements()) {
dict.remove(keys.nextElement());
}
}
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (DELETED.equals(entry.getValue())) {
dict.remove(entry.getKey());
} else {
dict.put(entry.getKey(), entry.getValue());
}
}
}
}
代码示例来源:origin: org.fusesource.fabric/fabric-configadmin
private void getPids(String node, Set<String> pids) throws KeeperException, InterruptedException, IOException {
ZooKeeperTreeTracker<String> tree = track(node);
TrackedNode<String> root = tree != null ? tree.getTree().get(node) : null;
String[] parents = getParents(root);
for (String parent : parents) {
getPids(ZkProfiles.getPath(version, parent), pids);
}
for (String pid : getChildren(tree, node)) {
if (pid.endsWith(".properties")) {
pid = stripSuffix(pid, ".properties");
pids.add(pid);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!