* - WATCHES the following events: NodeCreated, NodeDataChanged, NodeChildrenChanged
* - IGNORES the following events: None, NodeDeleted
*/
@Override
public synchronized void process(WatchedEvent event) {
EventType type = event.getType();
LOG.debug("ZK-EVENT-PROCESS: Got zkEvent " + type +
" state:" + event.getState() +
" path:" + event.getPath());
// Handle the ignored events
if(type.equals(EventType.None) ||
type.equals(EventType.NodeDeleted)) {
return;
}
// check if the path is for the UNASSIGNED directory we care about
if(event.getPath() == null ||
!event.getPath().startsWith(zkWrapper.getZNodePathForHBase(
zkWrapper.getRegionInTransitionZNode()))) {
return;
}
try
{
/*
* If a node is created in the UNASSIGNED directory in zookeeper, then:
* 1. watch its updates (this is an unassigned region).
* 2. read to see what its state is and handle as needed (state may have
* changed before we started watching it)
*/
if(type.equals(EventType.NodeCreated)) {
zkWrapper.watchZNode(event.getPath());
handleRegionStateInZK(event.getPath());
}
/*
* Data on some node has changed. Read to see what the state is and handle
* as needed.
*/
else if(type.equals(EventType.NodeDataChanged)) {
handleRegionStateInZK(event.getPath());
}
/*
* If there were some nodes created then watch those nodes
*/
else if(type.equals(EventType.NodeChildrenChanged)) {
List<ZNodePathAndData> newZNodes =
zkWrapper.watchAndGetNewChildren(event.getPath());
for(ZNodePathAndData zNodePathAndData : newZNodes) {
LOG.debug("Handling updates for znode: " + zNodePathAndData.getzNodePath());
handleRegionStateInZK(zNodePathAndData.getzNodePath(),