hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r734847 [1/2] - in /hadoop/zookeeper/trunk: ./ src/java/jmx/ src/java/main/org/apache/zookeeper/jmx/ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/persistence/ src/java/main/org/apache/zookeeper/server...
Date Thu, 15 Jan 2009 22:57:23 GMT
Author: phunt
Date: Thu Jan 15 14:57:14 2009
New Revision: 734847

URL: http://svn.apache.org/viewvc?rev=734847&view=rev
Log:
ZOOKEEPER-234. Eliminate using statics to initialize the sever. Should allow server to be more embeddable in OSGi enviorments.

Added:
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/CommonNames.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/MBeanRegistry.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java   (props changed)
      - copied unchanged from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/ZKMBeanInfo.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/LeaderBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/LeaderElectionBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElectionMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/LeaderElectionMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/LeaderMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/LocalPeerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/LocalPeerMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/QuorumBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/QuorumMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/RemotePeerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/RemotePeerMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/RemotePeerMXBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ServerBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/ServerBean.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ServerMXBean.java   (contents, props changed)
      - copied, changed from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/ServerMXBean.java
Removed:
    hadoop/zookeeper/trunk/src/java/jmx/
Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataNode.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Follower.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerHandler.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/ProposalRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumStats.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/CRCTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/InvalidSnapshotTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ACLTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FLETest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LETest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RepeatStartupTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/UpgradeTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherTest.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Thu Jan 15 14:57:14 2009
@@ -3,8 +3,8 @@
 Non-backward compatible changes:
 
 BUGFIXES:
-  ZOOKEEPER-255. zoo_set() api does not return stat datastructure. (avery
-ching via mahadev)
+  ZOOKEEPER-255. zoo_set() api does not return stat datastructure.
+  (avery ching via mahadev)
 
 Backward compatibile changes:
 
@@ -64,7 +64,7 @@
   files better. (mahadev via phunt)
  
   ZOOKEEPER-265. remove (deprecate) unused NoSyncConnected from KeeperState.
-(phunt via mahadev)
+  (phunt via mahadev)
  
 IMPROVEMENTS:
    
@@ -83,25 +83,29 @@
    ZOOKEEPER-230. Improvements to FLE. (Flavio via mahadev)
 
    ZOOKEEPER-225. c client should log an info message in zookeeper_init
-detailing connection parameters. (pat via mahadev)
+   detailing connection parameters. (pat via mahadev)
 
    ZOOKEEPER-222.  print C client log message timestamp in human readable
-form. (pat via mahadev) 
+   form. (pat via mahadev) 
   
-   ZOOKEEPER-246. review error code definition in both source and docs. (pat
-via mahadev)
+   ZOOKEEPER-246. review error code definition in both source and docs.
+   (pat via mahadev)
 
    ZOOKEEPER-256. support use of JMX to manage log4j configuration at runtime.
-(pat via mahadev)
+   (pat via mahadev)
 
-   ZOOKEEPER-214. add new "stat reset" command to server admin port. (pat via
-mahadev)
+   ZOOKEEPER-214. add new "stat reset" command to server admin port.
+   (pat via mahadev)
 
    ZOOKEEPER-258. docs incorrectly state max client timeout as 60 seconds
