You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ma...@apache.org on 2009/12/13 19:33:20 UTC

svn commit: r890090 - /lucene/solr/branches/cloud/src/java/org/apache/solr/core/ZooKeeperController.java

Author: markrmiller
Date: Sun Dec 13 18:33:20 2009
New Revision: 890090

URL: http://svn.apache.org/viewvc?rev=890090&view=rev
Log:
explore how we might handle async ZK client connect in ZooKeeperController - needs thought.

Modified:
    lucene/solr/branches/cloud/src/java/org/apache/solr/core/ZooKeeperController.java

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/core/ZooKeeperController.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/core/ZooKeeperController.java?rev=890090&r1=890089&r2=890090&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/core/ZooKeeperController.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/core/ZooKeeperController.java Sun Dec 13 18:33:20 2009
@@ -16,6 +16,7 @@
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
@@ -34,6 +35,8 @@
   private String configName;
 
   private String collectionName;
+  
+  private boolean connected = false;
 
   /**
    * @param zookeeperHost ZooKeeper host service
@@ -46,9 +49,19 @@
     try {
       keeper = new ZooKeeper(zookeeperHost, 10000, this);
 
-      // TODO
-      log.warn("TODO: remove sleep that waits for zookeeper client");
-      try {Thread.sleep(200);} catch (InterruptedException e) {e.printStackTrace();}
+      // TODO: nocommit: this is asynchronous - think about how to deal with connection
+      // lost, and other failures
+      synchronized (this) {
+        while (!connected) {
+          try {
+            this.wait();
+          } catch (InterruptedException e) {
+            // nocommit
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+          }
+        }
+      }
 
       loadConfigPath();
       register();
@@ -85,6 +98,13 @@
   public void process(WatchedEvent event) {
     // nocommit
     System.out.println("ZooKeeper Event:" + event);
+    // nocommit: consider how we want to accomplish this
+    if (event.getState() == KeeperState.SyncConnected) {
+      synchronized (this) {
+        connected = true;
+        this.notify();
+      }
+    }
   }
 
   private void loadConfigPath() {