private boolean watchNextLowerNode ( ) throws KeeperException , InterruptedException { /* * Iterate through the sorted list of children and find the given node, * then setup a electionWatcher on the previous node if it exists, otherwise the * previous of the previous...until we reach the beginning, then we are * the lowest node. */ List < String > children = zk . getChildren ( dir , false ) ; Collections . sort ( children ) ; ListIterator < String > iter = children . listIterator ( ) ; String me = null ; //Go till I find myself. while ( iter . hasNext ( ) ) { me = ZKUtil . joinZKPath ( dir , iter . next ( ) ) ; if ( me . equals ( node ) ) { break ; } } assert ( me != null ) ; //Back on me iter . previous ( ) ; //Until we have previous nodes and we set a watch on previous node. while ( iter . hasPrevious ( ) ) { //Proess my lower nodes and put a watch on whats live String previous = ZKUtil . joinZKPath ( dir , iter . previous ( ) ) ; if ( zk . exists ( previous , electionWatcher ) != null ) { return false ; } } return true ; }
Set a watch on the node that comes before the specified node in the directory .