incubator-accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1188619 - /incubator/accumulo/trunk/src/trace/src/main/java/cloudtrace/instrument/receivers/ZooSpanClient.java
Date Tue, 25 Oct 2011 11:56:30 GMT
Author: ecn
Date: Tue Oct 25 11:56:30 2011
New Revision: 1188619

URL: http://svn.apache.org/viewvc?rev=1188619&view=rev
Log:
ACCUMULO-66: defend against NPE due to "this" escaping the constructor; inline callback 

Modified:
    incubator/accumulo/trunk/src/trace/src/main/java/cloudtrace/instrument/receivers/ZooSpanClient.java

Modified: incubator/accumulo/trunk/src/trace/src/main/java/cloudtrace/instrument/receivers/ZooSpanClient.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/trace/src/main/java/cloudtrace/instrument/receivers/ZooSpanClient.java?rev=1188619&r1=1188618&r2=1188619&view=diff
==============================================================================
--- incubator/accumulo/trunk/src/trace/src/main/java/cloudtrace/instrument/receivers/ZooSpanClient.java
(original)
+++ incubator/accumulo/trunk/src/trace/src/main/java/cloudtrace/instrument/receivers/ZooSpanClient.java
Tue Oct 25 11:56:30 2011
@@ -26,6 +26,7 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper.States;
 
@@ -33,21 +34,32 @@ import org.apache.zookeeper.ZooKeeper.St
  * Find a Span collector via zookeeper and push spans there via Thrift RPC
  * 
  */
-public class ZooSpanClient extends SendSpansViaThrift implements Watcher {
+public class ZooSpanClient extends SendSpansViaThrift {
   
   private static final Logger log = Logger.getLogger(ZooSpanClient.class);
   private static final int TOTAL_TIME_WAIT_CONNECT_MS = 10 * 1000;
   private static final int TIME_WAIT_CONNECT_CHECK_MS = 100;
   
-  final ZooKeeper zoo;
+  ZooKeeper zoo = null;
   final String path;
   final Random random = new Random();
   final List<String> hosts = new ArrayList<String>();
   
-  public ZooSpanClient(String keepers, String path, String host, String service, long millis)
throws IOException, KeeperException, InterruptedException {
+  public ZooSpanClient(String keepers, final String path, String host, String service, long
millis) throws IOException, KeeperException, InterruptedException {
     super(host, service, millis);
     this.path = path;
-    zoo = new ZooKeeper(keepers, 30 * 1000, this);
+    zoo = new ZooKeeper(keepers, 30 * 1000, new Watcher() {
+      @Override
+      public void process(WatchedEvent event) {
+        try {
+          if (zoo != null) {
+            updateHosts(path, zoo.getChildren(path, null));
+          }
+        } catch (Exception ex) {
+          log.error("unable to get destination hosts in zookeeper", ex);
+        }
+      }
+    });
     for (int i = 0; i < TOTAL_TIME_WAIT_CONNECT_MS; i += TIME_WAIT_CONNECT_CHECK_MS) {
       if (zoo.getState().equals(States.CONNECTED)) break;
       try {
@@ -84,13 +96,4 @@ public class ZooSpanClient extends SendS
     }
     return null;
   }
-  
-  @Override
-  public void process(WatchedEvent event) {
-    try {
-      updateHosts(path, zoo.getChildren(path, null));
-    } catch (Exception ex) {
-      log.error("unable to get destination hosts in zookeeper", ex);
-    }
-  }
 }



Mime
View raw message