publicabstractvoidprocess(WatchedEvent event);synchronizedpublicvoidprocess(WatchedEvent event){
ReplyHeader h =newReplyHeader(-1,-1L,0);if(LOG.isTraceEnabled()){
ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,"Deliver event "+ event +" to 0x"+ Long.toHexString(this.sessionId)+" through "+this);}// Convert WatchedEvent to a type that can be sent over the wire
WatcherEvent e = event.getWrapper();sendResponse(h, e,"notification");}
classSendThreadextendsZooKeeperThread{privatelong lastPingSentNs;privatefinal ClientCnxnSocket clientCnxnSocket;private Random r =newRandom(System.nanoTime());privateboolean isFirstConnect =true;voidreadResponse(ByteBuffer incomingBuffer)throws IOException {
ByteBufferInputStream bbis =newByteBufferInputStream(
incomingBuffer);
BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis);
ReplyHeader replyHdr =newReplyHeader();
replyHdr.deserialize(bbia,"header");......if(replyHdr.getXid()==-1){// -1 means notificationif(LOG.isDebugEnabled()){
LOG.debug("Got notification sessionid:0x"+ Long.toHexString(sessionId));}
WatcherEvent event =newWatcherEvent();
event.deserialize(bbia,"response");// convert from a server path to a client pathif(chrootPath != null){
String serverPath = event.getPath();if(serverPath.compareTo(chrootPath)==0)
event.setPath("/");elseif(serverPath.length()> chrootPath.length())
event.setPath(serverPath.substring(chrootPath.length()));else{
LOG.warn("Got server path "+ event.getPath()+" which is too short for chroot path "+ chrootPath);}}
WatchedEvent we =newWatchedEvent(event);if(LOG.isDebugEnabled()){
LOG.debug("Got "+ we +" for sessionid 0x"+ Long.toHexString(sessionId));}
eventThread.queueEvent( we );return;}......}
publicvoidqueueEvent(WatchedEvent event){if(event.getType()== EventType.None
&& sessionState == event.getState()){return;}
sessionState = event.getState();// materialize the watchers based on the event
WatcherSetEventPair pair =newWatcherSetEventPair(
watcher.materialize(event.getState(), event.getType(),
event.getPath()),
event);// queue the pair (watch set & event) for later processing
waitingEvents.add(pair);}