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:22:22 UTC

svn commit: r890086 - in /lucene/solr/branches/cloud/src: java/org/apache/solr/util/ZooPut.java test/org/apache/solr/AbstractZooKeeperTestCase.java

Author: markrmiller
Date: Sun Dec 13 18:22:22 2009
New Revision: 890086

URL: http://svn.apache.org/viewvc?rev=890086&view=rev
Log:
Start exploring a solution for ZooKeeper client async startup

Modified:
    lucene/solr/branches/cloud/src/java/org/apache/solr/util/ZooPut.java
    lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/util/ZooPut.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/util/ZooPut.java?rev=890086&r1=890085&r2=890086&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/util/ZooPut.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/util/ZooPut.java Sun Dec 13 18:22:22 2009
@@ -6,22 +6,39 @@
 
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.Watcher.Event.KeeperState;
 
 /**
  * Util for uploading and updating files in ZooKeeper.
  * 
  */
-public class ZooPut {
+public class ZooPut implements Watcher {
 
   private ZooKeeper keeper;
 
   private boolean closeKeeper = true;
+  
+  private boolean connected = false;
 
   public ZooPut(String host) throws IOException {
-    keeper = new ZooKeeper(host, 10000, null);
-    // TODO: this is asynchronous - think about how to deal with connection lost, and other failures
+    keeper = new ZooKeeper(host, 10000, this);
+    // 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();
+        }
+      }
+    }
   }
 
   public ZooPut(ZooKeeper keeper) throws IOException {
@@ -134,4 +151,16 @@
     zooPut.close();
   }
 
+  @Override
+  public void process(WatchedEvent event) {
+    // nocommit: consider how we want to accomplish this
+    if (event.getState() == KeeperState.SyncConnected) {
+      synchronized (this) {
+        connected = true;
+        this.notify();
+      }
+    }
+
+  }
+
 }

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java?rev=890086&r1=890085&r2=890086&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/AbstractZooKeeperTestCase.java Sun Dec 13 18:22:22 2009
@@ -1,7 +1,6 @@
 package org.apache.solr;
 
 import java.io.File;
-import java.io.IOException;
 
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.util.AbstractSolrTestCase;
@@ -18,7 +17,13 @@
 public abstract class AbstractZooKeeperTestCase extends AbstractSolrTestCase {
   public static final String ZOO_KEEPER_HOST = "localhost:2181/solr";
   protected static Logger log = LoggerFactory.getLogger(AbstractZooKeeperTestCase.class);
-  protected ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
+  
+  class ZKServerMain extends ZooKeeperServerMain {
+	  public void shutdown() {
+		  super.shutdown();
+	  }
+  }
+  protected ZKServerMain zkServer = new ZKServerMain();
 
   protected File tmpDir = new File(System.getProperty("java.io.tmpdir")
       + System.getProperty("file.separator") + getClass().getName() + "-"
@@ -89,12 +94,10 @@
 
   public static void buildZooKeeper(String config, String schema) throws Exception {
     ZooPut zooPut = new ZooPut(ZOO_KEEPER_HOST.substring(0, ZOO_KEEPER_HOST.indexOf('/')));
-    Thread.sleep(200);  // TODO: ZooPut creation is currently async
     zooPut.makePath("/solr");
     zooPut.close();
     
     zooPut = new ZooPut(ZOO_KEEPER_HOST);
-    Thread.sleep(200);  // TODO: ZooPut creation is currently async
     
     zooPut.makePath("/collections/collection1/config=collection1");
     
@@ -113,6 +116,7 @@
   }
 
   public void tearDown() throws Exception {
+	zkServer.shutdown();
     super.tearDown();
   }
 }