本文整理汇总了Java中org.apache.zookeeper.WatchedEvent.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java WatchedEvent.getPath方法的具体用法?Java WatchedEvent.getPath怎么用?Java WatchedEvent.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.zookeeper.WatchedEvent
的用法示例。
在下文中一共展示了WatchedEvent.getPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processDataOrChildChange
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的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);
}
}
}
示例2: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public void process(WatchedEvent event) {
if (isDestroyed()) {
return;
}
if (!getZooKeeperConnection().isConnected()) {
return;
}
String eventPath = event.getPath();
EventType eventType = event.getType();
Znode znode = getData();
String path = znode.getPath();
if (path.equals(eventPath) && eventType.equals(EventType.NodeDeleted)) {
destroy();
return;
}
processUpdate(event);
fireDataModelDataChanged();
}
示例3: processDataOrChildChange
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的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);
}
}
}
示例4: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
if (KeeperState.Expired == event.getState()) {
// It's all over
LOG.error("Lost session");
System.exit(4);
}
if (event.getPath() != null && event.getPath().equals(assignmentsNode)) {
// children have changed, so read in the new list
zk.getChildren(assignmentsNode, true, this, null);
}
}
示例5: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
/**
* Watcher callback
*/
public void process(WatchedEvent event) {
String path = event.getPath();
if (event.getType() == Event.EventType.None) {
// We are are being told that the state of the
// connection has changed
switch (event.getState()) {
case SyncConnected:
// In this particular example we don't need to do anything
// here - watches are automatically re-registered with
// server and any watches triggered while the client was
// disconnected will be delivered (in order of course)
onZooKeeperReconnected();
break;
case Expired:
// It's all over
onZooKeeperSessionClosed();
break;
// It's all over
case Disconnected:
onZooKeeperDisconnected();
break;
}
} else {
if (path != null && path.equals(getZNodePath())) {
// Something has changed on the node, let's find out
checkZNodeExistsAsync();
}
}
}
示例6: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
logger.debug("Received event: " + event);
_zookeeperEventThread = Thread.currentThread();
boolean stateChanged = event.getPath() == null;
boolean znodeChanged = event.getPath() != null;
boolean dataChanged = event.getType() == EventType.NodeDataChanged || //
event.getType() == EventType.NodeDeleted || event.getType() == EventType.NodeCreated || //
event.getType() == EventType.NodeChildrenChanged;
getEventLock().lock();
try {
// We might have to install child change event listener if a new node was created
if (getShutdownTrigger()) {
logger.debug("ignoring event '{" + event.getType() + " | " + event.getPath() + "}' since shutdown triggered");
return;
}
if (stateChanged) {
processStateChanged(event);
}
if (dataChanged) {
processDataOrChildChange(event);
}
} finally {
if (stateChanged) {
getEventLock().getStateChangedCondition().signalAll();
// If the session expired we have to signal all conditions, because watches might have been removed and
// there is no guarantee that those
// conditions will be signaled at all after an Expired event
if (event.getState() == KeeperState.Expired) {
getEventLock().getZNodeEventCondition().signalAll();
getEventLock().getDataChangedCondition().signalAll();
// We also have to notify all listeners that something might have changed
fireAllEvents();
}
}
if (znodeChanged) {
getEventLock().getZNodeEventCondition().signalAll();
}
if (dataChanged) {
getEventLock().getDataChangedCondition().signalAll();
}
getEventLock().unlock();
logger.debug("Leaving process event");
}
}
示例7: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
if (event.getPath() != null && event.getPath().equals("/simpleCase")) {
zk.getData("/simpleCase", true, this, null);
}
}
示例8: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
System.out.println("latch:" + path + " " + event.getPath());
this.eventPath = event.getPath();
latch.countDown();
}
示例9: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
@Override
public void process(final WatchedEvent p_event) {
String path;
String prefix;
List<String> children;
short nodeID;
NodeRole role;
String node;
String[] splits;
if (!m_shutdown) {
if (p_event.getType() == Event.EventType.None && p_event.getState() == KeeperState.Expired) {
// #if LOGGER >= ERROR
LOGGER.error("ZooKeeper state expired");
// #endif /* LOGGER >= ERROR */
} else {
try {
path = p_event.getPath();
prefix = m_zookeeper.getPath() + '/';
while (m_isStarting) {
try {
Thread.sleep(100);
} catch (final InterruptedException ignored) {
}
}
if (path != null) {
if (path.equals(prefix + "nodes/new")) {
children = m_zookeeper.getChildren("nodes/new", this);
for (String child : children) {
nodeID = Short.parseShort(child);
node = new String(zookeeperGetData("nodes/new/" + nodeID));
splits = node.split(":");
role = NodeRole.toNodeRole(splits[2]);
m_nodes.addNode(nodeID, new NodeEntry(new IPV4Unit(splits[0], Integer.parseInt(splits[1])), (short) 0, (short) 0, role, false));
}
}
}
} catch (final ZooKeeperException e) {
// #if LOGGER >= ERROR
LOGGER.error("Could not access ZooKeeper", e);
// #endif /* LOGGER >= ERROR */
}
}
}
}
示例10: process
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
public void process(WatchedEvent event) {
LOG.debug("Received event: " + event);
_zookeeperEventThread = Thread.currentThread();
boolean stateChanged = event.getPath() == null;
boolean znodeChanged = event.getPath() != null;
boolean dataChanged = event.getType() == EventType.NodeDataChanged || event.getType() == EventType.NodeDeleted
|| event.getType() == EventType.NodeCreated
|| event.getType() == EventType.NodeChildrenChanged;
getEventLock().lock();
try {
// We might have to install child change event listener if a new node was created
if (getShutdownTrigger()) {
LOG.debug("ignoring event '{" + event.getType() + " | " + event.getPath()
+ "}' since shutdown triggered");
return;
}
if (stateChanged) {
processStateChanged(event);
}
if (dataChanged) {
processDataOrChildChange(event);
}
} finally {
if (stateChanged) {
getEventLock().getStateChangedCondition().signalAll();
// If the session expired we have to signal all conditions, because watches might have been removed and
// there is no guarantee that those
// conditions will be signaled at all after an Expired event
// TODO PVo write a test for this
if (event.getState() == KeeperState.Expired) {
getEventLock().getZNodeEventCondition().signalAll();
getEventLock().getDataChangedCondition().signalAll();
// We also have to notify all listeners that something might have changed
fireAllEvents();
}
}
if (znodeChanged) {
getEventLock().getZNodeEventCondition().signalAll();
}
if (dataChanged) {
getEventLock().getDataChangedCondition().signalAll();
}
getEventLock().unlock();
LOG.debug("Leaving process event");
}
}
示例11: processWatchEvent
import org.apache.zookeeper.WatchedEvent; //导入方法依赖的package包/类
/**
* interface implementation of Zookeeper watch events (connection and node),
* proxied by {@link WatcherWithClientRef}.
*/
synchronized void processWatchEvent(ZooKeeper zk, WatchedEvent event) {
Event.EventType eventType = event.getType();
if (isStaleClient(zk)) return;
LOG.debug("Watcher event type: " + eventType + " with state:"
+ event.getState() + " for path:" + event.getPath()
+ " connectionState: " + zkConnectionState
+ " for " + this);
if (eventType == Event.EventType.None) {
// the connection state has changed
switch (event.getState()) {
case SyncConnected:
LOG.info("Session connected.");
// if the listener was asked to move to safe state then it needs to
// be undone
ConnectionState prevConnectionState = zkConnectionState;
zkConnectionState = ConnectionState.CONNECTED;
if (prevConnectionState == ConnectionState.DISCONNECTED &&
wantToBeInElection) {
monitorActiveStatus();
}
break;
case Disconnected:
LOG.info("Session disconnected. Entering neutral mode...");
// ask the app to move to safe state because zookeeper connection
// is not active and we dont know our state
zkConnectionState = ConnectionState.DISCONNECTED;
enterNeutralMode();
break;
case Expired:
// the connection got terminated because of session timeout
// call listener to reconnect
LOG.info("Session expired. Entering neutral mode and rejoining...");
enterNeutralMode();
reJoinElection(0);
break;
case SaslAuthenticated:
LOG.info("Successfully authenticated to ZooKeeper using SASL.");
break;
default:
fatalError("Unexpected Zookeeper watch event state: "
+ event.getState());
break;
}
return;
}
// a watch on lock path in zookeeper has fired. so something has changed on
// the lock. ideally we should check that the path is the same as the lock
// path but trusting zookeeper for now
String path = event.getPath();
if (path != null) {
switch (eventType) {
case NodeDeleted:
if (state == State.ACTIVE) {
enterNeutralMode();
}
joinElectionInternal();
break;
case NodeDataChanged:
monitorActiveStatus();
break;
default:
LOG.debug("Unexpected node event: " + eventType + " for path: " + path);
monitorActiveStatus();
}
return;
}
// some unexpected error has occurred
fatalError("Unexpected watch error from Zookeeper");
}