Parcourir la source

ZOOKEEPER-144 add tostring support for watcher event, and enums for event type/state

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@700664 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt il y a 16 ans
Parent
commit
acfce8b8fc

+ 3 - 0
CHANGES.txt

@@ -14,6 +14,9 @@ Backward compatibile changes:
 
   BUGFIXES: 
 
+  ZOOKEEPER-144. add tostring support for watcher event, and enums for event
+  type/state (Jakob Homan via phunt)
+
   ZOOKEEPER-21. Improve zk ctor/watcher (state transition) docs (phunt)
 
   ZOOKEEPER-142. Provide Javadoc as to the maximum size of the data byte 

+ 3 - 3
src/java/main/org/apache/zookeeper/ClientCnxn.java

@@ -493,13 +493,13 @@ public class ClientCnxn {
                 // -1 means notification
                 WatcherEvent event = new WatcherEvent();
                 event.deserialize(bbia, "response");
-                
+                WatchedEvent we = new WatchedEvent(event);
                 if (LOG.isDebugEnabled()) {
-                    LOG.debug("Got an event: " + event + " for sessionid 0x"
+                    LOG.debug("Got " + we + " for sessionid 0x"
                             + Long.toHexString(sessionId));
                 }
                 
-                eventThread.queueEvent( new WatchedEvent(event) );
+                eventThread.queueEvent( we );
                 return;
             }
             if (pendingQueue.size() == 0) {

+ 10 - 2
src/java/main/org/apache/zookeeper/WatchedEvent.java

@@ -62,12 +62,20 @@ public class WatchedEvent {
         return path;
     }
 
+    @Override
+    public String toString() {
+        if(path == null)  // then is a state change 
+            return "WatchedEvent: Server state change. New state: " + keeperState;
+         else  // is a znode change
+            return "WatchedEvent: Znode change. Path: " + path + " Type: " + eventType;
+    }
+
     /**
      *  Convert WatchedEvent to type that can be sent over network
      */
     public WatcherEvent getWrapper() {
         return new WatcherEvent(eventType.getIntValue(), 
-                                       keeperState.getIntValue(), 
-                                       path);
+                                keeperState.getIntValue(), 
+                                path);
     }
 }

+ 1 - 2
src/java/main/org/apache/zookeeper/ZooKeeperMain.java

@@ -51,8 +51,7 @@ public class ZooKeeperMain {
 
     static private class MyWatcher implements Watcher {
         public void process(WatchedEvent event) {
-            System.err.println(event.getPath() + ": " + event.getState() + "-"
-                    + event.getType());
+            System.err.println(event);
         }
     }