Index: src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTClusterTestBase.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTClusterTestBase.java (revision 1005244) +++ src/test/java/org/apache/hadoop/hbase/rest/HBaseRESTClusterTestBase.java (working copy) @@ -88,6 +88,7 @@ if (server != null) try { server.stop(); server = null; + RESTServlet.stop(); } catch (Exception e) { LOG.warn(StringUtils.stringifyException(e)); } Index: src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java (revision 1005244) +++ src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java (working copy) @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; @@ -42,7 +44,7 @@ import org.apache.hadoop.hbase.util.Bytes; public class TestRemoteTable extends HBaseRESTClusterTestBase { - + private static final Log LOG = LogFactory.getLog(HBaseRESTClusterTestBase.class); static final String TABLE = "TestRemoteTable"; static final byte[] ROW_1 = Bytes.toBytes("testrow1"); static final byte[] ROW_2 = Bytes.toBytes("testrow2"); @@ -71,6 +73,7 @@ super.setUp(); admin = new HBaseAdmin(conf); + LOG.info("Admin Connection=" + admin.getConnection() + ", " + admin.getConnection().getZooKeeperWatcher()); if (!admin.tableExists(TABLE)) { HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(COLUMN_1)); @@ -78,6 +81,7 @@ htd.addFamily(new HColumnDescriptor(COLUMN_3)); admin.createTable(htd); HTable table = new HTable(conf, TABLE); + LOG.info("Table connection=" + table.getConnection() + ", " + admin.getConnection().getZooKeeperWatcher()); Put put = new Put(ROW_1); put.add(COLUMN_1, QUALIFIER_1, TS_2, VALUE_1); table.put(put); Index: src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java (revision 1005244) +++ src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java (working copy) @@ -29,6 +29,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.util.Threads; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; @@ -238,9 +239,8 @@ private void connectionEvent(WatchedEvent event) { switch(event.getState()) { case SyncConnected: - // Update our identifier. Otherwise ignore. - this.identifier = this.identifier + "-0x" + - Long.toHexString(this.zooKeeper.getSessionId()); + long sessionid = this.zooKeeper.getSessionId(); + this.identifier = this.identifier + "-0x" + Long.toHexString(sessionid); LOG.info(this.identifier + " connected"); break; @@ -307,7 +307,6 @@ try { if (zooKeeper != null) { zooKeeper.close(); -// super.close(); } } catch (InterruptedException e) { } Index: src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java (revision 1005244) +++ src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java (working copy) @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; @@ -37,25 +36,22 @@ * Singleton class encapsulating global REST servlet state and functions. */ public class RESTServlet implements Constants { - - private static RESTServlet instance; - - Configuration conf; - HTablePool pool; - AtomicBoolean stopping = new AtomicBoolean(false); - Map maxAgeMap = + private static RESTServlet INSTANCE; + private final Configuration conf; + private final HTablePool pool; + private final Map maxAgeMap = Collections.synchronizedMap(new HashMap()); - RESTMetrics metrics = new RESTMetrics(); + private final RESTMetrics metrics = new RESTMetrics(); /** * @return the RESTServlet singleton instance * @throws IOException */ public synchronized static RESTServlet getInstance() throws IOException { - if (instance == null) { - instance = new RESTServlet(); + if (INSTANCE == null) { + INSTANCE = new RESTServlet(); } - return instance; + return INSTANCE; } /** @@ -65,17 +61,21 @@ */ public synchronized static RESTServlet getInstance(Configuration conf) throws IOException { - if (instance == null) { - instance = new RESTServlet(conf); + if (INSTANCE == null) { + INSTANCE = new RESTServlet(conf); } - return instance; + return INSTANCE; } + public synchronized static void stop() { + if (INSTANCE != null) INSTANCE = null; + } + /** * Constructor * @throws IOException */ - public RESTServlet() throws IOException { + RESTServlet() throws IOException { this(HBaseConfiguration.create()); } @@ -84,7 +84,7 @@ * @param conf existing configuration * @throws IOException. */ - public RESTServlet(Configuration conf) throws IOException { + RESTServlet(Configuration conf) throws IOException { this.conf = conf; this.pool = new HTablePool(conf, 10); } @@ -140,4 +140,4 @@ public void invalidateMaxAge(String tableName) { maxAgeMap.remove(tableName); } -} +} \ No newline at end of file Index: src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1005244) +++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -258,7 +258,11 @@ 10); // initialize zookeeper and master address manager - this.zooKeeper = getZooKeeperWatcher(); + try { + this.zooKeeper = new ZooKeeperWatcher(conf, "hconnection", this); + } catch (IOException e) { + throw new ZooKeeperConnectionException(e); + } masterAddressTracker = new MasterAddressTracker(this.zooKeeper, this); zooKeeper.registerListener(masterAddressTracker); masterAddressTracker.start(); @@ -926,16 +930,8 @@ * @returns zookeeper reference * @throws ZooKeeperConnectionException if there's a problem connecting to zk */ - public synchronized ZooKeeperWatcher getZooKeeperWatcher() - throws ZooKeeperConnectionException { - if(zooKeeper == null) { - try { - this.zooKeeper = new ZooKeeperWatcher(conf, "hconnection", this); - } catch (IOException e) { - throw new ZooKeeperConnectionException(e); - } - } - return zooKeeper; + public ZooKeeperWatcher getZooKeeperWatcher() { + return this.zooKeeper; } public T getRegionServerWithRetries(ServerCallable callable)