Return-Path: Delivered-To: apmail-lucene-solr-commits-archive@minotaur.apache.org Received: (qmail 3468 invoked from network); 13 Dec 2009 18:22:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Dec 2009 18:22:45 -0000 Received: (qmail 26438 invoked by uid 500); 13 Dec 2009 18:22:45 -0000 Delivered-To: apmail-lucene-solr-commits-archive@lucene.apache.org Received: (qmail 26359 invoked by uid 500); 13 Dec 2009 18:22:45 -0000 Mailing-List: contact solr-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: solr-dev@lucene.apache.org Delivered-To: mailing list solr-commits@lucene.apache.org Received: (qmail 26350 invoked by uid 99); 13 Dec 2009 18:22:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Dec 2009 18:22:45 +0000 X-ASF-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Dec 2009 18:22:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BE3342388998; Sun, 13 Dec 2009 18:22:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r890086 - in /lucene/solr/branches/cloud/src: java/org/apache/solr/util/ZooPut.java test/org/apache/solr/AbstractZooKeeperTestCase.java Date: Sun, 13 Dec 2009 18:22:22 -0000 To: solr-commits@lucene.apache.org From: markrmiller@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091213182222.BE3342388998@eris.apache.org> 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(); } }