ACCUMULO-1984 Rework interruption for instance implementations.

This change removes the throwing of InterruptedException from several
classes, simplifying the API. Some of the affected classes now also
implement java.io.Closeable.

Signed-off-by: Eric Newton <eric.new...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/0d0bc464
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/0d0bc464
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/0d0bc464

Branch: refs/heads/1.4.5-SNAPSHOT
Commit: 0d0bc4643a8680593e2cf5f828b7566c30fcb345
Parents: cc68925
Author: Bill Havanki <bhava...@cloudera.com>
Authored: Wed Dec 11 13:06:47 2013 -0500
Committer: Eric Newton <eric.new...@gmail.com>
Committed: Thu Dec 12 11:23:52 2013 -0500

----------------------------------------------------------------------
 .../org/apache/accumulo/core/client/Instance.java    |  7 ++++---
 .../accumulo/core/client/ZooKeeperInstance.java      |  6 +++---
 .../accumulo/core/client/mock/MockInstance.java      |  2 +-
 .../org/apache/accumulo/core/zookeeper/ZooCache.java |  6 ++++--
 .../apache/accumulo/core/zookeeper/ZooReader.java    | 15 ++++++++++++---
 .../core/client/impl/TabletLocatorImplTest.java      |  2 +-
 .../accumulo/server/client/HdfsZooInstance.java      |  8 ++------
 7 files changed, 27 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/core/src/main/java/org/apache/accumulo/core/client/Instance.java
----------------------------------------------------------------------
diff --git 
a/src/core/src/main/java/org/apache/accumulo/core/client/Instance.java 
b/src/core/src/main/java/org/apache/accumulo/core/client/Instance.java
index 1820e7a..3b2af18 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/client/Instance.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/client/Instance.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.core.client;
 
+import java.io.Closeable;
 import java.nio.ByteBuffer;
 import java.util.List;
 
@@ -26,7 +27,7 @@ import org.apache.accumulo.core.security.thrift.AuthInfo;
  * This class represents the information a client needs to know to connect to 
an instance of accumulo.
  * 
  */
-public interface Instance {
+public interface Instance extends Closeable {
   /**
    * Returns the location of the tablet server that is serving the root tablet.
    * 
@@ -130,9 +131,9 @@ public interface Instance {
   /**
    * Closes up the instance to free up all associated resources. You should 
try to reuse an Instance as much as you can because there is some location 
caching
    * stored which will enhance performance.
-   * @throws AccumuloException 
    */
-  public abstract void close() throws AccumuloException;
+  @Override
+  public abstract void close();
   
   /**
    * Returns the AccumuloConfiguration to use when interacting with this 
instance.

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
----------------------------------------------------------------------
diff --git 
a/src/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java 
b/src/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
index fcf8f55..4cd4972 100644
--- 
a/src/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
+++ 
b/src/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
@@ -303,14 +303,14 @@ public class ZooKeeperInstance implements Instance {
   static private final AtomicInteger clientInstances = new AtomicInteger(0);
 
   @Override
-  public synchronized void close() throws AccumuloException {
+  public synchronized void close() {
     if (!closed && clientInstances.decrementAndGet() == 0) {
       try {
         zooCache.close();
         ThriftUtil.close();
-      } catch (InterruptedException e) {
+      } catch (RuntimeException e) {
         clientInstances.incrementAndGet();
-        throw new AccumuloException("Issues closing ZooKeeper.");
+        throw e;
       }
     }
     closed = true;

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
----------------------------------------------------------------------
diff --git 
a/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java 
b/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
index d8a15e0..b9778a7 100644
--- 
a/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
+++ 
b/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
@@ -142,7 +142,7 @@ public class MockInstance implements Instance {
   }
 
   @Override
-  public void close() throws AccumuloException {
+  public void close() {
     // NOOP
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
----------------------------------------------------------------------
diff --git 
a/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java 
b/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
index 0a36923..1d55f6c 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooCache.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.core.zookeeper;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -40,7 +41,7 @@ import org.apache.zookeeper.data.Stat;
  * Caches values stored in zookeeper and keeps them up to date as they change 
in zookeeper.
  * 
  */
-public class ZooCache {
+public class ZooCache implements Closeable {
   private static final Logger log = Logger.getLogger(ZooCache.class);
   
   private ZCacheWatcher watcher = new ZCacheWatcher();
@@ -308,7 +309,8 @@ public class ZooCache {
     return zc;
   }
   
-  public void close() throws InterruptedException {
+  @Override
+  public void close() {
     cache.clear();
     statCache.clear();
     childrenCache.clear();

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooReader.java
----------------------------------------------------------------------
diff --git 
a/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooReader.java 
b/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooReader.java
index 1bcd22b..ab02034 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooReader.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/zookeeper/ZooReader.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.core.zookeeper;
 
+import java.io.Closeable;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -28,7 +29,7 @@ import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.data.Stat;
 
-public class ZooReader implements IZooReader {
+public class ZooReader implements IZooReader, Closeable {
   
   protected String keepers;
   protected int timeout;
@@ -108,7 +109,15 @@ public class ZooReader implements IZooReader {
     this(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
   }
 
-  public void close() throws InterruptedException {
-    getZooKeeper().close();
+  /**
+   * Closes this reader. If closure of the underlying session is interrupted,
+   * this method sets the calling thread's interrupt status.
+   */
+  public void close() {
+    try {
+      getZooKeeper().close();
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
----------------------------------------------------------------------
diff --git 
a/src/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
 
b/src/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
index 624a824..e0ae60e 100644
--- 
a/src/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
+++ 
b/src/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
@@ -450,7 +450,7 @@ public class TabletLocatorImplTest extends TestCase {
     }
     
     @Override
-    public void close() throws AccumuloException {
+    public void close() {
       // NOOP
     }
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/0d0bc464/src/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
----------------------------------------------------------------------
diff --git 
a/src/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
 
b/src/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
index d68449d..2dd1db6 100644
--- 
a/src/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
+++ 
b/src/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
@@ -179,12 +179,8 @@ public class HdfsZooInstance implements Instance {
   }
 
   @Override
-  public void close() throws AccumuloException {
-    try {
-      zooCache.close();
-    } catch (InterruptedException e) {
-      throw new AccumuloException("Issues closing ZooKeeper, try again");
-    }
+  public void close() {
+    zooCache.close();
   }
   
   @Override

Reply via email to