-(it's based on server ticktime). (phunt via mahadev)
+   (it's based on server ticktime). (phunt via mahadev)
 
    ZOOKEEPER-135. Fat jar build target. (phunt and breed via mahadev)
 
+   ZOOKEEPER-234. Eliminate using statics to initialize the sever. Should
+   allow server to be more embeddable in OSGi enviorments. (phunt)
+
+
 Release 3.0.0 - 2008-10-21
 
 Non-backward compatible changes:

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/CommonNames.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/CommonNames.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/CommonNames.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java Thu Jan 15 14:57:14 2009
@@ -23,7 +23,7 @@
  * TODO: will get rid of it eventually.
  */
 public class CommonNames {
-    public static final String DOMAIN="org.apache.ZookeeperService";
+    public static final String DOMAIN="org.apache.ZooKeeperService";
     public static final String DATA_TREE_KEY="DataTree";
     public static final String STANDALONE_SERVER_KEY="StandaloneServer";
 }

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/CommonNames.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/MBeanRegistry.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/MBeanRegistry.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/MBeanRegistry.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java Thu Jan 15 14:57:14 2009
@@ -35,9 +35,14 @@
  */
 public class MBeanRegistry {
     private static final Logger LOG = Logger.getLogger(MBeanRegistry.class);
+    
     private static MBeanRegistry instance=new MBeanRegistry(); 
-    private Map<ZKMBeanInfo, String> mapBean2Path = new ConcurrentHashMap<ZKMBeanInfo, String>();
-    private Map<String, ZKMBeanInfo> mapName2Bean = new ConcurrentHashMap<String, ZKMBeanInfo>();
+    
+    private Map<ZKMBeanInfo, String> mapBean2Path =
+        new ConcurrentHashMap<ZKMBeanInfo, String>();
+    
+    private Map<String, ZKMBeanInfo> mapName2Bean =
+        new ConcurrentHashMap<String, ZKMBeanInfo>();
 
     public static MBeanRegistry getInstance(){
         return instance;

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/MBeanRegistry.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/server/ManagedUtil.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java Thu Jan 15 14:57:14 2009
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.server;
+package org.apache.zookeeper.jmx;
 
 import java.lang.management.ManagementFactory;
 import java.util.Enumeration;

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/jmx/ZKMBeanInfo.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java Thu Jan 15 14:57:14 2009
@@ -16,17 +16,14 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server;
+package org.apache.zookeeper.server;
 
 import java.util.Arrays;
 import java.util.Date;
 
 import org.apache.log4j.Logger;
-
 import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.jmx.ZKMBeanInfo;
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ZooKeeperServer;
 
 /**
  * Implementation of connection MBean interface.
@@ -44,7 +41,7 @@
     }
     
     public String getSessionId() {
-        return Long.toHexString(connection.getSessionId());
+        return "0x" + Long.toHexString(connection.getSessionId());
     }
 
     

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionMXBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionMXBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ConnectionMXBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java Thu Jan 15 14:57:14 2009
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server;
+package org.apache.zookeeper.server;
 
 /**
  * This MBean represents a client connection.

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ConnectionMXBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataNode.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataNode.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataNode.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataNode.java Thu Jan 15 14:57:14 2009
@@ -19,15 +19,11 @@
 package org.apache.zookeeper.server;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 
-import org.apache.jute.Index;
 import org.apache.jute.InputArchive;
 import org.apache.jute.OutputArchive;
 import org.apache.jute.Record;
-import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.StatPersisted;
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTree.java Thu Jan 15 14:57:14 2009
@@ -44,7 +44,6 @@
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.StatPersisted;
-import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.txn.CreateTxn;
 import org.apache.zookeeper.txn.DeleteTxn;
 import org.apache.zookeeper.txn.ErrorTxn;
@@ -68,7 +67,8 @@
      * This hashtable provides a fast lookup to the datanodes. The tree is the
      * source of truth and is where all the locking occurs
      */
-    private ConcurrentHashMap<String, DataNode> nodes = new ConcurrentHashMap<String, DataNode>();
+    private ConcurrentHashMap<String, DataNode> nodes =
+        new ConcurrentHashMap<String, DataNode>();
 
     private WatchManager dataWatches = new WatchManager();
 
@@ -213,6 +213,19 @@
     }
 
     /**
+     * Get the size of the nodes based on path and data length.
+     * @return size of the data
+     */
+    public long approximateDataSize() {
+        long result = 0;
+        for (Map.Entry<String, DataNode> entry : nodes.entrySet()) {
+            result += entry.getKey().length();
+            result += entry.getValue().data.length;
+        }
+        return result;
+    }
+    
+    /**
      * This is a pointer to the root of the DataTree. It is the source of truth,
      * but we usually use the nodes hashmap to find nodes in the tree.
      */

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java Thu Jan 15 14:57:14 2009
@@ -16,59 +16,41 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server;
+package org.apache.zookeeper.server;
+
+import java.util.HashSet;
+import java.util.Map;
 
-import org.apache.log4j.Logger;
 import org.apache.zookeeper.jmx.ZKMBeanInfo;
+import org.apache.zookeeper.server.DataTree;
 
 /**
  * This class implements the data tree MBean.
  */
 public class DataTreeBean implements DataTreeMXBean, ZKMBeanInfo {
-    private static final Logger LOG = Logger.getLogger(DataTreeBean.class);
-
-    org.apache.zookeeper.server.DataTree dataTree;
+    DataTree dataTree;
     
-    public DataTreeBean(){
-    }
-
     public DataTreeBean(org.apache.zookeeper.server.DataTree dataTree){
-        this.dataTree=dataTree;
+        this.dataTree = dataTree;
     }
     
     public int getNodeCount() {
         return dataTree.getNodeCount();
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.zookeeper.jmx.server.DataTreeMBean#getDataSize()
-     */
-    //TODO: it's useful info but can be expensive to get
-    public long getDataSize() {
-      /*  We need a more efficient way to do this
-        ByteArrayOutputStream stream=new ByteArrayOutputStream();
-        BinaryOutputArchive oa = BinaryOutputArchive.getArchive(stream);
-        try {
-            dataTree.serialize(oa, "tree");
-        } catch (Exception e) {
-            LOG.warn("Failed to get data tree size: "+e.getMessage());            
+    public long approximateDataSize() {
+        return dataTree.approximateDataSize();
+    }
+
+    public int countEphemerals() {
+        Map<Long, HashSet<String>> map = dataTree.getEphemeralsMap();
+        int result = 0;
+        for (HashSet<String> set : map.values()) {
+            result += set.size();
         }
-        return stream.size();
-      */
-        LOG.warn("Not Implemented");            
-        return -1;
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.zookeeper.jmx.server.DataTreeMBean#getEphemeralCount()
-     */
-    public int getEphemeralCount() {
-        return dataTree.getSessions().size();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.zookeeper.jmx.server.DataTreeMBean#getWatchCount()
-     */
+        return result;
+    }
+
     public int getWatchCount() {
         return dataTree.getWatchCount();
     }
@@ -81,8 +63,8 @@
         return false;
     }
 
-    public long getLastZxid() {
-        return dataTree.lastProcessedZxid;
+    public String getLastZxid() {
+        return "0x" + Long.toHexString(dataTree.lastProcessedZxid);
     }
 
 }

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeMXBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeMXBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/DataTreeMXBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java Thu Jan 15 14:57:14 2009
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server;
+package org.apache.zookeeper.server;
 
 /**
  * Zookeeper data tree MBean.
@@ -27,20 +27,21 @@
      */
     public int getNodeCount();
     /**
-     * @return data tree size in bytes. The size includes the znode path and 
-     * its value.
-     */
-    public long getDataSize();
-    /**
      * @return the most recent zxid processed by the data tree.
      */
-    public long getLastZxid();
+    public String getLastZxid();
     /**
      * @return number of watches set.
      */
     public int getWatchCount();
+    
+    /**
+     * @return data tree size in bytes. The size includes the znode path and 
+     * its value.
+     */
+    public long approximateDataSize();
     /**
      * @return number of ephemeral nodes in the data tree
      */
-    public int getEphemeralCount();
+    public int countEphemerals();
 }

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/DataTreeMXBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java Thu Jan 15 14:57:14 2009
@@ -251,7 +251,7 @@
         }
         ReplyHeader hdr =
             new ReplyHeader(request.cxid, request.zxid, err.intValue());
-        ServerStats.getInstance().updateLatency(request.createTime);
+        zks.serverStats().updateLatency(request.createTime);
         try {
             request.cnxn.sendResponse(hdr, rsp, "response");
         } catch (IOException e) {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java Thu Jan 15 14:57:14 2009
@@ -50,6 +50,7 @@
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.data.Id;
+import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.proto.AuthPacket;
 import org.apache.zookeeper.proto.ConnectRequest;
 import org.apache.zookeeper.proto.ConnectResponse;
@@ -66,6 +67,8 @@
 public class NIOServerCnxn implements Watcher, ServerCnxn {
     private static final Logger LOG = Logger.getLogger(NIOServerCnxn.class);
 
+    private ConnectionBean jmxConnectionBean;
+
     static public class Factory extends Thread {
         ZooKeeperServer zks;
 
@@ -113,7 +116,7 @@
         public ZooKeeperServer getZooKeeperServer() {
             return this.zks;
         }
- 
+
         public InetSocketAddress getLocalAddress(){
             return (InetSocketAddress)ss.socket().getLocalSocketAddress();
         }
@@ -294,13 +297,13 @@
                         readLength(k);
                     } else if (!initialized) {
                         stats.packetsReceived++;
-                        ServerStats.getInstance().incrementPacketsReceived();
+                        zk.serverStats().incrementPacketsReceived();
                         readConnectRequest();
                         lenBuffer.clear();
                         incomingBuffer = lenBuffer;
                     } else {
                         stats.packetsReceived++;
-                        ServerStats.getInstance().incrementPacketsReceived();
+                        zk.serverStats().incrementPacketsReceived();
                         readRequest();
                         lenBuffer.clear();
                         incomingBuffer = lenBuffer;
@@ -378,7 +381,7 @@
                         stats.packetsSent++;
                         /* We've sent the whole buffer, so drop the buffer */
                         sent -= bb.remaining();
-                        ServerStats.getInstance().incrementPacketsSent();
+                        zk.serverStats().incrementPacketsSent();
                         outgoingBuffers.remove();
                     }
                     // ZooLog.logTraceMessage(LOG,
@@ -423,7 +426,7 @@
             String scheme = authPacket.getScheme();
             AuthenticationProvider ap = ProviderRegistry.getProvider(scheme);
             if (ap == null
-                    || (ap.handleAuthentication(this, authPacket.getAuth()) 
+                    || (ap.handleAuthentication(this, authPacket.getAuth())
                             != KeeperException.Code.OK)) {
                 if (ap == null)
                     LOG.error("No authentication provider for scheme: "
@@ -526,7 +529,7 @@
             // We take advantage of the limited size of the length to look
             // for cmds. They are all 4-bytes which fits inside of an int
             if (len == ruokCmd) {
-                LOG.info("Processing ruok command from " 
+                LOG.info("Processing ruok command from "
                         + sock.socket().getRemoteSocketAddress());
 
                 sendBuffer(imok.duplicate());
@@ -534,11 +537,11 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == killCmd) {
-                LOG.info("Processing kill command from " 
+                LOG.info("Processing kill command from "
                         + sock.socket().getRemoteSocketAddress());
                 System.exit(0);
             } else if (len == getTraceMaskCmd) {
-                LOG.info("Processing getracemask command from " 
+                LOG.info("Processing getracemask command from "
                         + sock.socket().getRemoteSocketAddress());
                 long traceMask = ZooTrace.getTextTraceLevel();
                 ByteBuffer resp = ByteBuffer.allocate(8);
@@ -549,7 +552,7 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == setTraceMaskCmd) {
-                LOG.info("Processing settracemask command from " 
+                LOG.info("Processing settracemask command from "
                         + sock.socket().getRemoteSocketAddress());
                 incomingBuffer = ByteBuffer.allocate(8);
 
@@ -569,7 +572,7 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == dumpCmd) {
-                LOG.info("Processing dump command from " 
+                LOG.info("Processing dump command from "
                         + sock.socket().getRemoteSocketAddress());
                 if (zk == null) {
                     sendBuffer(ByteBuffer.wrap("ZooKeeper not active \n"
@@ -585,7 +588,7 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == reqsCmd) {
-                LOG.info("Processing reqs command from " 
+                LOG.info("Processing reqs command from "
                         + sock.socket().getRemoteSocketAddress());
                 StringBuffer sb = new StringBuffer();
                 sb.append("Requests:\n");
@@ -599,7 +602,7 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == statCmd) {
-                LOG.info("Processing stat command from " 
+                LOG.info("Processing stat command from "
                         + sock.socket().getRemoteSocketAddress());
                 StringBuffer sb = new StringBuffer();
                 if(zk!=null){
@@ -612,7 +615,7 @@
                         }
                     }
                     sb.append("\n");
-                    sb.append(ServerStats.getInstance().toString());
+                    sb.append(zk.serverStats().toString());
                     sb.append("Node count: ").append(zk.dataTree.getNodeCount()).
                         append("\n");
                 }else
@@ -622,12 +625,12 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == enviCmd) {
-                LOG.info("Processing envi command from " 
+                LOG.info("Processing envi command from "
                         + sock.socket().getRemoteSocketAddress());
                 StringBuffer sb = new StringBuffer();
-                
+
                 List<Environment.Entry> env = Environment.list();
-                
+
                 sb.append("Environment:\n");
                 for(Environment.Entry e : env) {
                     sb.append(e.getKey()).append("=").append(e.getValue())
@@ -638,10 +641,9 @@
                 k.interestOps(SelectionKey.OP_WRITE);
                 return;
             } else if (len == srstCmd) {
-                LOG.info("Processing srst command from " 
+                LOG.info("Processing srst command from "
                         + sock.socket().getRemoteSocketAddress());
-                ServerStats stats = ServerStats.getInstance();
-                stats.reset();
+                zk.serverStats().reset();
 
                 sendBuffer(ByteBuffer.wrap("Stats reset.\n".getBytes()));
                 k.interestOps(SelectionKey.OP_WRITE);
@@ -707,6 +709,16 @@
      * @see org.apache.zookeeper.server.ServerCnxnIface#close()
      */
     public void close() {
+        // unregister from JMX
+        try {
+            if(jmxConnectionBean != null){
+                MBeanRegistry.getInstance().unregister(jmxConnectionBean);
+            }
+        } catch (Exception e) {
+            LOG.warn("Failed to unregister with JMX", e);
+        }
+        jmxConnectionBean = null;
+
         if (closed) {
             return;
         }
@@ -812,16 +824,24 @@
         ReplyHeader h = new ReplyHeader(-1, -1L, 0);
         ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                  "Deliver event " + event + " to 0x"
-                                 + Long.toHexString(this.sessionId) 
+                                 + 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");
     }
 
     public void finishSessionInit(boolean valid) {
+        // register with JMX
+        try {
+            jmxConnectionBean = new ConnectionBean(this, zk);
+            MBeanRegistry.getInstance().register(jmxConnectionBean, zk.jmxServerBean);
+        } catch (Exception e) {
+            LOG.warn("Failed to register with JMX", e);
+        }
+
         try {
             ConnectResponse rsp = new ConnectResponse(0, valid ? sessionTimeout
                     : 0, valid ? sessionId : 0, // send 0 if session is no
@@ -850,7 +870,7 @@
             close();
         }
     }
-
+    
     /*
      * (non-Javadoc)
      *

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java Thu Jan 15 14:57:14 2009
@@ -27,14 +27,13 @@
 
 import org.apache.jute.Record;
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
-import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.StatPersisted;
 import org.apache.zookeeper.proto.CreateRequest;
 import org.apache.zookeeper.proto.DeleteRequest;

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxn.java Thu Jan 15 14:57:14 2009
@@ -24,11 +24,10 @@
 import java.util.ArrayList;
 
 import org.apache.jute.Record;
-import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.proto.ReplyHeader;
-import org.apache.zookeeper.proto.WatcherEvent;
 
 public interface ServerCnxn extends Watcher {
     

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java Thu Jan 15 14:57:14 2009
@@ -19,47 +19,37 @@
 package org.apache.zookeeper.server;
 
 
+/**
+ * Basic Server Statistics
+ */
 public class ServerStats {
-    private static ServerStats instance=null;
     private long packetsSent;
     private long packetsReceived;
     private long maxLatency;
     private long minLatency = Long.MAX_VALUE;
     private long totalLatency = 0;
     private long count = 0;
-    
-    public interface Provider{
+
+    private final Provider provider;
+
+    public interface Provider {
         public long getOutstandingRequests();
         public long getLastProcessedZxid();
     }
-    private Provider provider=null;
-    private Object mutex=new Object();
     
-    static public ServerStats getInstance(){
-        return instance;
-    }
-    static public void registerAsConcrete() {
-        setInstance(new ServerStats());
-    }
-    static synchronized public void unregister() {
-        instance=null;
-    }
-    static synchronized protected void setInstance(ServerStats newInstance){
-        assert instance==null;
-        instance = newInstance;
-    }
-    protected ServerStats() {
-        // protected constructor
+    public ServerStats(Provider provider) {
+        this.provider = provider;
     }
     
     // getters
     synchronized public long getMinLatency() {
-        return (minLatency == Long.MAX_VALUE) ? 0 : minLatency;
+        return minLatency == Long.MAX_VALUE ? 0 : minLatency;
     }
 
     synchronized public long getAvgLatency() {
-        if(count!=0)
+        if (count != 0) {
             return totalLatency / count;
+        }
         return 0;
     }
 
@@ -68,15 +58,13 @@
     }
 
     public long getOutstandingRequests() {
-        synchronized(mutex){
-            return (provider!=null)?provider.getOutstandingRequests():-1;
-        }
+        return provider.getOutstandingRequests();
     }
+    
     public long getLastProcessedZxid(){
-        synchronized(mutex){
-            return (provider!=null)?provider.getLastProcessedZxid():-1;
-        }
+        return provider.getLastProcessedZxid();
     }
+    
     synchronized public long getPacketsReceived() {
         return packetsReceived;
     }
@@ -85,7 +73,7 @@
         return packetsSent;
     }
 
-    public String getServerState(){
+    public String getServerState() {
         return "standalone";
     }
     
@@ -100,15 +88,10 @@
             sb.append("Outstanding: " + getOutstandingRequests() + "\n");
             sb.append("Zxid: 0x"+ Long.toHexString(getLastProcessedZxid())+ "\n");
         }
-        sb.append("Mode: "+getServerState()+"\n");
+        sb.append("Mode: " + getServerState() + "\n");
         return sb.toString();
     }
     // mutators
-    public void setStatsProvider(Provider zk){
-        synchronized(mutex){
-            provider=zk;
-        }
-    }
     synchronized void updateLatency(long requestCreateTime) {
         long latency = System.currentTimeMillis() - requestCreateTime;
         totalLatency += latency;
@@ -121,11 +104,13 @@
         }
     }
     synchronized public void resetLatency(){
-        totalLatency=count=maxLatency=0;
-        minLatency=Long.MAX_VALUE;
+        totalLatency = 0;
+        count = 0;
+        maxLatency = 0;
+        minLatency = Long.MAX_VALUE;
     }
     synchronized public void resetMaxLatency(){
-        maxLatency=getMinLatency();
+        maxLatency = getMinLatency();
     }
     synchronized public void incrementPacketsReceived() {
         packetsReceived++;
@@ -134,7 +119,8 @@
         packetsSent++;
     }
     synchronized public void resetRequestCounters(){
-        packetsReceived=packetsSent=0;
+        packetsReceived = 0;
+        packetsSent = 0;
     }
     
     synchronized public void reset() {

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/WatchManager.java Thu Jan 15 14:57:14 2009
@@ -23,12 +23,10 @@
 import java.util.Set;
 
 import org.apache.log4j.Logger;
-
+import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.proto.WatcherEvent;
 
 /**
  * This class manages watches. It allows watches to be associated with a string

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java Thu Jan 15 14:57:14 2009
@@ -41,6 +41,7 @@
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.StatPersisted;
+import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.proto.RequestHeader;
 import org.apache.zookeeper.server.SessionTracker.SessionExpirer;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
@@ -57,7 +58,7 @@
  * PrepRequestProcessor -> SyncRequestProcessor -> FinalRequestProcessor
  */
 public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
-    private static final Logger LOG;
+    protected static final Logger LOG;
     
     static {
         LOG = Logger.getLogger(ZooKeeperServer.class);
@@ -65,8 +66,11 @@
         Environment.logEnv("Server environment:", LOG);
     }
 
+    protected ZooKeeperServerBean jmxServerBean;
+    protected DataTreeBean jmxDataTreeBean;
+
     /**
-     * Create an instance of Zookeeper server
+     * Create an instance of ZooKeeper server
      */
     static public interface Factory {
         public ZooKeeperServer createServer() throws IOException;
@@ -105,20 +109,23 @@
     protected RequestProcessor firstProcessor;
     LinkedBlockingQueue<Long> sessionsToDie = new LinkedBlockingQueue<Long>();
     protected volatile boolean running;
+
     /**
      * This is the secret that we use to generate passwords, for the moment it
      * is more of a sanity check.
      */
     final private long superSecret = 0XB3415C00L;
+
     int requestsInProcess;
     List<ChangeRecord> outstandingChanges = new ArrayList<ChangeRecord>();
     private NIOServerCnxn.Factory serverCnxnFactory;
     private int clientPort;
-    
+
+    private final ServerStats serverStats;
+
     void removeCnxn(ServerCnxn cnxn) {
         dataTree.removeCnxn(cnxn);
     }
-
  
     /**
      * Creates a ZooKeeperServer instance. Nothing is setup, use the setX
@@ -128,10 +135,9 @@
      * @throws IOException
      */
     public ZooKeeperServer() {
-        ServerStats.getInstance().setStatsProvider(this);
+        serverStats = new ServerStats(this);
         treeBuilder = new BasicDataTreeBuilder();
     }
-
     
     /**
      * Creates a ZooKeeperServer instance. It sets everything up, but doesn't
@@ -142,14 +148,19 @@
      */
     public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime,
             DataTreeBuilder treeBuilder) throws IOException {
-        this.txnLogFactory=txnLogFactory;
-        this.tickTime = tickTime;
+        serverStats = new ServerStats(this);
         this.treeBuilder = treeBuilder;
-        ServerStats.getInstance().setStatsProvider(this);
+
+        this.txnLogFactory = txnLogFactory;
+        this.tickTime = tickTime;
         
         LOG.info("Created server");
     }
 
+    public ServerStats serverStats() {
+        return serverStats;
+    }
+    
     /**
      * This constructor is for backward compatibility with the existing unit
      * test code.
@@ -324,12 +335,27 @@
         }
     }
 
+    protected void registerJMX() {
+        // register with JMX
+        try {
+            jmxServerBean = new ZooKeeperServerBean(this);
+            MBeanRegistry.getInstance().register(jmxServerBean, null);
+            jmxDataTreeBean = new DataTreeBean(dataTree);
+            MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean);
+        } catch (Exception e) {
+            LOG.warn("Failed to register with JMX", e);
+        }
+    }
+    
     public void startup() throws IOException, InterruptedException {
         if (dataTree == null) {
             loadData();
         }
         createSessionTracker();
         setupRequestProcessors();
+
+        registerJMX();
+
         synchronized (this) {
             running = true;
             notifyAll();
@@ -367,6 +393,24 @@
         if (dataTree != null) {
             dataTree.clear();
         }
+
+        unregisterJMX();
+    }
+
+    protected void unregisterJMX() {
+        // unregister from JMX
+        try {
+            if (jmxDataTreeBean != null) {
+                MBeanRegistry.getInstance().unregister(jmxDataTreeBean);
+            }
+            if (jmxServerBean != null) {
+                MBeanRegistry.getInstance().unregister(jmxServerBean);
+            }
+        } catch (Exception e) {
+            LOG.warn("Failed to unregister with JMX", e);
+        }
+        jmxServerBean = null;
+        jmxDataTreeBean = null;
     }
 
     synchronized public void incInProcess() {

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java Thu Jan 15 14:57:14 2009
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server;
+package org.apache.zookeeper.server;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -28,23 +28,21 @@
 import org.apache.zookeeper.server.ZooKeeperServer;
 
 /**
- * This class implements the zookeeper server MBean interface.
+ * This class implements the ZooKeeper server MBean interface.
  */
 public class ZooKeeperServerBean implements ZooKeeperServerMXBean, ZKMBeanInfo {
-    private Date startTime=new Date();
-    private ZooKeeperServer zooKeeperServer;
+    private final Date startTime;
+    private final String name;
     
-    public ZooKeeperServerBean() {        
-    }
-    public ZooKeeperServerBean(ZooKeeperServer zooKeeperServer) {
-        this.zooKeeperServer = zooKeeperServer;
+    protected final ZooKeeperServer zks;
+    
+    public ZooKeeperServerBean(ZooKeeperServer zks) {
+        startTime = new Date();
+        this.zks = zks;
+        name = "StandaloneServer_port" + zks.getClientPort();
     }
-
+    
     public String getClientPort() {
-        ZooKeeperServer zks = getZooKeeperServer();
-        if( zks == null ) {
-            return null;
-        }
         try {
             return InetAddress.getLocalHost().getHostAddress() + ":"
                     + zks.getClientPort();
@@ -54,7 +52,7 @@
     }
     
     public String getName() {
-        return "StandaloneServer";
+        return name;
     }
     
     public boolean isHidden() {
@@ -70,48 +68,49 @@
     }
     
     public long getAvgRequestLatency() {
-        return ServerStats.getInstance().getAvgLatency();
+        return zks.serverStats().getAvgLatency();
     }
     
     public long getMaxRequestLatency() {
-        return ServerStats.getInstance().getMaxLatency();
+        return zks.serverStats().getMaxLatency();
     }
     
     public long getMinRequestLatency() {
-        return ServerStats.getInstance().getMinLatency();
+        return zks.serverStats().getMinLatency();
     }
     
     public long getOutstandingRequests() {
-        return ServerStats.getInstance().getOutstandingRequests();
+        return zks.serverStats().getOutstandingRequests();
+    }
+
+    public int getTickTime() {
+        return zks.getTickTime();
     }
+
+    public void setTickTime(int tickTime) {
+        zks.setTickTime(tickTime);
+    }
+
     
     public long getPacketsReceived() {
-        return ServerStats.getInstance().getPacketsReceived();
+        return zks.serverStats().getPacketsReceived();
     }
     
     public long getPacketsSent() {
-        return ServerStats.getInstance().getPacketsSent();
+        return zks.serverStats().getPacketsSent();
     }
     
     public void resetLatency() {
-        ServerStats.getInstance().resetLatency();
+        zks.serverStats().resetLatency();
     }
     
     public void resetMaxLatency() {
-        ServerStats.getInstance().resetMaxLatency();
+        zks.serverStats().resetMaxLatency();
     }
 
     public void resetStatistics() {
-        ServerStats.getInstance().resetRequestCounters();
-        ServerStats.getInstance().resetLatency();
-    }
-
-    public ZooKeeperServer getZooKeeperServer() {
-        return zooKeeperServer;
+        ServerStats serverStats = zks.serverStats();
+        serverStats.resetRequestCounters();
+        serverStats.resetLatency();
     }
-
-    public void setZooKeeperServer(ZooKeeperServer zooKeeperServer) {
-        this.zooKeeperServer = zooKeeperServer;
-    }
-
 }

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerMXBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerMXBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/ZooKeeperServerMXBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java Thu Jan 15 14:57:14 2009
@@ -16,10 +16,10 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server;
+package org.apache.zookeeper.server;
 
 /**
- * Zookeeper server MBean.
+ * ZooKeeper server MBean.
  */
 public interface ZooKeeperServerMXBean {
     /**
@@ -58,7 +58,15 @@
      * @return number of outstanding requests.
      */
     public long getOutstandingRequests();
-    
+    /**
+     * Current TickTime of server
+     */
+    public int getTickTime();
+    /**
+     * Set TickTime of server
+     */
+    public void setTickTime(int tickTime);
+
     /**
      * Reset packet and latency statistics 
      */

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java Thu Jan 15 14:57:14 2009
@@ -21,9 +21,11 @@
 import java.io.File;
 import java.io.IOException;
 
+import javax.management.JMException;
+
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.jmx.ManagedUtil;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
-import org.apache.zookeeper.server.ZooKeeperServer.BasicDataTreeBuilder;
 
 /**
  * This class starts and runs a standalone ZooKeeperServer.
@@ -39,6 +41,12 @@
      */
     public static void main(String[] args) {
         try {
+            ManagedUtil.registerLog4jMBeans();
+        } catch (JMException e) {
+            LOG.warn("Unable to register log4j JMX control", e);
+        }
+
+        try {
             ServerConfig.parse(args);
         } catch(Exception e) {
             LOG.fatal("Error in config", e);
@@ -64,17 +72,17 @@
         });
     }
 
-    public static void runStandalone(ZooKeeperServer.Factory factory) {
+    public static void runStandalone(ZooKeeperServer.Factory serverFactory) {
         try {
             // Note that this thread isn't going to be doing anything else,
             // so rather than spawning another thread, we will just call
             // run() in this thread.
-            ServerStats.registerAsConcrete();
-            ZooKeeperServer zk = factory.createServer();
+            ZooKeeperServer zk = serverFactory.createServer();
             zk.startup();
-            NIOServerCnxn.Factory t = factory.createConnectionFactory();
-            t.setZooKeeperServer(zk);
-            t.join();
+            NIOServerCnxn.Factory cnxnFactory =
+                serverFactory.createConnectionFactory();
+            cnxnFactory.setZooKeeperServer(zk);
+            cnxnFactory.join();
             if (zk.isRunning()) {
                 zk.shutdown();
             }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java Thu Jan 15 14:57:14 2009
@@ -26,7 +26,6 @@
 import org.apache.jute.Record;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.ZooDefs.OpCode;
-import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.server.DataTree;
 import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.ZooTrace;

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java Thu Jan 15 14:57:14 2009
@@ -19,7 +19,6 @@
 
 package org.apache.zookeeper.server.quorum;
 
-import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.HashMap;

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Follower.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Follower.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Follower.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/Follower.java Thu Jan 15 14:57:14 2009
@@ -60,6 +60,16 @@
         this.zk=zk;
     }
 
+    @Override
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("Follower ").append(sock);
+        sb.append(" lastQueuedZxid:").append(lastQueued);
+        sb.append(" pendingRevalidationCount:")
+            .append(pendingRevalidations.size());
+        return sb.toString();
+    }
+
     private InputArchive leaderIs;
 
     private OutputArchive leaderOs;
@@ -111,182 +121,193 @@
      * @throws InterruptedException
      */
     void followLeader() throws InterruptedException {
-        InetSocketAddress addr = null;
-        // Find the leader by id
-        Vote current = self.getCurrentVote();
-        for (QuorumServer s : self.quorumPeers.values()) {
-            if (s.id == current.id) {
-                addr = s.addr;
-                break;
-            }
-        }
-        if (addr == null) {
-            LOG.warn("Couldn't find the leader with id = "
-                    + current.id);
-        }
-        LOG.info("Following " + addr);
-        sock = new Socket();
+        zk.registerJMX(new FollowerBean(this, zk), self.jmxLocalPeerBean);
+
         try {
-            QuorumPacket ack = new QuorumPacket(Leader.ACK, 0, null, null);
-            sock.setSoTimeout(self.tickTime * self.initLimit);
-            for (int tries = 0; tries < 5; tries++) {
-                try {
-                    //sock = new Socket();
-                    //sock.setSoTimeout(self.tickTime * self.initLimit);
-                    sock.connect(addr, self.tickTime * self.syncLimit);
-                    sock.setTcpNoDelay(true);
+            InetSocketAddress addr = null;
+            // Find the leader by id
+            Vote current = self.getCurrentVote();
+            for (QuorumServer s : self.quorumPeers.values()) {
+                if (s.id == current.id) {
+                    addr = s.addr;
                     break;
-                } catch (ConnectException e) {
-                    if (tries == 4) {
-                        LOG.error("Unexpected exception",e);
-                        throw e;
-                    } else {
-                        LOG.warn("Unexpected exception",e);
-                        sock = new Socket();
-                        sock.setSoTimeout(self.tickTime * self.initLimit);
-                    }
                 }
-                Thread.sleep(1000);
             }
-            leaderIs = BinaryInputArchive.getArchive(new BufferedInputStream(
-                    sock.getInputStream()));
-            bufferedOutput = new BufferedOutputStream(sock.getOutputStream());
-            leaderOs = BinaryOutputArchive.getArchive(bufferedOutput);
-            QuorumPacket qp = new QuorumPacket();
-            qp.setType(Leader.LASTZXID);
-            long sentLastZxid = self.getLastLoggedZxid();
-            qp.setZxid(sentLastZxid);
-            writePacket(qp);
-            readPacket(qp);
-            long newLeaderZxid = qp.getZxid();
-
-            if (qp.getType() != Leader.NEWLEADER) {
-                LOG.error("First packet should have been NEWLEADER");
-                throw new IOException("First packet should have been NEWLEADER");
+            if (addr == null) {
+                LOG.warn("Couldn't find the leader with id = "
+                        + current.id);
             }
-            readPacket(qp);
-            synchronized (zk) {
-                if (qp.getType() == Leader.DIFF) {
-                    LOG.info("Getting a diff from the leader!");
-                    zk.loadData();
-                }
-                else if (qp.getType() == Leader.SNAP) {
-                    LOG.info("Getting a snapshot from leader");
-                    // The leader is going to dump the database
-                    zk.deserializeSnapshot(leaderIs);
-                    String signature = leaderIs.readString("signature");
-                    if (!signature.equals("BenWasHere")) {
-                        LOG.error("Missing signature. Got " + signature);
-                        throw new IOException("Missing signature");
-                    }
-                } else if (qp.getType() == Leader.TRUNC) {
-                    //we need to truncate the log to the lastzxid of the leader
-                    LOG.warn("Truncating log to get in sync with the leader 0x"
-                            + Long.toHexString(qp.getZxid()));
-                    boolean truncated=zk.getLogWriter().truncateLog(qp.getZxid());
-                    if (!truncated) {
-                        // not able to truncate the log
-                        LOG.error("Not able to truncate the log "
-                                + Long.toHexString(qp.getZxid()));
-                        System.exit(13);
+            LOG.info("Following " + addr);
+            sock = new Socket();
+            try {
+                QuorumPacket ack = new QuorumPacket(Leader.ACK, 0, null, null);
+                sock.setSoTimeout(self.tickTime * self.initLimit);
+                for (int tries = 0; tries < 5; tries++) {
+                    try {
+                        //sock = new Socket();
+                        //sock.setSoTimeout(self.tickTime * self.initLimit);
+                        sock.connect(addr, self.tickTime * self.syncLimit);
+                        sock.setTcpNoDelay(true);
+                        break;
+                    } catch (ConnectException e) {
+                        if (tries == 4) {
+                            LOG.error("Unexpected exception",e);
+                            throw e;
+                        } else {
+                            LOG.warn("Unexpected exception",e);
+                            sock = new Socket();
+                            sock.setSoTimeout(self.tickTime * self.initLimit);
+                        }
                     }
-
-                    zk.loadData();
+                    Thread.sleep(1000);
                 }
-                else {
-                    LOG.error("Got unexpected packet from leader "
-                            + qp.getType() + " exiting ... " );
-                    System.exit(13);
+                leaderIs = BinaryInputArchive.getArchive(new BufferedInputStream(
+                        sock.getInputStream()));
+                bufferedOutput = new BufferedOutputStream(sock.getOutputStream());
+                leaderOs = BinaryOutputArchive.getArchive(bufferedOutput);
+                QuorumPacket qp = new QuorumPacket();
+                qp.setType(Leader.LASTZXID);
+                long sentLastZxid = self.getLastLoggedZxid();
+                qp.setZxid(sentLastZxid);
+                writePacket(qp);
+                readPacket(qp);
+                long newLeaderZxid = qp.getZxid();
+    
+                if (qp.getType() != Leader.NEWLEADER) {
+                    LOG.error("First packet should have been NEWLEADER");
+                    throw new IOException("First packet should have been NEWLEADER");
                 }
-                zk.dataTree.lastProcessedZxid = newLeaderZxid;
-            }
-            ack.setZxid(newLeaderZxid & ~0xffffffffL);
-            writePacket(ack);
-            sock.setSoTimeout(self.tickTime * self.syncLimit);
-            zk.startup();
-            while (self.running) {
                 readPacket(qp);
-                switch (qp.getType()) {
-                case Leader.PING:
-                    // Send back the ping with our session data
-                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
-                    DataOutputStream dos = new DataOutputStream(bos);
-                    HashMap<Long, Integer> touchTable = zk
-                            .getTouchSnapshot();
-                    for (Entry<Long, Integer> entry : touchTable.entrySet()) {
-                        dos.writeLong(entry.getKey());
-                        dos.writeInt(entry.getValue());
+                synchronized (zk) {
+                    if (qp.getType() == Leader.DIFF) {
+                        LOG.info("Getting a diff from the leader!");
+                        zk.loadData();
                     }
-                    qp.setData(bos.toByteArray());
-                    writePacket(qp);
-                    break;
-                case Leader.PROPOSAL:
-                    TxnHeader hdr = new TxnHeader();
-                    BinaryInputArchive ia = BinaryInputArchive
-                            .getArchive(new ByteArrayInputStream(qp.getData()));
-                    Record txn = SerializeUtils.deserializeTxn(ia, hdr);
-                    if (hdr.getZxid() != lastQueued + 1) {
-                        LOG.warn("Got zxid 0x"
-                                + Long.toHexString(hdr.getZxid())
-                                + " expected 0x"
-                                + Long.toHexString(lastQueued + 1));
+                    else if (qp.getType() == Leader.SNAP) {
+                        LOG.info("Getting a snapshot from leader");
+                        // The leader is going to dump the database
+                        zk.deserializeSnapshot(leaderIs);
+                        String signature = leaderIs.readString("signature");
+                        if (!signature.equals("BenWasHere")) {
+                            LOG.error("Missing signature. Got " + signature);
+                            throw new IOException("Missing signature");
+                        }
+                    } else if (qp.getType() == Leader.TRUNC) {
+                        //we need to truncate the log to the lastzxid of the leader
+                        LOG.warn("Truncating log to get in sync with the leader 0x"
+                                + Long.toHexString(qp.getZxid()));
+                        boolean truncated=zk.getLogWriter().truncateLog(qp.getZxid());
+                        if (!truncated) {
+                            // not able to truncate the log
+                            LOG.error("Not able to truncate the log "
+                                    + Long.toHexString(qp.getZxid()));
+                            System.exit(13);
+                        }
+    
+                        zk.loadData();
                     }
-                    lastQueued = hdr.getZxid();
-                    zk.logRequest(hdr, txn);
-                    break;
-                case Leader.COMMIT:
-                    zk.commit(qp.getZxid());
-                    break;
-                case Leader.UPTODATE:
-                    zk.takeSnapshot();
-                    self.cnxnFactory.setZooKeeperServer(zk);
-                    break;
-                case Leader.REVALIDATE:
-                    ByteArrayInputStream bis = new ByteArrayInputStream(qp
-                            .getData());
-                    DataInputStream dis = new DataInputStream(bis);
-                    long sessionId = dis.readLong();
-                    boolean valid = dis.readBoolean();
-                    synchronized (pendingRevalidations) {
-                        ServerCnxn cnxn = pendingRevalidations
-                                .remove(sessionId);
-                        if (cnxn == null) {
-                            LOG.warn("Missing session 0x"
-                                    + Long.toHexString(sessionId)
-                                    + " for validation");
-                        } else {
-                            cnxn.finishSessionInit(valid);
+                    else {
+                        LOG.error("Got unexpected packet from leader "
+                                + qp.getType() + " exiting ... " );
+                        System.exit(13);
+                    }
+                    zk.dataTree.lastProcessedZxid = newLeaderZxid;
+                }
+                ack.setZxid(newLeaderZxid & ~0xffffffffL);
+                writePacket(ack);
+                sock.setSoTimeout(self.tickTime * self.syncLimit);
+                zk.startup();
+                while (self.running) {
+                    readPacket(qp);
+                    switch (qp.getType()) {
+                    case Leader.PING:
+                        // Send back the ping with our session data
+                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                        DataOutputStream dos = new DataOutputStream(bos);
+                        HashMap<Long, Integer> touchTable = zk
+                                .getTouchSnapshot();
+                        for (Entry<Long, Integer> entry : touchTable.entrySet()) {
+                            dos.writeLong(entry.getKey());
+                            dos.writeInt(entry.getValue());
+                        }
+                        qp.setData(bos.toByteArray());
+                        writePacket(qp);
+                        break;
+                    case Leader.PROPOSAL:
+                        TxnHeader hdr = new TxnHeader();
+                        BinaryInputArchive ia = BinaryInputArchive
+                                .getArchive(new ByteArrayInputStream(qp.getData()));
+                        Record txn = SerializeUtils.deserializeTxn(ia, hdr);
+                        if (hdr.getZxid() != lastQueued + 1) {
+                            LOG.warn("Got zxid 0x"
+                                    + Long.toHexString(hdr.getZxid())
+                                    + " expected 0x"
+                                    + Long.toHexString(lastQueued + 1));
                         }
+                        lastQueued = hdr.getZxid();
+                        zk.logRequest(hdr, txn);
+                        break;
+                    case Leader.COMMIT:
+                        zk.commit(qp.getZxid());
+                        break;
+                    case Leader.UPTODATE:
+                        zk.takeSnapshot();
+                        self.cnxnFactory.setZooKeeperServer(zk);
+                        break;
+                    case Leader.REVALIDATE:
+                        ByteArrayInputStream bis = new ByteArrayInputStream(qp
+                                .getData());
+                        DataInputStream dis = new DataInputStream(bis);
+                        long sessionId = dis.readLong();
+                        boolean valid = dis.readBoolean();
+                        synchronized (pendingRevalidations) {
+                            ServerCnxn cnxn = pendingRevalidations
+                                    .remove(sessionId);
+                            if (cnxn == null) {
+                                LOG.warn("Missing session 0x"
+                                        + Long.toHexString(sessionId)
+                                        + " for validation");
+                            } else {
+                                cnxn.finishSessionInit(valid);
+                            }
+                        }
+                        ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
+                                                 "Session 0x" 
+                                                 + Long.toHexString(sessionId)
+                                                 + " is valid: " + valid);
+                        break;
+                    case Leader.SYNC:
+                        zk.sync();
+                        break;
                     }
-                    ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK,
-                                             "Session 0x" 
-                                             + Long.toHexString(sessionId)
-                                             + " is valid: " + valid);
-                    break;
-                case Leader.SYNC:
-                    zk.sync();
-                    break;
+                }
+            } catch (IOException e) {
+                LOG.warn("Exception when following the leader", e);
+                try {
+                    sock.close();
+                } catch (IOException e1) {
+                    e1.printStackTrace();
+                }
+    
+                synchronized (pendingRevalidations) {
+                    // clear pending revalitions
+                    pendingRevalidations.clear();
+                    pendingRevalidations.notifyAll();
                 }
             }
-        } catch (IOException e) {
-            LOG.warn("Exception when following the leader", e);
-            try {
-                sock.close();
-            } catch (IOException e1) {
-                e1.printStackTrace();
-            }
-
-            synchronized (pendingRevalidations) {
-                // clear pending revalitions
-                pendingRevalidations.clear();
-                pendingRevalidations.notifyAll();
-            }
+        } finally {
+            zk.unregisterJMX(this);
         }
     }
 
     private long lastQueued;
 
-    ConcurrentHashMap<Long, ServerCnxn> pendingRevalidations = new ConcurrentHashMap<Long, ServerCnxn>();
+    final ConcurrentHashMap<Long, ServerCnxn> pendingRevalidations =
+        new ConcurrentHashMap<Long, ServerCnxn>();
+    
+    public int getPendingRevalidationsCount() {
+        return pendingRevalidations.size();
+    }
 
     /**
      * validate a seesion for a client
@@ -362,6 +383,10 @@
         }
         return -1;
     }
+    
+    public long getLastQueued() {
+        return lastQueued;
+    }
 
     public void shutdown() {
         // set the zookeeper server to null

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java Thu Jan 15 14:57:14 2009
@@ -16,13 +16,35 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server.quorum;
+package org.apache.zookeeper.server.quorum;
+
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.ZooKeeperServerBean;
 
 /**
  * Follower MBean inteface implementation
  */
-public class FollowerBean extends ServerBean implements FollowerMXBean {
+public class FollowerBean extends ZooKeeperServerBean implements FollowerMXBean {
+    private final Follower follower;
+
+    public FollowerBean(Follower follower, ZooKeeperServer zks) {
+        super(zks);
+        this.follower = follower;
+    }
+    
     public String getName() {
         return "Follower";
     }
+
+    public String getQuorumAddress() {
+        return follower.sock.toString();
+    }
+    
+    public String getLastQueuedZxid() {
+        return "0x" + Long.toHexString(follower.getLastQueued());
+    }
+    
+    public int getPendingRevalidationCount() {
+        return follower.getPendingRevalidationsCount();
+    }
 }

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerHandler.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerHandler.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerHandler.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerHandler.java Thu Jan 15 14:57:14 2009
@@ -47,16 +47,17 @@
 public class FollowerHandler extends Thread {
     private static final Logger LOG = Logger.getLogger(FollowerHandler.class);
 
-    public Socket sock;
+    public final Socket sock;
 
-    Leader leader;
+    final Leader leader;
 
     long tickOfLastAck;
 
     /**
      * The packets to be sent to the follower
      */
-    LinkedBlockingQueue<QuorumPacket> queuedPackets = new LinkedBlockingQueue<QuorumPacket>();
+    final LinkedBlockingQueue<QuorumPacket> queuedPackets =
+        new LinkedBlockingQueue<QuorumPacket>();
 
     private BinaryInputArchive ia;
 
@@ -71,11 +72,21 @@
         leader.addFollowerHandler(this);
         start();
     }
+    
+    @Override
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("FollowerHandler ").append(sock);
+        sb.append(" tickOfLastAck:").append(tickOfLastAck());
+        sb.append(" synced?:").append(synced());
+        sb.append(" queuedPacketLength:").append(queuedPackets.size());
+        return sb.toString();
+    }
 
     /**
      * If this packet is queued, the sender thread will exit
      */
-    QuorumPacket proposalOfDeath = new QuorumPacket();
+    final QuorumPacket proposalOfDeath = new QuorumPacket();
 
     /**
      * This method will use the thread to send packets added to the

Copied: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java (from r734276, hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerMXBean.java)
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java?p2=hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java&p1=hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerMXBean.java&r1=734276&r2=734847&rev=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/jmx/org/apache/zookeeper/jmx/server/quorum/FollowerMXBean.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java Thu Jan 15 14:57:14 2009
@@ -16,11 +16,26 @@
  * limitations under the License.
  */
 
-package org.apache.zookeeper.jmx.server.quorum;
+package org.apache.zookeeper.server.quorum;
+
+import org.apache.zookeeper.server.ZooKeeperServerMXBean;
 
 /**
  * Follower MBean
  */
-public interface FollowerMXBean extends ServerMXBean {
-
+public interface FollowerMXBean extends ZooKeeperServerMXBean {
+    /**
+     * @return socket address
+     */
+    public String getQuorumAddress();
+    
+    /**
+     * @return last queued zxid
+     */
+    public String getLastQueuedZxid();
+    
+    /**
+     * @return count of pending revalidations
+     */
+    public int getPendingRevalidationCount();
 }

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java?rev=734847&r1=734846&r2=734847&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FollowerZooKeeperServer.java Thu Jan 15 14:57:14 2009
@@ -20,11 +20,13 @@
 
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 
 import org.apache.jute.Record;
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.jmx.MBeanRegistry;
+import org.apache.zookeeper.server.DataTreeBean;
 import org.apache.zookeeper.server.FinalRequestProcessor;
 import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.RequestProcessor;
@@ -174,4 +176,56 @@
             LOG.error("FIXMSG",e);
         }
     }
+
+
+    @Override
+    protected void registerJMX() {
+        // register with JMX
+        try {
+            jmxDataTreeBean = new DataTreeBean(dataTree);
+            MBeanRegistry.getInstance().register(jmxDataTreeBean, jmxServerBean);
+        } catch (Exception e) {
+            LOG.warn("Failed to register with JMX", e);
+        }
+    }
+
+    public void registerJMX(FollowerBean followerBean,
+            LocalPeerBean localPeerBean)
+    {
+        // register with JMX
+        try {
+            MBeanRegistry.getInstance().unregister(self.jmxLeaderElectionBean);
+            self.jmxLeaderElectionBean = null;
+
+            jmxServerBean = followerBean;
+            MBeanRegistry.getInstance().register(followerBean, localPeerBean);
+        } catch (Exception e) {
+            LOG.warn("Failed to register with JMX", e);
+        }
+    }
+
+    @Override
+    protected void unregisterJMX() {
+        // unregister from JMX
+        try {
+            if (jmxDataTreeBean != null) {
+                MBeanRegistry.getInstance().unregister(jmxDataTreeBean);
+            }
+        } catch (Exception e) {
+            LOG.warn("Failed to unregister with JMX", e);
+        }
+        jmxDataTreeBean = null;
+    }
+
+    protected void unregisterJMX(Follower follower) {
+        // unregister from JMX
+        try {
+            if (jmxServerBean != null) {
+                MBeanRegistry.getInstance().unregister(jmxServerBean);
+            }
+        } catch (Exception e) {
+            LOG.warn("Failed to unregister with JMX", e);
+        }
+        jmxServerBean = null;
+    }
 }



Mime
View raw message