You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2015/05/12 17:53:48 UTC

[01/26] curator git commit: [CURATOR-160] Add builders and dsl for ZooKeeper's config and reconfig methods.

Repository: curator
Updated Branches:
  refs/heads/CURATOR-215 54142668e -> f76971769


[CURATOR-160] Add builders and dsl for ZooKeeper's config and reconfig methods.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/2c576dc3
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/2c576dc3
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/2c576dc3

Branch: refs/heads/CURATOR-215
Commit: 2c576dc344a167ad4a72d71412c98d76ff4e2d3d
Parents: d4883a8
Author: Ioannis Canellos <io...@gmail.com>
Authored: Thu Nov 6 17:34:47 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Thu Nov 6 17:34:47 2014 +0200

----------------------------------------------------------------------
 .../curator/framework/CuratorFramework.java     |  12 +
 .../framework/api/AsyncReconfigurable.java      |  29 ++
 .../curator/framework/api/DataCallbackable.java |  32 ++
 .../curator/framework/api/GetConfigBuilder.java |  27 ++
 .../api/IncrementalReconfigBuilder.java         |  33 ++
 .../apache/curator/framework/api/Joinable.java  |  40 +++
 .../apache/curator/framework/api/Leaveable.java |  38 +++
 .../curator/framework/api/Memberable.java       |  40 +++
 .../api/NonIncrementalReconfigBuilder.java      |  32 ++
 .../curator/framework/api/ReconfigBuilder.java  |  26 ++
 .../framework/api/SyncReconfigurable.java       |  30 ++
 .../framework/imps/CuratorFrameworkImpl.java    |  10 +
 .../framework/imps/GetConfigBuilderImpl.java    |  80 +++++
 .../framework/imps/ReconfigBuilderImpl.java     | 182 +++++++++++
 .../framework/imps/TestReconfiguration.java     | 303 +++++++++++++++++++
 15 files changed, 914 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
index 9c23ddb..181e4e8 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
@@ -122,6 +122,18 @@ public interface CuratorFramework extends Closeable
     public SetACLBuilder setACL();
 
     /**
+     * Start a reconfig builder
+     * @return builder object
+     */
+    public ReconfigBuilder reconfig();
+
+    /**
+     * Start a getConfig builder
+     * @return
+     */
+    public GetConfigBuilder getConfig();
+
+    /**
      * Start a transaction builder
      *
      * @return builder object

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/AsyncReconfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/AsyncReconfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/AsyncReconfigurable.java
new file mode 100644
index 0000000..fc7fd57
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/AsyncReconfigurable.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface AsyncReconfigurable  {
+
+    /**
+     * Sets the configuration version to use.
+     * @param config The version of the configuration.
+     * @throws Exception
+     */
+    void fromConfig(long config) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/DataCallbackable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/DataCallbackable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/DataCallbackable.java
new file mode 100644
index 0000000..75ded65
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/DataCallbackable.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+import org.apache.zookeeper.AsyncCallback.DataCallback;
+
+public interface DataCallbackable<T> {
+
+    /**
+     * Passes a callback and a context object to the config/reconfig command.
+     * @param callback  The async callback to use.
+     * @param ctx       An object that will be passed to the callback.
+     * @return this
+     */
+    T usingDataCallback(DataCallback callback, Object ctx);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
new file mode 100644
index 0000000..c7c013b
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface GetConfigBuilder extends
+        Watchable<GetConfigBuilder>,
+        DataCallbackable<Void>,
+        Statable<byte[]> {
+}
+
+

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/IncrementalReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/IncrementalReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/IncrementalReconfigBuilder.java
new file mode 100644
index 0000000..0ad6426
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/IncrementalReconfigBuilder.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods join and leave, so that we prevent
+ * mixing concepts that can't be used together.
+ * @param <T>
+ */
+public interface IncrementalReconfigBuilder<T> extends
+        Joinable<IncrementalReconfigBuilder<T>>,
+        Leaveable<IncrementalReconfigBuilder<T>>,
+        DataCallbackable<AsyncReconfigurable>,
+        Statable<SyncReconfigurable> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
new file mode 100644
index 0000000..ff1b3c5
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+import java.util.Collection;
+
+public interface Joinable<T> {
+
+    /**
+     * Adds a server to join the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param server The server to join.
+     * @return this.
+     */
+    T join(String server);
+
+    /**
+     * Adds a collection of servers to the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param servers The collection of servers to join
+     * @return this
+     */
+    T join(Collection<String> servers);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
new file mode 100644
index 0000000..8560d65
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+import java.util.Collection;
+
+public interface Leaveable<T> {
+
+    /**
+     * Sets a server to leave the ensemble.
+     * @param server The server id.
+     * @return this
+     */
+    T leave(String server);
+
+    /**
+     * Sets a collection of servers to leave the ensemble.
+     * @param servers The collection of server ids.
+     * @return this.
+     */
+    T leave(Collection<String> servers);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
new file mode 100644
index 0000000..5b62dba
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+import java.util.Collection;
+
+public interface Memberable<T> {
+
+    /**
+     * Sets a member that is meant to be part of the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param server The server to add as a member of the ensemble.
+     * @return this.
+     */
+    T withMember(String server);
+
+    /**
+     * Sets a collection of members member that is meant to be part of the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param servers The collection of server to set as a members of the ensemble.
+     * @return this.
+     */
+    T withMembers(Collection<String> servers);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java
new file mode 100644
index 0000000..2f6a9c6
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An non-incremental reconfiguration builder.
+ * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
+ * mixing concepts that can't be used together.
+ * @param <T>
+ */
+public interface NonIncrementalReconfigBuilder<T> extends
+        Memberable<NonIncrementalReconfigBuilder<T>>,
+        DataCallbackable<AsyncReconfigurable>,
+        Statable<SyncReconfigurable> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
new file mode 100644
index 0000000..0e420a1
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface ReconfigBuilder extends
+        Joinable<IncrementalReconfigBuilder<byte[]>>,
+        Leaveable<IncrementalReconfigBuilder<byte[]>>,
+        Memberable<NonIncrementalReconfigBuilder<byte[]>> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/api/SyncReconfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/SyncReconfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/SyncReconfigurable.java
new file mode 100644
index 0000000..bd7b96b
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/SyncReconfigurable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface SyncReconfigurable  {
+
+    /**
+     * Sets the configuration version to use.
+     * @param config    The version of the configuration.
+     * @return The configuration data.
+     * @throws Exception
+     */
+    byte[] fromConfig(long config) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index cf38e21..53f0a61 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -413,6 +413,16 @@ public class CuratorFrameworkImpl implements CuratorFramework
     }
 
     @Override
+    public ReconfigBuilder reconfig() {
+        return new ReconfigBuilderImpl(this);
+    }
+
+    @Override
+    public GetConfigBuilder getConfig() {
+        return new GetConfigBuilderImpl(this);
+    }
+
+    @Override
     public CuratorTransaction inTransaction()
     {
         Preconditions.checkState(getState() == CuratorFrameworkState.STARTED, "instance must be started before calling this method");

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
new file mode 100644
index 0000000..a56894d
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.api.GetConfigBuilder;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.data.Stat;
+
+public class GetConfigBuilderImpl implements GetConfigBuilder {
+
+    private final CuratorFrameworkImpl client;
+    private boolean watched;
+    private Watcher watcher;
+
+    public GetConfigBuilderImpl(CuratorFrameworkImpl client) {
+        this.client = client;
+    }
+
+    @Override
+    public Void usingDataCallback(AsyncCallback.DataCallback callback, Object ctx) {
+        try {
+            if (watcher != null) {
+                client.getZooKeeper().getConfig(watcher, callback, ctx);
+            } else {
+                client.getZooKeeper().getConfig(watched, callback, ctx);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public byte[] storingStatIn(Stat stat) {
+        try {
+            if (watcher != null) {
+               return client.getZooKeeper().getConfig(watcher, stat);
+            } else {
+                return client.getZooKeeper().getConfig(watched, stat);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public GetConfigBuilder watched() {
+        this.watched = true;
+        return this;
+    }
+
+    @Override
+    public GetConfigBuilder usingWatcher(Watcher watcher) {
+        this.watcher = watcher;
+        return null;
+    }
+
+    @Override
+    public GetConfigBuilder usingWatcher(final CuratorWatcher watcher) {
+        throw new UnsupportedOperationException("GetConfigBuilder doesn't support CuratorWatcher, please use Watcher instead.");
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
new file mode 100644
index 0000000..7b39be6
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -0,0 +1,182 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.framework.api.AsyncReconfigurable;
+import org.apache.curator.framework.api.IncrementalReconfigBuilder;
+import org.apache.curator.framework.api.NonIncrementalReconfigBuilder;
+import org.apache.curator.framework.api.ReconfigBuilder;
+import org.apache.curator.framework.api.SyncReconfigurable;
+import org.apache.zookeeper.AsyncCallback.DataCallback;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+public class ReconfigBuilderImpl implements ReconfigBuilder {
+
+    private final CuratorFrameworkImpl client;
+
+    private static class IncrementalReconfigBuilderImpl<T> implements IncrementalReconfigBuilder<T> {
+
+        private final CuratorFrameworkImpl client;
+        private List<String> joiningServers = new LinkedList<String>();
+        private List<String> leavingServers = new LinkedList<String>();
+
+        private IncrementalReconfigBuilderImpl(CuratorFrameworkImpl client) {
+            this.client = client;
+        }
+
+        @Override
+        public IncrementalReconfigBuilderImpl<T> join(String server) {
+            joiningServers.add(server);
+            return this;
+        }
+
+        @Override
+        public IncrementalReconfigBuilder<T> join(Collection<String> servers) {
+            joiningServers.addAll(servers);
+            return this;
+        }
+
+        @Override
+        public IncrementalReconfigBuilderImpl<T> leave(String server) {
+            leavingServers.add(server);
+            return this;
+        }
+
+        @Override
+        public IncrementalReconfigBuilder<T> leave(Collection<String> servers) {
+            leavingServers.addAll(servers);
+            return this;
+        }
+
+        @Override
+        public SyncReconfigurable storingStatIn(final Stat stat) {
+            return new SyncReconfigurable() {
+                @Override
+                public byte[] fromConfig(long config) throws Exception {
+                    return client
+                            .getZooKeeper()
+                            .reconfig(joiningServers.isEmpty() ? null : joiningServers,
+                                      leavingServers.isEmpty() ? null : leavingServers,
+                                      null,
+                                      config, stat);
+                }
+            };
+        }
+
+        @Override
+        public AsyncReconfigurable usingDataCallback(final DataCallback callback, final Object ctx) {
+            return new AsyncReconfigurable() {
+                @Override
+                public void fromConfig(long config) throws Exception {
+                     client.getZooKeeper()
+                           .reconfig(joiningServers.isEmpty() ? null : joiningServers,
+                                     leavingServers.isEmpty() ? null : leavingServers,
+                                     null,
+                                     config, callback, ctx);
+                }
+            };
+        }
+    }
+
+    private static class NonIncrementalReconfigBuilderImpl<T> implements NonIncrementalReconfigBuilder<T> {
+
+        private final CuratorFrameworkImpl client;
+        private List<String> newMembers = new LinkedList<String>();
+
+        private NonIncrementalReconfigBuilderImpl(CuratorFrameworkImpl client) {
+            this.client = client;
+        }
+
+        private NonIncrementalReconfigBuilderImpl(CuratorFrameworkImpl client, List<String> newMembers) {
+            this.client = client;
+            this.newMembers = newMembers;
+        }
+
+        @Override
+        public NonIncrementalReconfigBuilder<T> withMember(String server) {
+            newMembers.add(server);
+            return this;
+        }
+
+        @Override
+        public NonIncrementalReconfigBuilder<T> withMembers(Collection servers) {
+            newMembers.addAll(servers);
+            return this;
+        }
+
+        @Override
+        public SyncReconfigurable storingStatIn(final Stat stat) {
+            return new SyncReconfigurable() {
+                @Override
+                public byte[] fromConfig(long config) throws Exception {
+                    return client.getZooKeeper().reconfig(null, null, newMembers, config, stat);
+                }
+            };
+        }
+
+        @Override
+        public AsyncReconfigurable usingDataCallback(final DataCallback callback, final Object ctx) {
+            return new AsyncReconfigurable() {
+                @Override
+                public void fromConfig(long config) throws Exception {
+                    client.getZooKeeper().reconfig(null, null, newMembers, config, callback, ctx);
+                }
+            };
+        }
+    }
+
+
+    public ReconfigBuilderImpl(CuratorFrameworkImpl client) {
+        this.client = client;
+    }
+
+    @Override
+    public IncrementalReconfigBuilder<byte[]> join(String server) {
+        return new IncrementalReconfigBuilderImpl(client).join(server);
+    }
+
+    @Override
+    public IncrementalReconfigBuilder<byte[]> join(Collection<String> servers) {
+        return new IncrementalReconfigBuilderImpl(client).join(servers);
+    }
+
+    @Override
+    public IncrementalReconfigBuilder<byte[]> leave(String server) {
+        return new IncrementalReconfigBuilderImpl(client).leave(server);
+    }
+
+    @Override
+    public IncrementalReconfigBuilder<byte[]> leave(Collection<String> servers) {
+        return new IncrementalReconfigBuilderImpl(client).leave(servers);
+    }
+
+    @Override
+    public NonIncrementalReconfigBuilder<byte[]> withMember(String server) {
+        return new NonIncrementalReconfigBuilderImpl(client).withMember(server);
+    }
+
+    @Override
+    public NonIncrementalReconfigBuilder<byte[]> withMembers(Collection<String> servers) {
+        return new NonIncrementalReconfigBuilderImpl<byte[]>(client).withMembers(servers);
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/2c576dc3/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
new file mode 100644
index 0000000..6918825
--- /dev/null
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -0,0 +1,303 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.InstanceSpec;
+import org.apache.curator.test.TestingCluster;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class TestReconfiguration {
+
+    static TestingCluster cluster;
+
+    @BeforeClass
+    public void setup() throws Exception {
+        cluster = new TestingCluster(5);
+        cluster.start();
+    }
+
+    @AfterClass
+    public void tearDown() throws IOException {
+        cluster.close();
+    }
+
+    @Test
+    public void testSyncIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            Stat stat = new Stat();
+            byte[] bytes = client.getConfig().storingStatIn(stat);
+            Assert.assertNotNull(bytes);
+            QuorumVerifier qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(5, qv.getAllMembers().size());
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+
+            //Remove Servers
+            bytes = client.reconfig().leave("1").storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            bytes = client.reconfig().leave("2").storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(3, qv.getAllMembers().size());
+
+            //Add Servers
+            bytes = client.reconfig().join("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            bytes = client.reconfig().join("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(5, qv.getAllMembers().size());
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testAsyncIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+            final AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() {
+                @Override
+                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+                    bytes.set(data);
+                    ((CountDownLatch)ctx).countDown();
+                }
+            };
+
+            CountDownLatch latch = new CountDownLatch(1);
+            client.getConfig().usingDataCallback(callback, latch);
+            latch.await(5, TimeUnit.SECONDS);
+            Assert.assertNotNull(bytes.get());
+            QuorumVerifier qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(5, qv.getAllMembers().size());
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+
+
+            //Remove Servers
+            latch = new CountDownLatch(1);
+            client.reconfig().leave("1").usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            latch = new CountDownLatch(1);
+            client.reconfig().leave("2").usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(3, qv.getAllMembers().size());
+
+            //Add Servers
+            latch = new CountDownLatch(1);
+            client.reconfig().join("server.1=" + server1).usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            latch = new CountDownLatch(1);
+            client.reconfig().join("server.2=" + server2).usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(5, qv.getAllMembers().size());
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testSyncNonIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            Stat stat = new Stat();
+            byte[] bytes = client.getConfig().storingStatIn(stat);
+            Assert.assertNotNull(bytes);
+            QuorumVerifier qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(5, qv.getAllMembers().size());
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+            String server3 = getServerString(qv, cluster, 3L);
+            String server4 = getServerString(qv, cluster, 4L);
+            String server5 = getServerString(qv, cluster, 5L);
+
+            //Remove Servers
+            bytes = client.reconfig()
+                    .withMember("server.2="+server2)
+                    .withMember("server.3="+server3)
+                    .withMember("server.4="+server4)
+                    .withMember("server.5="+server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            bytes = client.reconfig()
+                    .withMember("server.3=" + server3)
+                    .withMember("server.4=" + server4)
+                    .withMember("server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion());
+
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(3, qv.getAllMembers().size());
+
+            //Add Servers
+            bytes = client.reconfig()
+                    .withMember("server.1="+server1)
+                    .withMember("server.3=" + server3)
+                    .withMember("server.4="+server4)
+                    .withMember("server.5="+server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            bytes = client.reconfig()
+                    .withMember("server.1="+server1)
+                    .withMember("server.2="+server2)
+                    .withMember("server.3=" + server3)
+                    .withMember("server.4="+server4)
+                    .withMember("server.5="+server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion());
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(5, qv.getAllMembers().size());
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testAsyncNonIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+            final AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() {
+                @Override
+                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+                    bytes.set(data);
+                    ((CountDownLatch)ctx).countDown();
+                }
+            };
+
+            CountDownLatch latch = new CountDownLatch(1);
+            client.getConfig().usingDataCallback(callback, latch);
+            latch.await(5, TimeUnit.SECONDS);
+            Assert.assertNotNull(bytes.get());
+            QuorumVerifier qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(5, qv.getAllMembers().size());
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+            String server3 = getServerString(qv, cluster, 3L);
+            String server4 = getServerString(qv, cluster, 4L);
+            String server5 = getServerString(qv, cluster, 5L);
+
+
+            //Remove Servers
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMember("server.2=" + server2)
+                    .withMember("server.3="+server3)
+                    .withMember("server.4="+server4)
+                    .withMember("server.5="+server5)
+            .usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMember("server.3="+server3)
+                    .withMember("server.4=" + server4)
+                    .withMember("server.5=" + server5)
+                    .usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(3, qv.getAllMembers().size());
+
+            //Add Servers
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMember("server.1="+server1)
+                    .withMember("server.3=" + server3)
+                    .withMember("server.4=" + server4)
+                    .withMember("server.5=" + server5)
+                    .usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(4, qv.getAllMembers().size());
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMember("server.1="+server1)
+                    .withMember("server.2="+server2)
+                    .withMember("server.3="+server3)
+                    .withMember("server.4=" + server4)
+                    .withMember("server.5=" + server5)
+                    .usingDataCallback(callback, latch).fromConfig(qv.getVersion());
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(5, qv.getAllMembers().size());
+        } finally {
+            client.close();
+        }
+    }
+
+
+    static QuorumVerifier getQuorumVerifier(byte[] bytes) throws Exception {
+        Properties properties = new Properties();
+        properties.load(new StringReader(new String(bytes)));
+        return new QuorumMaj(properties);
+    }
+
+    static InstanceSpec getInstance(TestingCluster cluster, int id) {
+        for (InstanceSpec spec : cluster.getInstances()) {
+            if (spec.getServerId() == id) {
+                return spec;
+            }
+        }
+        throw new IllegalStateException("InstanceSpec with id:" + id + " not found");
+    }
+
+    static String getServerString(QuorumVerifier qv, TestingCluster cluster, long id) throws Exception {
+        String str = qv.getAllMembers().get(id).toString();
+        //check if connection string is already there.
+        if (str.contains(";")) {
+            return str;
+        } else {
+            return str + ";" + getInstance(cluster, (int) id).getConnectString();
+        }
+    }
+}
\ No newline at end of file


[18/26] curator git commit: Reworked the reconfig() APIs to be more like the rest of Curator

Posted by ra...@apache.org.
Reworked the reconfig() APIs to be more like the rest of Curator


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

Branch: refs/heads/CURATOR-215
Commit: aaa048727f955058f5ecb1f222dbfb60bbd0e794
Parents: d183d02
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 09:13:53 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 09:13:53 2015 -0500

----------------------------------------------------------------------
 .../curator/framework/CuratorFramework.java     |   4 +-
 .../api/AddStatConfigEnsembleable.java          |  32 +
 .../apache/curator/framework/api/Addable.java   |  43 ++
 .../api/BackgroundStatConfigEnsembleable.java   |  24 -
 .../api/BackgroundStatConfigurable.java         |  24 -
 .../api/BackgroundStatEnsembleable.java         |  24 -
 .../curator/framework/api/Configurable.java     |   6 +-
 .../api/JoinAddStatConfigEnsembleable.java      |  33 ++
 .../JoinBackgroundStatConfigEnsembleable.java   |  30 -
 .../api/JoinBackgroundStatConfigurable.java     |  30 -
 .../api/JoinLeaveStatConfigEnsembleable.java    |  33 ++
 .../api/JoinStatConfigEnsembleable.java         |  32 +
 .../framework/api/JoinStatConfigurable.java     |  30 +
 .../apache/curator/framework/api/Joinable.java  |  18 +-
 .../api/LeaveAddStatConfigEnsembleable.java     |  32 +
 .../LeaveBackgroundStatConfigEnsembleable.java  |  30 -
 .../api/LeaveBackgroundStatConfigurable.java    |  30 -
 .../api/LeaveStatConfigEnsembleable.java        |  32 +
 .../apache/curator/framework/api/Leaveable.java |  15 +-
 .../curator/framework/api/Memberable.java       |  31 -
 .../api/NonIncrementalReconfigBuilder.java      |  32 -
 .../curator/framework/api/ReconfigBuilder.java  |  10 +-
 .../framework/api/ReconfigBuilderMain.java      |  27 +
 .../framework/api/StatConfigEnsembleable.java   |  26 +
 .../curator/framework/api/StatEnsembleable.java |  26 +
 .../framework/imps/CreateBuilderImpl.java       |   3 +-
 .../framework/imps/CuratorFrameworkImpl.java    |   6 +-
 .../imps/EnsembleServersAndConfig.java          |  52 --
 .../curator/framework/imps/EnsembleTracker.java | 115 ++--
 .../framework/imps/ReconfigBuilderImpl.java     | 582 ++++++++++++++-----
 .../framework/imps/TestReconfiguration.java     | 240 ++++----
 31 files changed, 1034 insertions(+), 618 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
index 181e4e8..7de49ce 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
@@ -123,13 +123,15 @@ public interface CuratorFramework extends Closeable
 
     /**
      * Start a reconfig builder
+     *
      * @return builder object
      */
     public ReconfigBuilder reconfig();
 
     /**
      * Start a getConfig builder
-     * @return
+     *
+     * @return builder object
      */
     public GetConfigBuilder getConfig();
 

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/AddStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/AddStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/AddStatConfigEnsembleable.java
new file mode 100644
index 0000000..16f78a2
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/AddStatConfigEnsembleable.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An non-incremental reconfiguration builder.
+ * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface AddStatConfigEnsembleable extends
+    Addable<StatConfigEnsembleable>,
+    StatConfigEnsembleable
+{
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/Addable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Addable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Addable.java
new file mode 100644
index 0000000..e908f1e
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Addable.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+import java.util.List;
+
+public interface Addable<T>
+{
+    /**
+     * Sets one or more members that are meant to be part of the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     *
+     * @param server The server to add as a member of the ensemble.
+     * @return this
+     */
+    T adding(String... server);
+
+    /**
+     * Sets one or more members that are meant to be part of the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     *
+     * @param servers The server to add as a member of the ensemble.
+     * @return this
+     */
+    T adding(List<String> servers);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java
deleted file mode 100644
index f109b0f..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-public interface BackgroundStatConfigEnsembleable<T> extends
-        Configurable<BackgroundStatEnsembleable<T>>,
-        BackgroundStatEnsembleable<T> {
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
deleted file mode 100644
index e46ba89..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-public interface BackgroundStatConfigurable<T> extends
-    BackgroundStatable<Configurable<T>>,
-    Configurable<T> {
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java
deleted file mode 100644
index 62f666d..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-public interface BackgroundStatEnsembleable<T> extends
-    BackgroundStatable<Ensembleable<T>>,
-    Ensembleable<T> {
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
index 39e2c0c..2bc0494 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
@@ -16,14 +16,16 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.api;
 
-public interface Configurable<T> {
+public interface Configurable
+{
 
     /**
      * Sets the configuration version to use.
      * @param config The version of the configuration.
      * @throws Exception
      */
-    BackgroundStatEnsembleable<byte[]> fromConfig(long config) throws Exception;
+    StatEnsembleable<byte[]> fromConfig(long config) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/JoinAddStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinAddStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinAddStatConfigEnsembleable.java
new file mode 100644
index 0000000..a905dd1
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinAddStatConfigEnsembleable.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinAddStatConfigEnsembleable extends
+    Joinable<AddStatConfigEnsembleable>,
+    Addable<JoinStatConfigurable>,
+    StatConfigEnsembleable
+{
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java
deleted file mode 100644
index ba45efd..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An incremental reconfiguration builder.
- * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
- * mixing concepts that can't be used together.
- */
-public interface JoinBackgroundStatConfigEnsembleable extends
-        Joinable<BackgroundStatConfigEnsembleable<byte[]>>,
-        BackgroundStatConfigEnsembleable<byte[]> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
deleted file mode 100644
index fb18c0c..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An incremental reconfiguration builder.
- * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
- * mixing concepts that can't be used together.
- */
-public interface JoinBackgroundStatConfigurable extends
-        Joinable<BackgroundStatConfigurable<byte[]>>,
-        BackgroundStatConfigurable<byte[]> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/JoinLeaveStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinLeaveStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinLeaveStatConfigEnsembleable.java
new file mode 100644
index 0000000..9642297
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinLeaveStatConfigEnsembleable.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinLeaveStatConfigEnsembleable extends
+    Joinable<LeaveStatConfigEnsembleable>,
+    Leaveable<JoinStatConfigEnsembleable>,
+    StatConfigEnsembleable
+{
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigEnsembleable.java
new file mode 100644
index 0000000..5fe7a8c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigEnsembleable.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinStatConfigEnsembleable extends
+    Joinable<StatConfigEnsembleable>,
+    StatConfigEnsembleable
+{
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigurable.java
new file mode 100644
index 0000000..ef17ef4
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinStatConfigurable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinStatConfigurable extends
+    Joinable<Configurable>
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
index dde5b1c..5cebe4d 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
@@ -16,16 +16,28 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.api;
 
-public interface Joinable<T> {
+import java.util.List;
 
+public interface Joinable<T>
+{
     /**
      * Adds one or more servers to joining the ensemble.
      * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
-     * @param server The server to joining.
-     * @return this.
+     *
+     * @param server The server joining.
+     * @return this
      */
     T joining(String... server);
 
+    /**
+     * Adds one or more servers to joining the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     *
+     * @param servers The servers joining.
+     * @return this
+     */
+    T joining(List<String> servers);
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveAddStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveAddStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveAddStatConfigEnsembleable.java
new file mode 100644
index 0000000..7912d45
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveAddStatConfigEnsembleable.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An non-incremental reconfiguration builder.
+ * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface LeaveAddStatConfigEnsembleable extends
+    Leaveable<AddStatConfigEnsembleable>,
+    Addable<LeaveStatConfigEnsembleable>,
+    StatConfigEnsembleable
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java
deleted file mode 100644
index a6316c1..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An non-incremental reconfiguration builder.
- * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
- * mixing concepts that can't be used together.
- */
-public interface LeaveBackgroundStatConfigEnsembleable extends
-        Leaveable<BackgroundStatConfigEnsembleable<byte[]>>,
-        BackgroundStatConfigEnsembleable<byte[]> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
deleted file mode 100644
index 196ffca..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An non-incremental reconfiguration builder.
- * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
- * mixing concepts that can't be used together.
- */
-public interface LeaveBackgroundStatConfigurable extends
-        Leaveable<BackgroundStatConfigurable<byte[]>>,
-        BackgroundStatConfigurable<byte[]> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveStatConfigEnsembleable.java
new file mode 100644
index 0000000..ddad854
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveStatConfigEnsembleable.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface LeaveStatConfigEnsembleable extends
+    Leaveable<StatConfigEnsembleable>,
+    StatConfigEnsembleable
+{
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
index a3c3358..6ec3542 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
@@ -16,15 +16,26 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.api;
 
-public interface Leaveable<T> {
+import java.util.List;
 
+public interface Leaveable<T>
+{
     /**
      * Sets one or more servers to leaving the ensemble.
-     * @param server The server ids.
+     *
+     * @param server The server ids
      * @return this
      */
     T leaving(String... server);
 
+    /**
+     * Sets one or more servers to leaving the ensemble.
+     *
+     * @param servers The server ids
+     * @return this
+     */
+    T leaving(List<String> servers);
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
deleted file mode 100644
index 6ef54c1..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-
-public interface Memberable<T> {
-
-    /**
-     * Sets one or more members that are meant to be part of the ensemble.
-     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
-     * @param server The server to add as a member of the ensemble.
-     * @return this.
-     */
-    T withMembers(String... server);
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java
deleted file mode 100644
index 2f6a9c6..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/NonIncrementalReconfigBuilder.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An non-incremental reconfiguration builder.
- * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
- * mixing concepts that can't be used together.
- * @param <T>
- */
-public interface NonIncrementalReconfigBuilder<T> extends
-        Memberable<NonIncrementalReconfigBuilder<T>>,
-        DataCallbackable<AsyncReconfigurable>,
-        Statable<SyncReconfigurable> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
index f05b99e..438abcf 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
@@ -16,11 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.api;
 
 public interface ReconfigBuilder extends
-        Joinable<LeaveBackgroundStatConfigEnsembleable>,
-        Leaveable<JoinBackgroundStatConfigEnsembleable>,
-        Memberable<BackgroundStatConfigEnsembleable<byte[]>> {
-
+    Joinable<LeaveAddStatConfigEnsembleable>,
+    Leaveable<JoinAddStatConfigEnsembleable>,
+    Addable<JoinLeaveStatConfigEnsembleable>,
+    Backgroundable<ReconfigBuilderMain>
+{
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilderMain.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilderMain.java b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilderMain.java
new file mode 100644
index 0000000..b86af2d
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilderMain.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+public interface ReconfigBuilderMain extends
+    Joinable<LeaveAddStatConfigEnsembleable>,
+    Leaveable<JoinAddStatConfigEnsembleable>,
+    Addable<JoinLeaveStatConfigEnsembleable>
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/StatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/StatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/StatConfigEnsembleable.java
new file mode 100644
index 0000000..4700c8c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/StatConfigEnsembleable.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+public interface StatConfigEnsembleable extends
+    Configurable,
+    StatEnsembleable<byte[]>
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/api/StatEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/StatEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/StatEnsembleable.java
new file mode 100644
index 0000000..0993b50
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/StatEnsembleable.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.api;
+
+public interface StatEnsembleable<T> extends
+    Statable<Ensembleable<T>>,
+    Ensembleable<T>
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index 5244d04..28b990d 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -751,7 +751,8 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
         return returnPath;
     }
 
-    private String adjustPath(String path) throws Exception
+    @VisibleForTesting
+    String adjustPath(String path) throws Exception
     {
         if ( doProtected )
         {

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index b9b9c31..9b96f60 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -398,12 +398,14 @@ public class CuratorFrameworkImpl implements CuratorFramework
     }
 
     @Override
-    public ReconfigBuilder reconfig() {
+    public ReconfigBuilder reconfig()
+    {
         return new ReconfigBuilderImpl(this);
     }
 
     @Override
-    public GetConfigBuilder getConfig() {
+    public GetConfigBuilder getConfig()
+    {
         return new GetConfigBuilderImpl(this);
     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
deleted file mode 100644
index df78aa7..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.imps;
-
-import java.util.Collections;
-import java.util.List;
-
-class EnsembleServersAndConfig {
-    private final List<String> joiningServers;
-    private final List<String> leavingServers;
-    private final List<String> members;
-    private final long config;
-
-    EnsembleServersAndConfig(List<String> joiningServers, List<String> leavingServers, List<String> members, long config) {
-        this.joiningServers = joiningServers.isEmpty() ? null : Collections.unmodifiableList(joiningServers);
-        this.leavingServers = leavingServers.isEmpty() ? null : Collections.unmodifiableList(leavingServers);
-        this.members = members.isEmpty() ? null : Collections.unmodifiableList(members);
-        this.config = config;
-    }
-
-    public List<String> getJoiningServers() {
-        return joiningServers;
-    }
-
-    public List<String> getLeavingServers() {
-        return leavingServers;
-    }
-
-    public List<String> getMembers() {
-        return members;
-    }
-
-    public long getConfig() {
-        return config;
-    }
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
index a789e42..6688848 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.imps;
 
 import com.google.common.base.Function;
@@ -35,7 +36,6 @@ import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import java.io.ByteArrayInputStream;
 import java.io.Closeable;
 import java.io.IOException;
@@ -46,65 +46,81 @@ import java.util.concurrent.atomic.AtomicReference;
 /**
  * Tracks changes to the ensemble and notifies registered {@link org.apache.curator.ensemble.EnsembleListener} instances.
  */
-public class EnsembleTracker implements Closeable {
-
+public class EnsembleTracker implements Closeable
+{
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final CuratorFramework client;
     private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
     private final ListenerContainer<EnsembleListener> listeners = new ListenerContainer<EnsembleListener>();
     private final AtomicBoolean isConnected = new AtomicBoolean(true);
-    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener() {
+    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener()
+    {
         @Override
-        public void stateChanged(CuratorFramework client, ConnectionState newState) {
-            if ((newState == ConnectionState.CONNECTED) || (newState == ConnectionState.RECONNECTED)) {
-                if (isConnected.compareAndSet(false, true)) {
-                    try {
+        public void stateChanged(CuratorFramework client, ConnectionState newState)
+        {
+            if ( (newState == ConnectionState.CONNECTED) || (newState == ConnectionState.RECONNECTED) )
+            {
+                if ( isConnected.compareAndSet(false, true) )
+                {
+                    try
+                    {
                         reset();
-                    } catch (Exception e) {
+                    }
+                    catch ( Exception e )
+                    {
                         log.error("Trying to reset after reconnection", e);
                     }
                 }
-            } else {
+            }
+            else
+            {
                 isConnected.set(false);
             }
         }
     };
 
-    private final CuratorWatcher watcher = new CuratorWatcher() {
+    private final CuratorWatcher watcher = new CuratorWatcher()
+    {
         @Override
-        public void process(WatchedEvent event) throws Exception {
+        public void process(WatchedEvent event) throws Exception
+        {
             reset();
         }
     };
 
-
-    private enum State {
+    private enum State
+    {
         LATENT,
         STARTED,
         CLOSED
     }
 
-    private final BackgroundCallback backgroundCallback = new BackgroundCallback() {
+    private final BackgroundCallback backgroundCallback = new BackgroundCallback()
+    {
         @Override
-        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
+        {
             processBackgroundResult(event);
         }
     };
 
-
-    public EnsembleTracker(CuratorFramework client) {
+    public EnsembleTracker(CuratorFramework client)
+    {
         this.client = client;
     }
 
-    public void start() throws Exception {
+    public void start() throws Exception
+    {
         Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once");
         client.getConnectionStateListenable().addListener(connectionStateListener);
         reset();
     }
 
     @Override
-    public void close() throws IOException {
-        if (state.compareAndSet(State.STARTED, State.CLOSED)) {
+    public void close() throws IOException
+    {
+        if ( state.compareAndSet(State.STARTED, State.CLOSED) )
+        {
             listeners.clear();
         }
         client.getConnectionStateListenable().removeListener(connectionStateListener);
@@ -122,27 +138,35 @@ public class EnsembleTracker implements Closeable {
         return listeners;
     }
 
-    private void reset() throws Exception {
+    private void reset() throws Exception
+    {
         client.getConfig().usingWatcher(watcher).inBackground(backgroundCallback).forEnsemble();
     }
 
-    private void processBackgroundResult(CuratorEvent event) throws Exception {
-        switch (event.getType()) {
-            case GET_CONFIG: {
-                if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
-                    processConfigData(event.getData());
-                }
+    private void processBackgroundResult(CuratorEvent event) throws Exception
+    {
+        switch ( event.getType() )
+        {
+        case GET_CONFIG:
+        {
+            if ( event.getResultCode() == KeeperException.Code.OK.intValue() )
+            {
+                processConfigData(event.getData());
             }
         }
+        }
     }
 
-    private void processConfigData(byte[] data) throws Exception {
+    private void processConfigData(byte[] data) throws Exception
+    {
         Properties properties = new Properties();
         properties.load(new ByteArrayInputStream(data));
         QuorumVerifier qv = new QuorumMaj(properties);
         StringBuilder sb = new StringBuilder();
-        for (QuorumPeer.QuorumServer server : qv.getAllMembers().values()) {
-            if (sb.length() != 0) {
+        for ( QuorumPeer.QuorumServer server : qv.getAllMembers().values() )
+        {
+            if ( sb.length() != 0 )
+            {
                 sb.append(",");
             }
             sb.append(server.clientAddr.getAddress().getHostAddress()).append(":").append(server.clientAddr.getPort());
@@ -150,18 +174,23 @@ public class EnsembleTracker implements Closeable {
 
         final String connectionString = sb.toString();
         listeners.forEach
-                (
-                        new Function<EnsembleListener, Void>() {
-                            @Override
-                            public Void apply(EnsembleListener listener) {
-                                try {
-                                    listener.connectionStringUpdated(connectionString);
-                                } catch (Exception e) {
-                                    log.error("Calling listener", e);
-                                }
-                                return null;
-                            }
+            (
+                new Function<EnsembleListener, Void>()
+                {
+                    @Override
+                    public Void apply(EnsembleListener listener)
+                    {
+                        try
+                        {
+                            listener.connectionStringUpdated(connectionString);
+                        }
+                        catch ( Exception e )
+                        {
+                            log.error("Calling listener", e);
                         }
-                );
+                        return null;
+                    }
+                }
+            );
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
index 5489691..15ed13e 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -16,201 +16,489 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.imps;
 
+import com.google.common.collect.ImmutableList;
 import org.apache.curator.RetryLoop;
 import org.apache.curator.TimeTrace;
-import org.apache.curator.framework.api.BackgroundCallback;
-import org.apache.curator.framework.api.BackgroundStatConfigEnsembleable;
-import org.apache.curator.framework.api.BackgroundStatEnsembleable;
-import org.apache.curator.framework.api.CuratorEvent;
-import org.apache.curator.framework.api.CuratorEventType;
-import org.apache.curator.framework.api.Ensembleable;
-import org.apache.curator.framework.api.JoinBackgroundStatConfigEnsembleable;
-import org.apache.curator.framework.api.LeaveBackgroundStatConfigEnsembleable;
-import org.apache.curator.framework.api.ReconfigBuilder;
+import org.apache.curator.framework.api.*;
 import org.apache.zookeeper.AsyncCallback;
 import org.apache.zookeeper.data.Stat;
-
+import org.apache.zookeeper.server.DataTree;
 import java.util.Arrays;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 
-public class ReconfigBuilderImpl implements ReconfigBuilder {
-
+public class ReconfigBuilderImpl implements
+    ReconfigBuilder,
+    ReconfigBuilderMain,
+    StatEnsembleable<byte[]>,
+    Configurable,
+    StatConfigEnsembleable,
+    BackgroundOperation<Void>
+{
     private final CuratorFrameworkImpl client;
 
-    public ReconfigBuilderImpl(CuratorFrameworkImpl client) {
+    private Backgrounding backgrounding;
+    private Stat responseStat;
+    private long fromConfig = -1;
+    private List<String> adding;
+    private List<String> joining;
+    private List<String> leaving;
+
+    public ReconfigBuilderImpl(CuratorFrameworkImpl client)
+    {
         this.client = client;
     }
 
-    private static class ReconfigBuilderBase implements BackgroundStatConfigEnsembleable<byte[]>, Ensembleable<byte[]>, BackgroundOperation<EnsembleServersAndConfig> {
+    @Override
+    public byte[] forEnsemble() throws Exception
+    {
+        if ( backgrounding != null )
+        {
+            client.processBackgroundOperation(new OperationAndData<>(this, null, backgrounding.getCallback(), null, backgrounding.getContext()), null);
+            return new byte[0];
+        }
+        else
+        {
+            return ensembleInForeground();
+        }
+    }
 
-        final CuratorFrameworkImpl client;
-        final List<String> joiningServers = new LinkedList<String>();
-        final List<String> leavingServers = new LinkedList<String>();
-        final List<String> members = new LinkedList<String>();
-        Backgrounding backgrounding;
-        Stat stat;
-        long config;
+    @Override
+    public Ensembleable<byte[]> storingStatIn(Stat stat)
+    {
+        responseStat = stat;
+        return this;
+    }
 
-        private ReconfigBuilderBase(CuratorFrameworkImpl client) {
-            this.client = client;
-            backgrounding = new Backgrounding();
-        }
+    @Override
+    public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+    {
+        fromConfig = config;
+        return this;
+    }
 
-        @Override
-        public Ensembleable<byte[]> inBackground() {
-            backgrounding = new Backgrounding();
-            return this;
-        }
+    @Override
+    public JoinLeaveStatConfigEnsembleable adding(String... server)
+    {
+        return adding((server != null) ? Arrays.asList(server) : null);
+    }
 
-        @Override
-        public Ensembleable<byte[]> inBackground(Object context) {
-            backgrounding = new Backgrounding(context);
-            return this;
-        }
+    @Override
+    public JoinLeaveStatConfigEnsembleable adding(List<String> servers)
+    {
+        this.adding = (servers != null) ? ImmutableList.copyOf(servers) : ImmutableList.<String>of();
 
-        @Override
-        public Ensembleable<byte[]> inBackground(BackgroundCallback callback) {
-            backgrounding = new Backgrounding(callback);
-            return this;
-        }
+        return new JoinLeaveStatConfigEnsembleable()
+        {
+            @Override
+            public byte[] forEnsemble() throws Exception
+            {
+                return ReconfigBuilderImpl.this.forEnsemble();
+            }
 
-        @Override
-        public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context) {
-            backgrounding = new Backgrounding(callback, context);
-            return this;
-        }
+            @Override
+            public Ensembleable<byte[]> storingStatIn(Stat stat)
+            {
+                return ReconfigBuilderImpl.this.storingStatIn(stat);
+            }
 
-        @Override
-        public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
-            backgrounding = new Backgrounding(callback, executor);
-            return this;
-        }
+            @Override
+            public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+            {
+                return ReconfigBuilderImpl.this.fromConfig(config);
+            }
 
-        @Override
-        public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
-            backgrounding = new Backgrounding(client, callback, context, executor);
-            return this;
-        }
+            @Override
+            public LeaveStatConfigEnsembleable joining(String... server)
+            {
+                return joining((server != null) ? Arrays.asList(server) : null);
+            }
 
-        @Override
-        public BackgroundStatEnsembleable<byte[]> fromConfig(long config) throws Exception {
-            this.config = config;
-            return this;
-        }
+            @Override
+            public LeaveStatConfigEnsembleable joining(List<String> servers)
+            {
+                return new LeaveStatConfigEnsembleable()
+                {
+                    @Override
+                    public byte[] forEnsemble() throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.forEnsemble();
+                    }
 
-        @Override
-        public Ensembleable<byte[]> storingStatIn(Stat stat) {
-            this.stat = stat;
-            return this;
-        }
+                    @Override
+                    public Ensembleable<byte[]> storingStatIn(Stat stat)
+                    {
+                        return ReconfigBuilderImpl.this.storingStatIn(stat);
+                    }
+
+                    @Override
+                    public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.fromConfig(config);
+                    }
 
-        @Override
-        public byte[] forEnsemble() throws Exception {
-            if (backgrounding.inBackground()) {
-                client.processBackgroundOperation(new OperationAndData<EnsembleServersAndConfig>(this,
-                        new EnsembleServersAndConfig(joiningServers, leavingServers, members, config),
-                        backgrounding.getCallback(), null, backgrounding.getContext()), null);
-                return new byte[0];
-            } else {
-                return ensembleInForeground();
+                    @Override
+                    public StatConfigEnsembleable leaving(List<String> servers)
+                    {
+                        return ReconfigBuilderImpl.this.leaving(servers);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable leaving(String... server)
+                    {
+                        return ReconfigBuilderImpl.this.leaving(server);
+                    }
+                };
             }
-        }
 
-        private byte[] ensembleInForeground() throws Exception {
-            TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Foreground");
-            byte[] responseData = RetryLoop.callWithRetry
-                    (
-                            client.getZookeeperClient(),
-                            new Callable<byte[]>() {
-                                @Override
-                                public byte[] call() throws Exception {
-                                    return client.getZooKeeper().reconfig(
-                                            joiningServers.isEmpty() ? null : joiningServers,
-                                            leavingServers.isEmpty() ? null : leavingServers,
-                                            members.isEmpty() ? null : members,
-                                            config,
-                                            stat
-                                    );
-                                }
-                            }
-                    );
-            trace.commit();
-            return responseData;
-        }
+            @Override
+            public JoinStatConfigEnsembleable leaving(String... server)
+            {
+                return leaving((server != null) ? Arrays.asList(server) : null);
+            }
 
-        @Override
-        public void performBackgroundOperation(final OperationAndData<EnsembleServersAndConfig> operationAndData) throws Exception {
-            final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background");
-            AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() {
-                @Override
-                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
-                    trace.commit();
-                    CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, data, null, null, null);
-                    client.processBackgroundOperation(operationAndData, event);
-                }
-            };
-            client.getZooKeeper().reconfig(
-                    operationAndData.getData().getJoiningServers(),
-                    operationAndData.getData().getLeavingServers(),
-                    operationAndData.getData().getMembers(),
-                    operationAndData.getData().getConfig(),
-                    callback,
-                    operationAndData.getContext()
-            );
+            @Override
+            public JoinStatConfigEnsembleable leaving(List<String> servers)
+            {
+                return new JoinStatConfigEnsembleable()
+                {
+                    @Override
+                    public byte[] forEnsemble() throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.forEnsemble();
+                    }
 
-        }
+                    @Override
+                    public Ensembleable<byte[]> storingStatIn(Stat stat)
+                    {
+                        return ReconfigBuilderImpl.this.storingStatIn(stat);
+                    }
+
+                    @Override
+                    public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.fromConfig(config);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable joining(List<String> servers)
+                    {
+                        return ReconfigBuilderImpl.this.joining(servers);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable joining(String... server)
+                    {
+                        return ReconfigBuilderImpl.this.joining(server);
+                    }
+                };
+            }
+        };
     }
 
-    private static class JoinReconfigBuilderConfig extends ReconfigBuilderBase implements JoinBackgroundStatConfigEnsembleable {
+    @Override
+    public ReconfigBuilderMain inBackground()
+    {
+        backgrounding = new Backgrounding();
+        return this;
+    }
 
-        private JoinReconfigBuilderConfig(CuratorFrameworkImpl client) {
-            super(client);
-        }
+    @Override
+    public ReconfigBuilderMain inBackground(Object context)
+    {
+        backgrounding = new Backgrounding(context);
+        return this;
+    }
 
-        @Override
-        public BackgroundStatConfigEnsembleable<byte[]> joining(String... servers) {
-            joiningServers.addAll(Arrays.asList(servers));
-            return this;
-        }
+    @Override
+    public ReconfigBuilderMain inBackground(BackgroundCallback callback)
+    {
+        backgrounding = new Backgrounding(callback);
+        return this;
     }
 
-    private static class LeaveReconfigBuilderConfig extends ReconfigBuilderBase implements LeaveBackgroundStatConfigEnsembleable {
+    @Override
+    public ReconfigBuilderMain inBackground(BackgroundCallback callback, Object context)
+    {
+        backgrounding = new Backgrounding(callback, context);
+        return this;
+    }
 
-        private LeaveReconfigBuilderConfig(CuratorFrameworkImpl client) {
-            super(client);
-        }
+    @Override
+    public ReconfigBuilderMain inBackground(BackgroundCallback callback, Executor executor)
+    {
+        backgrounding = new Backgrounding(callback, executor);
+        return this;
+    }
 
-        @Override
-        public BackgroundStatConfigEnsembleable<byte[]> leaving(String... servers) {
-            leavingServers.addAll(Arrays.asList(servers));
-            return this;
-        }
+    @Override
+    public ReconfigBuilderMain inBackground(BackgroundCallback callback, Object context, Executor executor)
+    {
+        backgrounding = new Backgrounding(client, callback, context, executor);
+        return this;
     }
 
+    @Override
+    public LeaveAddStatConfigEnsembleable joining(String... server)
+    {
+        return joining((server != null) ? Arrays.asList(server) : null);
+    }
 
     @Override
-    public LeaveBackgroundStatConfigEnsembleable joining(String... servers) {
-        LeaveReconfigBuilderConfig builder = new LeaveReconfigBuilderConfig(client);
-        builder.joiningServers.addAll(Arrays.asList(servers));
-        return builder;
+    public LeaveAddStatConfigEnsembleable joining(List<String> servers)
+    {
+        joining = (servers != null) ? ImmutableList.copyOf(servers) : ImmutableList.<String>of();
+
+        return new LeaveAddStatConfigEnsembleable()
+        {
+            @Override
+            public byte[] forEnsemble() throws Exception
+            {
+                return ReconfigBuilderImpl.this.forEnsemble();
+            }
+
+            @Override
+            public Ensembleable<byte[]> storingStatIn(Stat stat)
+            {
+                return ReconfigBuilderImpl.this.storingStatIn(stat);
+            }
+
+            @Override
+            public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+            {
+                return ReconfigBuilderImpl.this.fromConfig(config);
+            }
+
+            @Override
+            public LeaveStatConfigEnsembleable adding(String... server)
+            {
+                return adding((server != null) ? Arrays.asList(server) : null);
+            }
+
+            @Override
+            public LeaveStatConfigEnsembleable adding(List<String> servers)
+            {
+                return new LeaveStatConfigEnsembleable()
+                {
+                    @Override
+                    public byte[] forEnsemble() throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.forEnsemble();
+                    }
+
+                    @Override
+                    public Ensembleable<byte[]> storingStatIn(Stat stat)
+                    {
+                        return ReconfigBuilderImpl.this.storingStatIn(stat);
+                    }
+
+                    @Override
+                    public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.fromConfig(config);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable leaving(List<String> servers)
+                    {
+                        return ReconfigBuilderImpl.this.leaving(servers);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable leaving(String... server)
+                    {
+                        return ReconfigBuilderImpl.this.leaving(server);
+                    }
+                };
+            }
+
+            @Override
+            public AddStatConfigEnsembleable leaving(String... server)
+            {
+                return leaving((server != null) ? Arrays.asList(server) : null);
+            }
+
+            @Override
+            public AddStatConfigEnsembleable leaving(List<String> servers)
+            {
+                return new AddStatConfigEnsembleable()
+                {
+                    @Override
+                    public byte[] forEnsemble() throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.forEnsemble();
+                    }
+
+                    @Override
+                    public Ensembleable<byte[]> storingStatIn(Stat stat)
+                    {
+                        return ReconfigBuilderImpl.this.storingStatIn(stat);
+                    }
+
+                    @Override
+                    public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.fromConfig(config);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable adding(List<String> servers)
+                    {
+                        return ReconfigBuilderImpl.this.adding(servers);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable adding(String... server)
+                    {
+                        return ReconfigBuilderImpl.this.adding(server);
+                    }
+                };
+            }
+        };
     }
 
     @Override
-    public JoinBackgroundStatConfigEnsembleable leaving(String... servers) {
-        JoinReconfigBuilderConfig builder = new JoinReconfigBuilderConfig(client);
-        builder.leavingServers.addAll(Arrays.asList(servers));
-        return builder;
+    public JoinAddStatConfigEnsembleable leaving(String... server)
+    {
+        return leaving((server != null) ? Arrays.asList(server) : null);
     }
 
     @Override
-    public BackgroundStatConfigEnsembleable<byte[]> withMembers(String... servers) {
-        ReconfigBuilderBase builder = new ReconfigBuilderBase(client);
-        builder.members.addAll(Arrays.asList(servers));
-        return builder;
+    public JoinAddStatConfigEnsembleable leaving(List<String> servers)
+    {
+        leaving = (servers != null) ? ImmutableList.copyOf(servers) : ImmutableList.<String>of();
+
+        return new JoinAddStatConfigEnsembleable()
+        {
+            @Override
+            public byte[] forEnsemble() throws Exception
+            {
+                return ReconfigBuilderImpl.this.forEnsemble();
+            }
+
+            @Override
+            public Ensembleable<byte[]> storingStatIn(Stat stat)
+            {
+                return ReconfigBuilderImpl.this.storingStatIn(stat);
+            }
+
+            @Override
+            public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+            {
+                return ReconfigBuilderImpl.this.fromConfig(config);
+            }
+
+            @Override
+            public JoinStatConfigurable adding(String... server)
+            {
+                return adding((server != null) ? Arrays.asList(server) : null);
+            }
+
+            @Override
+            public JoinStatConfigurable adding(List<String> servers)
+            {
+                return new JoinStatConfigurable()
+                {
+                    @Override
+                    public Configurable joining(List<String> servers)
+                    {
+                        return ReconfigBuilderImpl.this.joining(servers);
+                    }
+
+                    @Override
+                    public Configurable joining(String... server)
+                    {
+                        return ReconfigBuilderImpl.this.joining(server);
+                    }
+                };
+            }
+
+            @Override
+            public AddStatConfigEnsembleable joining(String... server)
+            {
+                return joining((server != null) ? Arrays.asList(server) : null);
+            }
+
+            @Override
+            public AddStatConfigEnsembleable joining(List<String> servers)
+            {
+                return new AddStatConfigEnsembleable()
+                {
+                    @Override
+                    public byte[] forEnsemble() throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.forEnsemble();
+                    }
+
+                    @Override
+                    public Ensembleable<byte[]> storingStatIn(Stat stat)
+                    {
+                        return ReconfigBuilderImpl.this.storingStatIn(stat);
+                    }
+
+                    @Override
+                    public StatEnsembleable<byte[]> fromConfig(long config) throws Exception
+                    {
+                        return ReconfigBuilderImpl.this.fromConfig(config);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable adding(List<String> servers)
+                    {
+                        return ReconfigBuilderImpl.this.adding(servers);
+                    }
+
+                    @Override
+                    public StatConfigEnsembleable adding(String... server)
+                    {
+                        return ReconfigBuilderImpl.this.adding(server);
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public void performBackgroundOperation(final OperationAndData<Void> data) throws Exception
+    {
+        final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background");
+        AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
+        {
+            @Override
+            public void processResult(int rc, String path, Object ctx, byte[] bytes, Stat stat)
+            {
+                trace.commit();
+                if ( (responseStat != null) && (stat != null) )
+                {
+                    DataTree.copyStat(stat, responseStat);
+                }
+                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, bytes, null, null, null);
+                client.processBackgroundOperation(data, event);
+            }
+        };
+        client.getZooKeeper().reconfig(joining, leaving, adding, fromConfig, callback, backgrounding.getContext());
+    }
+
+    private byte[] ensembleInForeground() throws Exception
+    {
+        TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Foreground");
+        byte[] responseData = RetryLoop.callWithRetry
+            (
+                client.getZookeeperClient(),
+                new Callable<byte[]>()
+                {
+                    @Override
+                    public byte[] call() throws Exception
+                    {
+                        return client.getZooKeeper().reconfig(joining, leaving, adding, fromConfig, responseStat);
+                    }
+                }
+            );
+        trace.commit();
+        return responseData;
     }
 }


[21/26] curator git commit: Added doc for reconfig

Posted by ra...@apache.org.
Added doc for reconfig


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

Branch: refs/heads/CURATOR-215
Commit: d36159491cb56cc3776500f56667b8189cab1293
Parents: 5e6cd0e
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 10:19:41 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 10:19:41 2015 -0500

----------------------------------------------------------------------
 curator-framework/src/site/confluence/index.confluence | 4 ++++
 src/site/confluence/utilities.confluence               | 5 +++++
 2 files changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/d3615949/curator-framework/src/site/confluence/index.confluence
----------------------------------------------------------------------
diff --git a/curator-framework/src/site/confluence/index.confluence b/curator-framework/src/site/confluence/index.confluence
index 84f794f..cf92514 100644
--- a/curator-framework/src/site/confluence/index.confluence
+++ b/curator-framework/src/site/confluence/index.confluence
@@ -43,6 +43,10 @@ h3. Methods
 |setData()|Begins an operation to set a ZNode's data. Call additional methods (version or background) and finalize the operation by calling forPath()|
 |getChildren()|Begins an operation to get a ZNode's list of children ZNodes. Call additional methods (watch, background or get stat) and finalize the operation by calling forPath()|
 |inTransaction()|Begins an atomic ZooKeeper transaction. Combine create, setData, check, and/or delete operations and then commit() as a unit.|
+|getACL()|Begins an operation to return a ZNode's ACL settings. Call additional methods and finalize the operation by calling forPath()|
+|setACL()|Begins an operation to set a ZNode's ACL settings. Call additional methods and finalize the operation by calling forPath()|
+|getConfig()|Begins an operation to return the last committed configuration. Call additional methods and finalize the operation by calling forEnsemble()|
+|reconfig()|Begins an operation to change the configuration. Call additional methods and finalize the operation by calling forEnsemble()|
 
 h3. Notifications
 Notifications for background operations and watches are published via the ClientListener interface. You register listeners with the

http://git-wip-us.apache.org/repos/asf/curator/blob/d3615949/src/site/confluence/utilities.confluence
----------------------------------------------------------------------
diff --git a/src/site/confluence/utilities.confluence b/src/site/confluence/utilities.confluence
index 7a8e95f..2ec5c6b 100644
--- a/src/site/confluence/utilities.confluence
+++ b/src/site/confluence/utilities.confluence
@@ -57,3 +57,8 @@ _ChildReaper_
 Utility to reap the empty child nodes in a parent node. Periodically calls getChildren() on the node and adds empty nodes to an internally managed Reaper.
 
 *NOTE:* You should consider using LeaderSelector to run the Reapers as they don't need to run in every client.
+
+h2. EnsembleTracker
+
+Utility to listen for ensemble/configuration changes via registered EnsembleListeners. Allocate a EnsembleTracker, add one or more listeners
+and start it.


[09/26] curator git commit: [CURATOR-160] Add EnsembleListener and EnsembleTracker. Implement a DynamicEnsembleProvider. TestReconfiguration now also tests the DynamicEnsembleProvider.

Posted by ra...@apache.org.
[CURATOR-160] Add EnsembleListener and EnsembleTracker. Implement a DynamicEnsembleProvider. TestReconfiguration now also tests the DynamicEnsembleProvider.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/59292d88
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/59292d88
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/59292d88

Branch: refs/heads/CURATOR-215
Commit: 59292d8854678d73d27a86746c1734f6c0f7e6a8
Parents: 3b5452f
Author: Ioannis Canellos <io...@gmail.com>
Authored: Tue Nov 11 16:35:57 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 13:00:30 2015 +0300

----------------------------------------------------------------------
 .../curator/ensemble/EnsembleListener.java      |  24 +
 .../dynamic/DynamicEnsembleProvider.java        |  61 +++
 .../curator/framework/imps/EnsembleTracker.java | 167 +++++++
 .../framework/imps/TestReconfiguration.java     | 489 +++++++++++--------
 4 files changed, 538 insertions(+), 203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/59292d88/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java b/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java
new file mode 100644
index 0000000..8f963cd
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.ensemble;
+
+public interface EnsembleListener {
+
+    void connectionStringUpdated(String connectionString);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/59292d88/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java b/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java
new file mode 100644
index 0000000..70b755f
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.ensemble.dynamic;
+
+import com.google.common.base.Preconditions;
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.ensemble.EnsembleProvider;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class DynamicEnsembleProvider implements EnsembleProvider, EnsembleListener {
+
+    private final AtomicReference<String> connectionString = new AtomicReference<String>();
+
+    /**
+     * The connection string to use
+     *
+     * @param connectionString connection string
+     */
+    public DynamicEnsembleProvider(String connectionString)
+    {
+        this.connectionString.set(Preconditions.checkNotNull(connectionString, "connectionString cannot be null"));
+    }
+
+    @Override
+    public void start() throws Exception {
+        // NOP
+    }
+
+    @Override
+    public String getConnectionString() {
+        return connectionString.get();
+    }
+
+    @Override
+    public void close() throws IOException {
+        // NOP
+    }
+
+    @Override
+    public void connectionStringUpdated(String connectionString) {
+        this.connectionString.set(connectionString);
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/59292d88/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
new file mode 100644
index 0000000..a789e42
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
@@ -0,0 +1,167 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.listen.ListenerContainer;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tracks changes to the ensemble and notifies registered {@link org.apache.curator.ensemble.EnsembleListener} instances.
+ */
+public class EnsembleTracker implements Closeable {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final CuratorFramework client;
+    private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
+    private final ListenerContainer<EnsembleListener> listeners = new ListenerContainer<EnsembleListener>();
+    private final AtomicBoolean isConnected = new AtomicBoolean(true);
+    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener() {
+        @Override
+        public void stateChanged(CuratorFramework client, ConnectionState newState) {
+            if ((newState == ConnectionState.CONNECTED) || (newState == ConnectionState.RECONNECTED)) {
+                if (isConnected.compareAndSet(false, true)) {
+                    try {
+                        reset();
+                    } catch (Exception e) {
+                        log.error("Trying to reset after reconnection", e);
+                    }
+                }
+            } else {
+                isConnected.set(false);
+            }
+        }
+    };
+
+    private final CuratorWatcher watcher = new CuratorWatcher() {
+        @Override
+        public void process(WatchedEvent event) throws Exception {
+            reset();
+        }
+    };
+
+
+    private enum State {
+        LATENT,
+        STARTED,
+        CLOSED
+    }
+
+    private final BackgroundCallback backgroundCallback = new BackgroundCallback() {
+        @Override
+        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+            processBackgroundResult(event);
+        }
+    };
+
+
+    public EnsembleTracker(CuratorFramework client) {
+        this.client = client;
+    }
+
+    public void start() throws Exception {
+        Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once");
+        client.getConnectionStateListenable().addListener(connectionStateListener);
+        reset();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (state.compareAndSet(State.STARTED, State.CLOSED)) {
+            listeners.clear();
+        }
+        client.getConnectionStateListenable().removeListener(connectionStateListener);
+    }
+
+    /**
+     * Return the ensemble listenable
+     *
+     * @return listenable
+     */
+    public ListenerContainer<EnsembleListener> getListenable()
+    {
+        Preconditions.checkState(state.get() != State.CLOSED, "Closed");
+
+        return listeners;
+    }
+
+    private void reset() throws Exception {
+        client.getConfig().usingWatcher(watcher).inBackground(backgroundCallback).forEnsemble();
+    }
+
+    private void processBackgroundResult(CuratorEvent event) throws Exception {
+        switch (event.getType()) {
+            case GET_CONFIG: {
+                if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
+                    processConfigData(event.getData());
+                }
+            }
+        }
+    }
+
+    private void processConfigData(byte[] data) throws Exception {
+        Properties properties = new Properties();
+        properties.load(new ByteArrayInputStream(data));
+        QuorumVerifier qv = new QuorumMaj(properties);
+        StringBuilder sb = new StringBuilder();
+        for (QuorumPeer.QuorumServer server : qv.getAllMembers().values()) {
+            if (sb.length() != 0) {
+                sb.append(",");
+            }
+            sb.append(server.clientAddr.getAddress().getHostAddress()).append(":").append(server.clientAddr.getPort());
+        }
+
+        final String connectionString = sb.toString();
+        listeners.forEach
+                (
+                        new Function<EnsembleListener, Void>() {
+                            @Override
+                            public Void apply(EnsembleListener listener) {
+                                try {
+                                    listener.connectionStringUpdated(connectionString);
+                                } catch (Exception e) {
+                                    log.error("Calling listener", e);
+                                }
+                                return null;
+                            }
+                        }
+                );
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/59292d88/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index e8896ae..faec551 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -18,6 +18,8 @@
  */
 package org.apache.curator.framework.imps;
 
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.ensemble.dynamic.DynamicEnsembleProvider;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.api.BackgroundCallback;
@@ -35,246 +37,287 @@ import org.testng.annotations.Test;
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 
 public class TestReconfiguration {
 
     TestingCluster cluster;
+    DynamicEnsembleProvider dynamicEnsembleProvider;
+    WaitOnDelegateListener waitOnDelegateListener;
+    EnsembleTracker ensembleTracker;
+    CuratorFramework client;
+
+    String connectionString1to5;
+    String connectionString2to5;
+    String connectionString3to5;
 
     @BeforeMethod
     public void setup() throws Exception {
         cluster = new TestingCluster(5);
         cluster.start();
+
+        connectionString1to5 = cluster.getConnectString();
+        connectionString2to5 = getConnectionString(cluster, 2,3,4,5);
+        connectionString3to5 = getConnectionString(cluster, 3,4,5);
+
+        dynamicEnsembleProvider = new DynamicEnsembleProvider(connectionString1to5);
+        client = CuratorFrameworkFactory.builder()
+                .ensembleProvider(dynamicEnsembleProvider)
+                .retryPolicy(new RetryOneTime(1))
+                .build();
+        client.start();
+        client.blockUntilConnected();
+
+        //Wrap around the dynamic ensemble provider, so that we can wait until it has received the event.
+        waitOnDelegateListener = new WaitOnDelegateListener(dynamicEnsembleProvider);
+        ensembleTracker = new EnsembleTracker(client);
+        ensembleTracker.getListenable().addListener(waitOnDelegateListener);
+        ensembleTracker.start();
+        //Wait for the initial event.
+        waitOnDelegateListener.waitForEvent();
     }
 
     @AfterMethod
     public void tearDown() throws IOException {
+        ensembleTracker.close();
+        client.close();
         cluster.close();
     }
 
     @Test
     public void testSyncIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            Stat stat = new Stat();
-            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
-            Assert.assertNotNull(bytes);
-            QuorumVerifier qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-
-            //Remove Servers
-            bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        Stat stat = new Stat();
+        byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+        Assert.assertNotNull(bytes);
+        QuorumVerifier qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+
+        //Remove Servers
+        bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+
+        //Add Servers
+        bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
     }
 
     @Test
     public void testAsyncIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
-            final BackgroundCallback callback = new BackgroundCallback() {
-                @Override
-                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
-                    bytes.set(event.getData());
-                    ((CountDownLatch)event.getContext()).countDown();
+        final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+        final BackgroundCallback callback = new BackgroundCallback() {
+            @Override
+            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                bytes.set(event.getData());
+                //We only need the latch on getConfig.
+                if (event.getContext() != null) {
+                    ((CountDownLatch) event.getContext()).countDown();
                 }
+            }
 
-            };
-
-            CountDownLatch latch = new CountDownLatch(1);
-            client.getConfig().inBackground(callback, latch).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            Assert.assertNotNull(bytes.get());
-            QuorumVerifier qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-
-
-            //Remove Servers
-            latch = new CountDownLatch(1);
-            client.reconfig().leaving("1").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            latch = new CountDownLatch(1);
-            client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        };
+
+        CountDownLatch latch = new CountDownLatch(1);
+        client.getConfig().inBackground(callback, latch).forEnsemble();
+        latch.await(5, TimeUnit.SECONDS);
+        Assert.assertNotNull(bytes.get());
+        QuorumVerifier qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+
+
+        //Remove Servers
+        client.reconfig().leaving("1").inBackground(callback).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        //Add Servers
+        client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+
+        client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
     }
 
     @Test
     public void testSyncNonIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            Stat stat = new Stat();
-            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
-            Assert.assertNotNull(bytes);
-            QuorumVerifier qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-            String server3 = getServerString(qv, cluster, 3L);
-            String server4 = getServerString(qv, cluster, 4L);
-            String server5 = getServerString(qv, cluster, 5L);
-
-            //Remove Servers
-            bytes = client.reconfig()
-                    .withMembers("server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig()
-                    .withMembers("server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            bytes = client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        Stat stat = new Stat();
+        byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+        Assert.assertNotNull(bytes);
+        QuorumVerifier qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+        String server3 = getServerString(qv, cluster, 3L);
+        String server4 = getServerString(qv, cluster, 4L);
+        String server5 = getServerString(qv, cluster, 5L);
+
+        //Remove Servers
+        bytes = client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig()
+                .withMembers("server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+
+        //Add Servers
+        bytes = client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig()
+                .withMembers("server.1=" + server1,
+                        "server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
     }
 
     @Test
     public void testAsyncNonIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
-            final BackgroundCallback callback = new BackgroundCallback() {
-                @Override
-                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
-                    bytes.set(event.getData());
-                    ((CountDownLatch)event.getContext()).countDown();
-                }
+        final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+        final BackgroundCallback callback = new BackgroundCallback() {
+            @Override
+            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                bytes.set(event.getData());
+                ((CountDownLatch) event.getContext()).countDown();
+            }
 
-            };
-
-            CountDownLatch latch = new CountDownLatch(1);
-            client.getConfig().inBackground(callback, latch).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            Assert.assertNotNull(bytes.get());
-            QuorumVerifier qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-            String server3 = getServerString(qv, cluster, 3L);
-            String server4 = getServerString(qv, cluster, 4L);
-            String server5 = getServerString(qv, cluster, 5L);
-
-            //Remove Servers
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-            .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        };
+
+        CountDownLatch latch = new CountDownLatch(1);
+        client.getConfig().inBackground(callback, latch).forEnsemble();
+        latch.await(5, TimeUnit.SECONDS);
+        Assert.assertNotNull(bytes.get());
+        QuorumVerifier qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+        String server3 = getServerString(qv, cluster, 3L);
+        String server4 = getServerString(qv, cluster, 4L);
+        String server5 = getServerString(qv, cluster, 5L);
+
+        //Remove Servers
+        client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        client.reconfig()
+                .withMembers("server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        //Add Servers
+        client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        client.reconfig()
+                .withMembers("server.1=" + server1,
+                        "server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
     }
 
 
@@ -302,4 +345,44 @@ public class TestReconfiguration {
             return str + ";" + getInstance(cluster, (int) id).getConnectString();
         }
     }
+
+    static String getConnectionString(TestingCluster cluster, long... ids) throws Exception {
+        StringBuilder sb = new StringBuilder();
+        Map<Long, InstanceSpec> specs = new HashMap<Long, InstanceSpec>();
+        for (InstanceSpec spec : cluster.getInstances()) {
+            specs.put(new Long(spec.getServerId()), spec);
+        }
+        for (long id : ids) {
+            if (sb.length() != 0) {
+                sb.append(",");
+            }
+            sb.append(specs.get(id).getConnectString());
+        }
+        return sb.toString();
+    }
+
+    //Simple EnsembleListener that can wait until the delegate handles the event.
+    private static class WaitOnDelegateListener implements EnsembleListener {
+        private CountDownLatch latch = new CountDownLatch(1);
+
+        private final EnsembleListener delegate;
+
+        private WaitOnDelegateListener(EnsembleListener delegate) {
+            this.delegate = delegate;
+        }
+
+        @Override
+        public void connectionStringUpdated(String connectionString) {
+            delegate.connectionStringUpdated(connectionString);
+            latch.countDown();
+        }
+
+        public void waitForEvent() throws InterruptedException, TimeoutException {
+            if (latch.await(5, TimeUnit.SECONDS)) {
+                latch = new CountDownLatch(1);
+            } else {
+                throw new TimeoutException("Failed to receive event in time.");
+            }
+        }
+    };
 }
\ No newline at end of file


[26/26] curator git commit: Merge branch 'CURATOR-3.0' into CURATOR-215

Posted by ra...@apache.org.
Merge branch 'CURATOR-3.0' into CURATOR-215

Conflicts:
	curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
	curator-framework/src/main/java/org/apache/curator/framework/imps/DeleteBuilderImpl.java
	curator-framework/src/site/confluence/index.confluence


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

Branch: refs/heads/CURATOR-215
Commit: f76971769ce5d999ccae7a3a6c42632298e0d75b
Parents: 5414266 fc45a4e
Author: randgalt <ra...@apache.org>
Authored: Tue May 12 10:53:32 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 12 10:53:32 2015 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/curator/RetryLoop.java |   3 +-
 .../curator/ensemble/EnsembleListener.java      |  24 +
 .../dynamic/DynamicEnsembleProvider.java        |  61 +++
 .../curator/framework/CuratorFramework.java     |  14 +
 .../api/AddStatConfigEnsembleable.java          |  32 ++
 .../apache/curator/framework/api/Addable.java   |  43 ++
 .../framework/api/AsyncReconfigurable.java      |  29 ++
 .../framework/api/BackgroundStatable.java       |  24 +
 .../curator/framework/api/Configurable.java     |  31 ++
 .../curator/framework/api/CuratorEventType.java |  10 +
 .../curator/framework/api/DataCallbackable.java |  32 ++
 .../curator/framework/api/Ensembleable.java     |  24 +
 .../curator/framework/api/GetConfigBuilder.java |  29 ++
 .../api/IncrementalReconfigBuilder.java         |  33 ++
 .../api/JoinAddStatConfigEnsembleable.java      |  33 ++
 .../api/JoinLeaveStatConfigEnsembleable.java    |  33 ++
 .../api/JoinStatConfigEnsembleable.java         |  32 ++
 .../framework/api/JoinStatConfigurable.java     |  30 ++
 .../apache/curator/framework/api/Joinable.java  |  43 ++
 .../api/LeaveAddStatConfigEnsembleable.java     |  32 ++
 .../api/LeaveStatConfigEnsembleable.java        |  32 ++
 .../apache/curator/framework/api/Leaveable.java |  41 ++
 .../curator/framework/api/ReconfigBuilder.java  |  28 ++
 .../framework/api/ReconfigBuilderMain.java      |  27 +
 .../framework/api/StatConfigEnsembleable.java   |  26 +
 .../curator/framework/api/StatEnsembleable.java |  26 +
 .../framework/api/SyncReconfigurable.java       |  30 ++
 .../framework/ensemble/EnsembleTracker.java     | 191 +++++++
 .../framework/imps/CreateBuilderImpl.java       |  11 +-
 .../framework/imps/CuratorFrameworkImpl.java    |  12 +
 .../framework/imps/DeleteBuilderImpl.java       | 102 ++--
 .../framework/imps/GetConfigBuilderImpl.java    | 187 +++++++
 .../framework/imps/ReconfigBuilderImpl.java     | 504 +++++++++++++++++++
 .../src/site/confluence/index.confluence        |  20 +-
 .../framework/imps/TestReconfiguration.java     | 417 +++++++++++++++
 .../org/apache/curator/test/InstanceSpec.java   |   4 +
 .../curator/test/QuorumConfigBuilder.java       |   2 +-
 .../org/apache/curator/test/TestingCluster.java |   1 +
 src/site/confluence/utilities.confluence        |   5 +
 39 files changed, 2189 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/f7697176/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/curator/blob/f7697176/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
index dce1f7f,50e9195..5a2dc56
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
@@@ -69,11 -69,16 +69,21 @@@ public enum CuratorEventTyp
      SET_ACL,
  
      /**
 +     * Corresponds to {@link CuratorFramework#transaction()}
 +     */
 +    TRANSACTION,
 +
 +    /**
+      * Corresponds to {@link CuratorFramework#getConfig()}
+      */
+     GET_CONFIG,
+ 
+     /**
+      * Corresponds to {@link CuratorFramework#reconfig()}
+      */
+     RECONFIG,
+ 
+     /**
       * Corresponds to {@link Watchable#usingWatcher(Watcher)} or {@link Watchable#watched()}
       */
      WATCHED,

http://git-wip-us.apache.org/repos/asf/curator/blob/f7697176/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/curator/blob/f7697176/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/curator/blob/f7697176/curator-framework/src/main/java/org/apache/curator/framework/imps/DeleteBuilderImpl.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/imps/DeleteBuilderImpl.java
index 51641b8,5d8b846..f5083fb
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/DeleteBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/DeleteBuilderImpl.java
@@@ -54,16 -55,16 +54,16 @@@ class DeleteBuilderImpl implements Dele
          guaranteed = false;
      }
  
 -    TransactionDeleteBuilder    asTransactionDeleteBuilder(final CuratorTransactionImpl curatorTransaction, final CuratorMultiTransactionRecord transaction)
 +    <T> TransactionDeleteBuilder<T> asTransactionDeleteBuilder(final T context, final CuratorMultiTransactionRecord transaction)
      {
 -        return new TransactionDeleteBuilder()
 +        return new TransactionDeleteBuilder<T>()
          {
              @Override
 -            public CuratorTransactionBridge forPath(String path) throws Exception
 +            public T forPath(String path) throws Exception
              {
-                 String fixedPath = client.fixForNamespace(path);
+                 String      fixedPath = client.fixForNamespace(path);
                  transaction.add(Op.delete(fixedPath, version), OperationType.DELETE, path);
 -                return curatorTransaction;
 +                return context;
              }
  
              @Override
@@@ -141,30 -142,27 +141,30 @@@
      @Override
      public void performBackgroundOperation(final OperationAndData<String> operationAndData) throws Exception
      {
-         final TimeTrace trace = client.getZookeeperClient().startTracer("DeleteBuilderImpl-Background");
+         final TimeTrace   trace = client.getZookeeperClient().startTracer("DeleteBuilderImpl-Background");
          client.getZooKeeper().delete
-             (
-                 operationAndData.getData(),
-                 version,
-                 new AsyncCallback.VoidCallback()
+         (
+             operationAndData.getData(),
+             version,
+             new AsyncCallback.VoidCallback()
+             {
+                 @Override
+                 public void processResult(int rc, String path, Object ctx)
                  {
-                     @Override
-                     public void processResult(int rc, String path, Object ctx)
+                     trace.commit();
 -                    if ((rc == KeeperException.Code.NOTEMPTY.intValue()) && deletingChildrenIfNeeded) {
++                    if ( (rc == KeeperException.Code.NOTEMPTY.intValue()) && deletingChildrenIfNeeded )
 +                    {
-                         trace.commit();
-                         if ( (rc == KeeperException.Code.NOTEMPTY.intValue()) && deletingChildrenIfNeeded )
-                         {
-                             backgroundDeleteChildrenThenNode(operationAndData);
-                         }
-                         else
-                         {
-                             CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.DELETE, rc, path, null, ctx, null, null, null, null, null, null);
-                             client.processBackgroundOperation(operationAndData, event);
-                         }
+                         backgroundDeleteChildrenThenNode(operationAndData);
 -                    } else {
 -                        CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.DELETE, rc, path, null, ctx, null, null, null, null, null);
 +                    }
-                 },
-                 backgrounding.getContext()
-             );
++                    else
++                    {
++                        CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.DELETE, rc, path, null, ctx, null, null, null, null, null, null);
+                         client.processBackgroundOperation(operationAndData, event);
+                     }
+                 }
+             },
+             backgrounding.getContext()
+         );
      }
  
      private void backgroundDeleteChildrenThenNode(final OperationAndData<String> mainOperationAndData)

http://git-wip-us.apache.org/repos/asf/curator/blob/f7697176/curator-framework/src/site/confluence/index.confluence
----------------------------------------------------------------------
diff --cc curator-framework/src/site/confluence/index.confluence
index 3c686db,c41b244..b065f00
--- a/curator-framework/src/site/confluence/index.confluence
+++ b/curator-framework/src/site/confluence/index.confluence
@@@ -42,8 -42,11 +42,16 @@@ h3. Method
  |getData()|Begins an operation to get a ZNode's data. Call additional methods (watch, background or get stat) and finalize the operation by calling forPath()|
  |setData()|Begins an operation to set a ZNode's data. Call additional methods (version or background) and finalize the operation by calling forPath()|
  |getChildren()|Begins an operation to get a ZNode's list of children ZNodes. Call additional methods (watch, background or get stat) and finalize the operation by calling forPath()|
++<<<<<<< HEAD
 +|transactionOp()|Used to allocate operations to be used with transaction().|
 +|transaction()|Atomically submit a set of operations as a transaction.|
++=======
+ |inTransaction()|Begins an atomic ZooKeeper transaction. Combine create, setData, check, and/or delete operations and then commit() as a unit.|
+ |getACL()|Begins an operation to return a ZNode's ACL settings. Call additional methods and finalize the operation by calling forPath()|
+ |setACL()|Begins an operation to set a ZNode's ACL settings. Call additional methods and finalize the operation by calling forPath()|
+ |getConfig()|Begins an operation to return the last committed configuration. Call additional methods and finalize the operation by calling forEnsemble()|
+ |reconfig()|Begins an operation to change the configuration. Call additional methods and finalize the operation by calling forEnsemble()|
++>>>>>>> CURATOR-3.0
  
  h3. Notifications
  Notifications for background operations and watches are published via the ClientListener interface. You register listeners with the
@@@ -66,8 -69,9 +74,10 @@@ CuratorEvent depend on the type of even
  |SYNC|getResultCode(), getStat()|
  |GET\_ACL|getResultCode(), getACLList()|
  |SET\_ACL|getResultCode()|
 +|TRANSACTION|getResultCode(), getOpResults()|
  |WATCHED|getWatchedEvent()|
+ |GET\_CONFIG|getResultCode(), getData()|
+ |RECONFIG|getResultCode(), getData()|
  
  h2. Namespaces
  Because a ZooKeeper cluster is a shared environment, it's vital that a namespace convention is


[19/26] curator git commit: Some more refactoring, etc.

Posted by ra...@apache.org.
Some more refactoring, etc.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/3cbc3afd
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/3cbc3afd
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/3cbc3afd

Branch: refs/heads/CURATOR-215
Commit: 3cbc3afd68173ed3892154fb25cdf140eba71b3a
Parents: aaa0487
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 09:22:47 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 09:22:47 2015 -0500

----------------------------------------------------------------------
 .../curator/framework/api/GetConfigBuilder.java |   8 +-
 .../framework/imps/GetConfigBuilderImpl.java    | 108 +++++++++----------
 .../framework/imps/ReconfigBuilderImpl.java     |   4 +-
 3 files changed, 61 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/3cbc3afd/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
index c2fdf6c..c42e4cb 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
@@ -16,12 +16,14 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.api;
 
 public interface GetConfigBuilder extends
-        Watchable<BackgroundStatable<Ensembleable<byte[]>>>,
-        BackgroundStatable<Ensembleable<byte[]>>,
-        Ensembleable<byte[]> {
+    Watchable<BackgroundStatable<Ensembleable<byte[]>>>,
+    BackgroundStatable<Ensembleable<byte[]>>,
+    Ensembleable<byte[]>
+{
 }
 
 

http://git-wip-us.apache.org/repos/asf/curator/blob/3cbc3afd/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
index d331a0a..b65f863 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.imps;
 
 import org.apache.curator.RetryLoop;
@@ -30,122 +31,112 @@ import org.apache.curator.framework.api.GetConfigBuilder;
 import org.apache.zookeeper.AsyncCallback;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.Stat;
-
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 
-public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperation<Void> {
-
+public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperation<Void>
+{
     private final CuratorFrameworkImpl client;
 
     private Backgrounding backgrounding;
     private Watching watching;
     private Stat stat;
 
-    public GetConfigBuilderImpl(CuratorFrameworkImpl client) {
+    public GetConfigBuilderImpl(CuratorFrameworkImpl client)
+    {
         this.client = client;
         backgrounding = new Backgrounding();
         watching = new Watching();
     }
 
     @Override
-    public Ensembleable<byte[]> storingStatIn(Stat stat) {
+    public Ensembleable<byte[]> storingStatIn(Stat stat)
+    {
         this.stat = stat;
         return this;
     }
 
     @Override
-    public BackgroundStatable<Ensembleable<byte[]>> watched() {
+    public BackgroundStatable<Ensembleable<byte[]>> watched()
+    {
         watching = new Watching(true);
         return this;
     }
 
     @Override
-    public GetConfigBuilder usingWatcher(Watcher watcher) {
+    public GetConfigBuilder usingWatcher(Watcher watcher)
+    {
         watching = new Watching(client, watcher);
         return this;
     }
 
     @Override
-    public GetConfigBuilder usingWatcher(final CuratorWatcher watcher) {
+    public GetConfigBuilder usingWatcher(final CuratorWatcher watcher)
+    {
         watching = new Watching(client, watcher);
         return this;
     }
 
     @Override
-    public Ensembleable<byte[]> inBackground() {
+    public Ensembleable<byte[]> inBackground()
+    {
         backgrounding = new Backgrounding();
         return this;
     }
 
     @Override
-    public Ensembleable<byte[]> inBackground(Object context) {
+    public Ensembleable<byte[]> inBackground(Object context)
+    {
         backgrounding = new Backgrounding(context);
         return this;
     }
 
     @Override
-    public Ensembleable<byte[]> inBackground(BackgroundCallback callback) {
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback)
+    {
         backgrounding = new Backgrounding(callback);
         return this;
     }
 
     @Override
-    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context) {
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context)
+    {
         backgrounding = new Backgrounding(callback, context);
         return this;
     }
 
     @Override
-    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Executor executor)
+    {
         backgrounding = new Backgrounding(callback, executor);
         return this;
     }
 
     @Override
-    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor)
+    {
         backgrounding = new Backgrounding(client, callback, context, executor);
         return this;
     }
 
-    private void performBackgroundOperation() {
-        try {
-            client.getZooKeeper().getConfig(watching.getWatcher(),
-                    new AsyncCallback.DataCallback() {
-                        @Override
-                        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
-                            try {
-                                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_CONFIG,
-                                        rc, path, null, ctx, stat, data, null, null, null);
-                                backgrounding.getCallback().processResult(client, event);
-                            } catch (Exception e) {
-                                throw new RuntimeException(e);
-                            }
-                        }
-                    }, backgrounding.getContext());
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     @Override
-    public byte[] forEnsemble() throws Exception {
-        byte[] responseData = null;
+    public byte[] forEnsemble() throws Exception
+    {
         if ( backgrounding.inBackground() )
         {
             client.processBackgroundOperation(new OperationAndData<Void>(this, null, backgrounding.getCallback(), null, backgrounding.getContext()), null);
+            return null;
         }
         else
         {
-            responseData = configInForeground();
+            return configInForeground();
         }
-        return responseData;
     }
 
     @Override
     public void performBackgroundOperation(final OperationAndData<Void> operationAndData) throws Exception
     {
-        final TimeTrace   trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
+        final TimeTrace trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
         AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
         {
             @Override
@@ -158,7 +149,7 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperati
         };
         if ( watching.isWatched() )
         {
-            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
+            client.getZooKeeper().getConfig(true, callback, backgrounding.getContext());
         }
         else
         {
@@ -166,21 +157,30 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperati
         }
     }
 
-
-    private byte[] configInForeground() throws Exception {
-        TimeTrace   trace = client.getZookeeperClient().startTracer("GetConfigBuilderImpl-Foreground");
-        try {
+    private byte[] configInForeground() throws Exception
+    {
+        TimeTrace trace = client.getZookeeperClient().startTracer("GetConfigBuilderImpl-Foreground");
+        try
+        {
             return RetryLoop.callWithRetry
-                    (
-                            client.getZookeeperClient(),
-                            new Callable<byte[]>() {
-                                @Override
-                                public byte[] call() throws Exception {
-                                    return client.getZooKeeper().getConfig(watching.getWatcher(), stat);
-                                }
-                            }
-                    );
-        } finally {
+            (
+                client.getZookeeperClient(),
+                new Callable<byte[]>()
+                {
+                    @Override
+                    public byte[] call() throws Exception
+                    {
+                        if ( watching.isWatched() )
+                        {
+                            return client.getZooKeeper().getConfig(true, stat);
+                        }
+                        return client.getZooKeeper().getConfig(watching.getWatcher(), stat);
+                    }
+                }
+            );
+        }
+        finally
+        {
             trace.commit();
         }
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/3cbc3afd/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
index 15ed13e..761c8ad 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -41,7 +41,7 @@ public class ReconfigBuilderImpl implements
 {
     private final CuratorFrameworkImpl client;
 
-    private Backgrounding backgrounding;
+    private Backgrounding backgrounding = new Backgrounding();
     private Stat responseStat;
     private long fromConfig = -1;
     private List<String> adding;
@@ -56,7 +56,7 @@ public class ReconfigBuilderImpl implements
     @Override
     public byte[] forEnsemble() throws Exception
     {
-        if ( backgrounding != null )
+        if ( backgrounding.inBackground() )
         {
             client.processBackgroundOperation(new OperationAndData<>(this, null, backgrounding.getCallback(), null, backgrounding.getContext()), null);
             return new byte[0];


[10/26] curator git commit: Update project version to 3.0.0-SNAPSHOT.

Posted by ra...@apache.org.
Update project version to 3.0.0-SNAPSHOT.


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

Branch: refs/heads/CURATOR-215
Commit: e11ef78a604531783b5f39b0a9c0c65efef85f94
Parents: 271924b
Author: Ioannis Canellos <io...@gmail.com>
Authored: Thu Nov 6 17:30:29 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 13:00:30 2015 +0300

----------------------------------------------------------------------
 curator-client/pom.xml             | 4 ++--
 curator-examples/pom.xml           | 2 +-
 curator-framework/pom.xml          | 4 ++--
 curator-recipes/pom.xml            | 4 ++--
 curator-test/pom.xml               | 4 ++--
 curator-x-discovery-server/pom.xml | 4 ++--
 curator-x-discovery/pom.xml        | 4 ++--
 curator-x-rpc/pom.xml              | 4 ++--
 pom.xml                            | 2 +-
 9 files changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-client/pom.xml
----------------------------------------------------------------------
diff --git a/curator-client/pom.xml b/curator-client/pom.xml
index 251d2b0..0f3955b 100644
--- a/curator-client/pom.xml
+++ b/curator-client/pom.xml
@@ -24,11 +24,11 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-client</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Curator Client</name>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-examples/pom.xml
----------------------------------------------------------------------
diff --git a/curator-examples/pom.xml b/curator-examples/pom.xml
index 96ea4b1..825ca16 100644
--- a/curator-examples/pom.xml
+++ b/curator-examples/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-examples</artifactId>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-framework/pom.xml
----------------------------------------------------------------------
diff --git a/curator-framework/pom.xml b/curator-framework/pom.xml
index 67f514f..a45ce77 100644
--- a/curator-framework/pom.xml
+++ b/curator-framework/pom.xml
@@ -24,11 +24,11 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-framework</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Curator Framework</name>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-recipes/pom.xml
----------------------------------------------------------------------
diff --git a/curator-recipes/pom.xml b/curator-recipes/pom.xml
index 3ce7d63..9d1d081 100644
--- a/curator-recipes/pom.xml
+++ b/curator-recipes/pom.xml
@@ -24,11 +24,11 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-recipes</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Curator Recipes</name>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-test/pom.xml
----------------------------------------------------------------------
diff --git a/curator-test/pom.xml b/curator-test/pom.xml
index 153db7b..1cbd93c 100644
--- a/curator-test/pom.xml
+++ b/curator-test/pom.xml
@@ -24,11 +24,11 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-test</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
 
     <name>Curator Testing</name>
     <description>Unit testing utilities.</description>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-x-discovery-server/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-discovery-server/pom.xml b/curator-x-discovery-server/pom.xml
index 6035681..352310f 100644
--- a/curator-x-discovery-server/pom.xml
+++ b/curator-x-discovery-server/pom.xml
@@ -24,11 +24,11 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-x-discovery-server</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Curator Service Discovery Server</name>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-x-discovery/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-discovery/pom.xml b/curator-x-discovery/pom.xml
index b557211..e211d89 100644
--- a/curator-x-discovery/pom.xml
+++ b/curator-x-discovery/pom.xml
@@ -24,11 +24,11 @@
     <parent>
         <groupId>org.apache.curator</groupId>
         <artifactId>apache-curator</artifactId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>curator-x-discovery</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Curator Service Discovery</name>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/curator-x-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rpc/pom.xml b/curator-x-rpc/pom.xml
index 7dfcc85..b647294 100644
--- a/curator-x-rpc/pom.xml
+++ b/curator-x-rpc/pom.xml
@@ -22,12 +22,12 @@
     <parent>
         <artifactId>apache-curator</artifactId>
         <groupId>org.apache.curator</groupId>
-        <version>2.7.2-SNAPSHOT</version>
+        <version>3.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>curator-x-rpc</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
 
     <name>Curator RPC Proxy</name>
     <description>A proxy that bridges non-java environments with the Curator framework and recipes</description>

http://git-wip-us.apache.org/repos/asf/curator/blob/e11ef78a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 51e86f6..598a0ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
 
     <groupId>org.apache.curator</groupId>
     <artifactId>apache-curator</artifactId>
-    <version>2.7.2-SNAPSHOT</version>
+    <version>3.0.0-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <name>Apache Curator</name>


[06/26] curator git commit: Merge branch 'CURATOR-160' of github.com:iocanel/curator into CURATOR-160

Posted by ra...@apache.org.
Merge branch 'CURATOR-160' of github.com:iocanel/curator into CURATOR-160


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7ab1b370
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7ab1b370
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7ab1b370

Branch: refs/heads/CURATOR-215
Commit: 7ab1b37030d33f839f1d208a01baf020da57c1a6
Parents: 2c576dc ad4889e
Author: randgalt <ra...@apache.org>
Authored: Thu Nov 13 20:56:13 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Thu Nov 13 20:56:13 2014 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/curator/RetryLoop.java |   3 +-
 .../curator/ensemble/EnsembleListener.java      |  24 +
 .../dynamic/DynamicEnsembleProvider.java        |  61 +++
 .../api/BackgroundStatConfigurable.java         |  24 +
 .../framework/api/BackgroundStatable.java       |  24 +
 .../curator/framework/api/Configurable.java     |  29 ++
 .../curator/framework/api/CuratorEventType.java |  10 +
 .../curator/framework/api/Ensembleable.java     |  24 +
 .../curator/framework/api/GetConfigBuilder.java |   6 +-
 .../api/JoinBackgroundStatConfigurable.java     |  30 ++
 .../apache/curator/framework/api/Joinable.java  |  15 +-
 .../api/LeaveBackgroundStatConfigurable.java    |  30 ++
 .../apache/curator/framework/api/Leaveable.java |  14 +-
 .../curator/framework/api/Memberable.java       |  13 +-
 .../curator/framework/api/ReconfigBuilder.java  |   6 +-
 .../imps/EnsembleServersAndConfig.java          |  52 ++
 .../curator/framework/imps/EnsembleTracker.java | 167 ++++++
 .../framework/imps/GetConfigBuilderImpl.java    | 165 ++++--
 .../framework/imps/ReconfigBuilderImpl.java     | 216 ++++----
 .../framework/imps/TestReconfiguration.java     | 505 +++++++++++--------
 .../org/apache/curator/test/InstanceSpec.java   |   4 +
 .../curator/test/QuorumConfigBuilder.java       |   2 +-
 .../org/apache/curator/test/TestingCluster.java |   1 +
 23 files changed, 1053 insertions(+), 372 deletions(-)
----------------------------------------------------------------------



[22/26] curator git commit: Merge branch 'CURATOR-3.0' into CURATOR-160

Posted by ra...@apache.org.
Merge branch 'CURATOR-3.0' into CURATOR-160


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

Branch: refs/heads/CURATOR-215
Commit: ea2873fb4cdd8de01a1aaf8b8c45e7e113ad712f
Parents: d361594 3016ce2
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 10:40:54 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 10:40:54 2015 -0500

----------------------------------------------------------------------
 .../main/java/discovery/InstanceDetails.java    |  2 +-
 .../contexts/GenericDiscoveryContext.java       |  8 +--
 .../contexts/IntegerDiscoveryContext.java       |  4 +-
 .../server/contexts/StringDiscoveryContext.java |  4 +-
 .../entity/JsonServiceInstanceMarshaller.java   |  6 +-
 .../entity/JsonServiceInstancesMarshaller.java  |  8 +--
 .../entity/JsonServiceNamesMarshaller.java      |  8 +--
 .../discovery/server/rest/DiscoveryContext.java |  4 +-
 .../server/jetty_jersey/ServiceDetails.java     |  4 +-
 curator-x-discovery/pom.xml                     | 14 +----
 .../curator/x/discovery/ServiceInstance.java    |  6 +-
 .../details/JsonInstanceSerializer.java         |  4 +-
 curator-x-rpc/pom.xml                           |  8 +++
 .../java/org/apache/curator/x/rpc/RpcTests.java |  6 +-
 pom.xml                                         | 59 ++++++++++++++------
 src/site/confluence/compatibility.confluence    |  9 +++
 src/site/site.xml                               |  1 +
 17 files changed, 95 insertions(+), 60 deletions(-)
----------------------------------------------------------------------



[12/26] curator git commit: [CURATOR-160] Fix watcher support in GetConfigBuilderImpl.

Posted by ra...@apache.org.
[CURATOR-160] Fix watcher support in GetConfigBuilderImpl.


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

Branch: refs/heads/CURATOR-215
Commit: d4a5c63fd291dfe1315537e6c76f442ae188e8a1
Parents: 0e92b56
Author: Ioannis Canellos <io...@gmail.com>
Authored: Tue Nov 11 12:28:10 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 13:00:30 2015 +0300

----------------------------------------------------------------------
 .../org/apache/curator/framework/imps/GetConfigBuilderImpl.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/d4a5c63f/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
index 54b1862..59a621a 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -158,11 +158,11 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperati
         };
         if ( watching.isWatched() )
         {
-            client.getZooKeeper().getConfig(watching.getWatcher(), callback, backgrounding.getContext());
+            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
         }
         else
         {
-            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
+            client.getZooKeeper().getConfig(watching.getWatcher(), callback, backgrounding.getContext());
         }
     }
 


[08/26] curator git commit: [CURATOR-160] Fix QuorumConfigBuilder to provide a valid server string.

Posted by ra...@apache.org.
[CURATOR-160] Fix QuorumConfigBuilder to provide a valid server string.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/3b5452f2
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/3b5452f2
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/3b5452f2

Branch: refs/heads/CURATOR-215
Commit: 3b5452f2c8c9c72a8298dc85671e71c2add16604
Parents: d4a5c63
Author: Ioannis Canellos <io...@gmail.com>
Authored: Tue Nov 11 12:28:53 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 13:00:30 2015 +0300

----------------------------------------------------------------------
 .../src/main/java/org/apache/curator/test/QuorumConfigBuilder.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/3b5452f2/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java b/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
index 8add08e..02979ee 100644
--- a/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
+++ b/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
@@ -99,7 +99,7 @@ public class QuorumConfigBuilder
         {
             for ( InstanceSpec thisSpec : instanceSpecs )
             {
-                properties.setProperty("server." + thisSpec.getServerId(), String.format("localhost:%d:%d", thisSpec.getQuorumPort(), thisSpec.getElectionPort()));
+                properties.setProperty("server." + thisSpec.getServerId(), String.format("localhost:%d:%d;localhost:%d", thisSpec.getQuorumPort(), thisSpec.getElectionPort(), thisSpec.getPort()));
             }
         }
 


[04/26] curator git commit: [CURATOR-160] Fix QuorumConfigBuilder to provide a valid server string.

Posted by ra...@apache.org.
[CURATOR-160] Fix QuorumConfigBuilder to provide a valid server string.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/019ed279
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/019ed279
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/019ed279

Branch: refs/heads/CURATOR-215
Commit: 019ed27961d900e828deb72c7530f417c1b3f28e
Parents: 0347837
Author: Ioannis Canellos <io...@gmail.com>
Authored: Tue Nov 11 12:28:53 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Tue Nov 11 12:28:53 2014 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/curator/test/QuorumConfigBuilder.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/019ed279/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java b/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
index 8add08e..02979ee 100644
--- a/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
+++ b/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
@@ -99,7 +99,7 @@ public class QuorumConfigBuilder
         {
             for ( InstanceSpec thisSpec : instanceSpecs )
             {
-                properties.setProperty("server." + thisSpec.getServerId(), String.format("localhost:%d:%d", thisSpec.getQuorumPort(), thisSpec.getElectionPort()));
+                properties.setProperty("server." + thisSpec.getServerId(), String.format("localhost:%d:%d;localhost:%d", thisSpec.getQuorumPort(), thisSpec.getElectionPort(), thisSpec.getPort()));
             }
         }
 


[16/26] curator git commit: closes #53 *Moved to PR 76*

Posted by ra...@apache.org.
closes #53 *Moved to PR 76*


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

Branch: refs/heads/CURATOR-215
Commit: d183d02e6b54fb115c5100f1584330ad99702e2b
Parents: ea1a168
Author: randgalt <ra...@apache.org>
Authored: Wed May 6 00:04:33 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed May 6 00:04:33 2015 -0500

----------------------------------------------------------------------

----------------------------------------------------------------------



[17/26] curator git commit: Reworked the reconfig() APIs to be more like the rest of Curator

Posted by ra...@apache.org.
http://git-wip-us.apache.org/repos/asf/curator/blob/aaa04872/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index 44f9d00..297cf9b 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.imps;
 
 import org.apache.curator.ensemble.EnsembleListener;
@@ -27,6 +28,7 @@ import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.test.TestingCluster;
+import org.apache.curator.utils.CloseableUtils;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
@@ -34,7 +36,6 @@ import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.HashMap;
@@ -45,32 +46,33 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 
-public class TestReconfiguration {
-
-    TestingCluster cluster;
-    DynamicEnsembleProvider dynamicEnsembleProvider;
-    WaitOnDelegateListener waitOnDelegateListener;
-    EnsembleTracker ensembleTracker;
-    CuratorFramework client;
+public class TestReconfiguration
+{
+    private TestingCluster cluster;
+    private DynamicEnsembleProvider dynamicEnsembleProvider;
+    private WaitOnDelegateListener waitOnDelegateListener;
+    private EnsembleTracker ensembleTracker;
+    private CuratorFramework client;
 
-    String connectionString1to5;
-    String connectionString2to5;
-    String connectionString3to5;
+    private String connectionString1to5;
+    private String connectionString2to5;
+    private String connectionString3to5;
 
     @BeforeMethod
-    public void setup() throws Exception {
+    public void setup() throws Exception
+    {
         cluster = new TestingCluster(5);
         cluster.start();
 
         connectionString1to5 = cluster.getConnectString();
-        connectionString2to5 = getConnectionString(cluster, 2,3,4,5);
-        connectionString3to5 = getConnectionString(cluster, 3,4,5);
+        connectionString2to5 = getConnectionString(cluster, 2, 3, 4, 5);
+        connectionString3to5 = getConnectionString(cluster, 3, 4, 5);
 
         dynamicEnsembleProvider = new DynamicEnsembleProvider(connectionString1to5);
         client = CuratorFrameworkFactory.builder()
-                .ensembleProvider(dynamicEnsembleProvider)
-                .retryPolicy(new RetryOneTime(1))
-                .build();
+            .ensembleProvider(dynamicEnsembleProvider)
+            .retryPolicy(new RetryOneTime(1))
+            .build();
         client.start();
         client.blockUntilConnected();
 
@@ -84,14 +86,16 @@ public class TestReconfiguration {
     }
 
     @AfterMethod
-    public void tearDown() throws IOException {
-        ensembleTracker.close();
-        client.close();
-        cluster.close();
+    public void tearDown() throws IOException
+    {
+        CloseableUtils.closeQuietly(ensembleTracker);
+        CloseableUtils.closeQuietly(client);
+        CloseableUtils.closeQuietly(cluster);
     }
 
     @Test
-    public void testSyncIncremental() throws Exception {
+    public void testSyncIncremental() throws Exception
+    {
         Stat stat = new Stat();
         byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
         Assert.assertNotNull(bytes);
@@ -132,15 +136,19 @@ public class TestReconfiguration {
     }
 
     @Test
-    public void testAsyncIncremental() throws Exception {
-        final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
-        final BackgroundCallback callback = new BackgroundCallback() {
+    public void testAsyncIncremental() throws Exception
+    {
+        final AtomicReference<byte[]> bytes = new AtomicReference<>();
+        final BackgroundCallback callback = new BackgroundCallback()
+        {
             @Override
-            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
+            {
                 bytes.set(event.getData());
                 //We only need the latch on getConfig.
-                if (event.getContext() != null) {
-                    ((CountDownLatch) event.getContext()).countDown();
+                if ( event.getContext() != null )
+                {
+                    ((CountDownLatch)event.getContext()).countDown();
                 }
             }
 
@@ -155,29 +163,27 @@ public class TestReconfiguration {
         String server1 = getServerString(qv, cluster, 1L);
         String server2 = getServerString(qv, cluster, 2L);
 
-
         //Remove Servers
-        client.reconfig().leaving("1").fromConfig(qv.getVersion()).inBackground(callback).forEnsemble();
+        client.reconfig().inBackground(callback).leaving("1").fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
-        client.reconfig().leaving("2").fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch).leaving("2").fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 3);
 
         //Add Servers
-        client.reconfig().joining("server.2=" + server2).fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch).joining("server.2=" + server2).fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
-
-        client.reconfig().joining("server.1=" + server1).fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch).joining("server.1=" + server1).fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
         qv = getQuorumVerifier(bytes.get());
@@ -185,7 +191,8 @@ public class TestReconfiguration {
     }
 
     @Test
-    public void testSyncNonIncremental() throws Exception {
+    public void testSyncNonIncremental() throws Exception
+    {
         Stat stat = new Stat();
         byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
         Assert.assertNotNull(bytes);
@@ -199,11 +206,11 @@ public class TestReconfiguration {
 
         //Remove Servers
         bytes = client.reconfig()
-                .withMembers("server.2=" + server2,
-                        "server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
+            .adding("server.2=" + server2,
+                "server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
@@ -211,10 +218,10 @@ public class TestReconfiguration {
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
 
         bytes = client.reconfig()
-                .withMembers("server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
+            .adding("server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
 
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 3);
@@ -224,11 +231,11 @@ public class TestReconfiguration {
 
         //Add Servers
         bytes = client.reconfig()
-                .withMembers("server.2=" + server2,
-                        "server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
+            .adding("server.2=" + server2,
+                "server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
@@ -236,12 +243,12 @@ public class TestReconfiguration {
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
 
         bytes = client.reconfig()
-                .withMembers("server.1=" + server1,
-                        "server.2=" + server2,
-                        "server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
+            .adding("server.1=" + server1,
+                "server.2=" + server2,
+                "server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 5);
 
@@ -250,13 +257,16 @@ public class TestReconfiguration {
     }
 
     @Test
-    public void testAsyncNonIncremental() throws Exception {
-        final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
-        final BackgroundCallback callback = new BackgroundCallback() {
+    public void testAsyncNonIncremental() throws Exception
+    {
+        final AtomicReference<byte[]> bytes = new AtomicReference<>();
+        final BackgroundCallback callback = new BackgroundCallback()
+        {
             @Override
-            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
+            {
                 bytes.set(event.getData());
-                ((CountDownLatch) event.getContext()).countDown();
+                ((CountDownLatch)event.getContext()).countDown();
             }
 
         };
@@ -274,86 +284,97 @@ public class TestReconfiguration {
         String server5 = getServerString(qv, cluster, 5L);
 
         //Remove Servers
-        client.reconfig()
-                .withMembers("server.2=" + server2,
-                        "server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch)
+            .adding("server.2=" + server2,
+                "server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
-        client.reconfig()
-                .withMembers("server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch)
+            .adding("server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 3);
 
         //Add Servers
-        client.reconfig()
-                .withMembers("server.2=" + server2,
-                        "server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch)
+            .adding("server.2=" + server2,
+                "server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
-        client.reconfig()
-                .withMembers("server.1=" + server1,
-                        "server.2=" + server2,
-                        "server.3=" + server3,
-                        "server.4=" + server4,
-                        "server.5=" + server5)
-                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
+        client.reconfig().inBackground(callback, latch)
+            .adding("server.1=" + server1,
+                "server.2=" + server2,
+                "server.3=" + server3,
+                "server.4=" + server4,
+                "server.5=" + server5)
+            .fromConfig(qv.getVersion()).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 5);
     }
 
-
-    static QuorumVerifier getQuorumVerifier(byte[] bytes) throws Exception {
+    static QuorumVerifier getQuorumVerifier(byte[] bytes) throws Exception
+    {
         Properties properties = new Properties();
         properties.load(new StringReader(new String(bytes)));
         return new QuorumMaj(properties);
     }
 
-    static InstanceSpec getInstance(TestingCluster cluster, int id) {
-        for (InstanceSpec spec : cluster.getInstances()) {
-            if (spec.getServerId() == id) {
+    static InstanceSpec getInstance(TestingCluster cluster, int id)
+    {
+        for ( InstanceSpec spec : cluster.getInstances() )
+        {
+            if ( spec.getServerId() == id )
+            {
                 return spec;
             }
         }
         throw new IllegalStateException("InstanceSpec with id:" + id + " not found");
     }
 
-    static String getServerString(QuorumVerifier qv, TestingCluster cluster, long id) throws Exception {
+    static String getServerString(QuorumVerifier qv, TestingCluster cluster, long id) throws Exception
+    {
         String str = qv.getAllMembers().get(id).toString();
         //check if connection string is already there.
-        if (str.contains(";")) {
+        if ( str.contains(";") )
+        {
             return str;
-        } else {
-            return str + ";" + getInstance(cluster, (int) id).getConnectString();
+        }
+        else
+        {
+            return str + ";" + getInstance(cluster, (int)id).getConnectString();
         }
     }
 
-    static String getConnectionString(TestingCluster cluster, long... ids) throws Exception {
+    static String getConnectionString(TestingCluster cluster, long... ids) throws Exception
+    {
         StringBuilder sb = new StringBuilder();
-        Map<Long, InstanceSpec> specs = new HashMap<Long, InstanceSpec>();
-        for (InstanceSpec spec : cluster.getInstances()) {
-            specs.put(new Long(spec.getServerId()), spec);
+        Map<Long, InstanceSpec> specs = new HashMap<>();
+        for ( InstanceSpec spec : cluster.getInstances() )
+        {
+            specs.put((long)spec.getServerId(), spec);
         }
-        for (long id : ids) {
-            if (sb.length() != 0) {
+        for ( long id : ids )
+        {
+            if ( sb.length() != 0 )
+            {
                 sb.append(",");
             }
             sb.append(specs.get(id).getConnectString());
@@ -362,27 +383,34 @@ public class TestReconfiguration {
     }
 
     //Simple EnsembleListener that can wait until the delegate handles the event.
-    private static class WaitOnDelegateListener implements EnsembleListener {
+    private static class WaitOnDelegateListener implements EnsembleListener
+    {
         private CountDownLatch latch = new CountDownLatch(1);
 
         private final EnsembleListener delegate;
 
-        private WaitOnDelegateListener(EnsembleListener delegate) {
+        private WaitOnDelegateListener(EnsembleListener delegate)
+        {
             this.delegate = delegate;
         }
 
         @Override
-        public void connectionStringUpdated(String connectionString) {
+        public void connectionStringUpdated(String connectionString)
+        {
             delegate.connectionStringUpdated(connectionString);
             latch.countDown();
         }
 
-        public void waitForEvent() throws InterruptedException, TimeoutException {
-            if (latch.await(5, TimeUnit.SECONDS)) {
+        public void waitForEvent() throws InterruptedException, TimeoutException
+        {
+            if ( latch.await(5, TimeUnit.SECONDS) )
+            {
                 latch = new CountDownLatch(1);
-            } else {
+            }
+            else
+            {
                 throw new TimeoutException("Failed to receive event in time.");
             }
         }
-    };
+    }
 }
\ No newline at end of file


[23/26] curator git commit: Updated CuratorEvent doc

Posted by ra...@apache.org.
Updated CuratorEvent doc


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

Branch: refs/heads/CURATOR-215
Commit: 7536465533787ce3e0a71dbe2b8ba1068012f8c0
Parents: ea2873f
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 10:47:30 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 10:47:30 2015 -0500

----------------------------------------------------------------------
 curator-framework/src/site/confluence/index.confluence | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/75364655/curator-framework/src/site/confluence/index.confluence
----------------------------------------------------------------------
diff --git a/curator-framework/src/site/confluence/index.confluence b/curator-framework/src/site/confluence/index.confluence
index cf92514..bb1807e 100644
--- a/curator-framework/src/site/confluence/index.confluence
+++ b/curator-framework/src/site/confluence/index.confluence
@@ -55,9 +55,9 @@ CuratorFramework instance using the addListener() method. The listener implement
 |eventReceived()|A background operation has completed or a watch has triggered. Examine the given event for details|
 <td>clientClosedDueToError()|An unrecoverable error has occurred. The CuratorFramework instance has been shut down|
 
-h3. ClientEvent
-The ClientEvent object is a super\-set POJO that can hold every type of background notification and triggered watch. The useful fields of
-ClientEvent depend on the type of event which is exposed via the getType() method.
+h3. CuratorEvent
+The CuratorEvent object is a super\-set POJO that can hold every type of background notification and triggered watch. The useful fields of
+CuratorEvent depend on the type of event which is exposed via the getType() method.
 
 ||Event Type||Event Methods||
 |CREATE|getResultCode() and getPath()|
@@ -66,7 +66,12 @@ ClientEvent depend on the type of event which is exposed via the getType() metho
 |GET_DATA|getResultCode(), getPath(), getStat() and getData()|
 |SET_DATA|getResultCode(), getPath() and getStat()|
 |CHILDREN|getResultCode(), getPath(), getStat(), getChildren()|
+|SYNC|getResultCode(), getStat()|
+|GET_ACL|getResultCode(), getACLList()|
+|SET_ACL|getResultCode()|
 |WATCHED|getWatchedEvent()|
+|GET_CONFIG|getResultCode(), getData()|
+|RECONFIG|getResultCode(), getData()|
 
 h2. Namespaces
 Because a ZooKeeper cluster is a shared environment, it's vital that a namespace convention is


[20/26] curator git commit: Moved EnsembleTracker and did some refactoring

Posted by ra...@apache.org.
Moved EnsembleTracker and did some refactoring


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/5e6cd0e9
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/5e6cd0e9
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/5e6cd0e9

Branch: refs/heads/CURATOR-215
Commit: 5e6cd0e9137297a264c34339f52dd737d50a8982
Parents: 3cbc3af
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 09:47:04 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 09:47:04 2015 -0500

----------------------------------------------------------------------
 .../framework/ensemble/EnsembleTracker.java     | 191 ++++++++++++++++++
 .../curator/framework/imps/EnsembleTracker.java | 196 -------------------
 .../framework/imps/TestReconfiguration.java     |   1 +
 3 files changed, 192 insertions(+), 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5e6cd0e9/curator-framework/src/main/java/org/apache/curator/framework/ensemble/EnsembleTracker.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/ensemble/EnsembleTracker.java b/curator-framework/src/main/java/org/apache/curator/framework/ensemble/EnsembleTracker.java
new file mode 100644
index 0000000..375e1f0
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/ensemble/EnsembleTracker.java
@@ -0,0 +1,191 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.curator.framework.ensemble;
+
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.listen.ListenerContainer;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.ByteArrayInputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tracks changes to the ensemble and notifies registered {@link org.apache.curator.ensemble.EnsembleListener} instances.
+ */
+public class EnsembleTracker implements Closeable
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final CuratorFramework client;
+    private final AtomicReference<State> state = new AtomicReference<>(State.LATENT);
+    private final ListenerContainer<EnsembleListener> listeners = new ListenerContainer<>();
+    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener()
+    {
+        @Override
+        public void stateChanged(CuratorFramework client, ConnectionState newState)
+        {
+            if ( (newState == ConnectionState.CONNECTED) || (newState == ConnectionState.RECONNECTED) )
+            {
+                try
+                {
+                    reset();
+                }
+                catch ( Exception e )
+                {
+                    log.error("Trying to reset after reconnection", e);
+                }
+            }
+        }
+    };
+
+    private final CuratorWatcher watcher = new CuratorWatcher()
+    {
+        @Override
+        public void process(WatchedEvent event) throws Exception
+        {
+            if ( event.getType() == Watcher.Event.EventType.NodeDataChanged )
+            {
+                reset();
+            }
+        }
+    };
+
+    private enum State
+    {
+        LATENT,
+        STARTED,
+        CLOSED
+    }
+
+    private final BackgroundCallback backgroundCallback = new BackgroundCallback()
+    {
+        @Override
+        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
+        {
+            processBackgroundResult(event);
+        }
+    };
+
+    public EnsembleTracker(CuratorFramework client)
+    {
+        this.client = client;
+    }
+
+    public void start() throws Exception
+    {
+        Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once");
+        client.getConnectionStateListenable().addListener(connectionStateListener);
+        reset();
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+        if ( state.compareAndSet(State.STARTED, State.CLOSED) )
+        {
+            listeners.clear();
+        }
+        client.getConnectionStateListenable().removeListener(connectionStateListener);
+    }
+
+    /**
+     * Return the ensemble listenable
+     *
+     * @return listenable
+     */
+    public ListenerContainer<EnsembleListener> getListenable()
+    {
+        Preconditions.checkState(state.get() != State.CLOSED, "Closed");
+
+        return listeners;
+    }
+
+    private void reset() throws Exception
+    {
+        client.getConfig().usingWatcher(watcher).inBackground(backgroundCallback).forEnsemble();
+    }
+
+    private void processBackgroundResult(CuratorEvent event) throws Exception
+    {
+        switch ( event.getType() )
+        {
+            case GET_CONFIG:
+            {
+                if ( event.getResultCode() == KeeperException.Code.OK.intValue() )
+                {
+                    processConfigData(event.getData());
+                }
+            }
+        }
+    }
+
+    private void processConfigData(byte[] data) throws Exception
+    {
+        Properties properties = new Properties();
+        properties.load(new ByteArrayInputStream(data));
+        QuorumVerifier qv = new QuorumMaj(properties);
+        StringBuilder sb = new StringBuilder();
+        for ( QuorumPeer.QuorumServer server : qv.getAllMembers().values() )
+        {
+            if ( sb.length() != 0 )
+            {
+                sb.append(",");
+            }
+            sb.append(server.clientAddr.getAddress().getHostAddress()).append(":").append(server.clientAddr.getPort());
+        }
+
+        final String connectionString = sb.toString();
+        listeners.forEach
+            (
+                new Function<EnsembleListener, Void>()
+                {
+                    @Override
+                    public Void apply(EnsembleListener listener)
+                    {
+                        try
+                        {
+                            listener.connectionStringUpdated(connectionString);
+                        }
+                        catch ( Exception e )
+                        {
+                            log.error("Calling listener", e);
+                        }
+                        return null;
+                    }
+                }
+            );
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/5e6cd0e9/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
deleted file mode 100644
index 6688848..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.curator.framework.imps;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import org.apache.curator.ensemble.EnsembleListener;
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.api.BackgroundCallback;
-import org.apache.curator.framework.api.CuratorEvent;
-import org.apache.curator.framework.api.CuratorWatcher;
-import org.apache.curator.framework.listen.ListenerContainer;
-import org.apache.curator.framework.state.ConnectionState;
-import org.apache.curator.framework.state.ConnectionStateListener;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
-import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
-import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.ByteArrayInputStream;
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Tracks changes to the ensemble and notifies registered {@link org.apache.curator.ensemble.EnsembleListener} instances.
- */
-public class EnsembleTracker implements Closeable
-{
-    private final Logger log = LoggerFactory.getLogger(getClass());
-    private final CuratorFramework client;
-    private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
-    private final ListenerContainer<EnsembleListener> listeners = new ListenerContainer<EnsembleListener>();
-    private final AtomicBoolean isConnected = new AtomicBoolean(true);
-    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener()
-    {
-        @Override
-        public void stateChanged(CuratorFramework client, ConnectionState newState)
-        {
-            if ( (newState == ConnectionState.CONNECTED) || (newState == ConnectionState.RECONNECTED) )
-            {
-                if ( isConnected.compareAndSet(false, true) )
-                {
-                    try
-                    {
-                        reset();
-                    }
-                    catch ( Exception e )
-                    {
-                        log.error("Trying to reset after reconnection", e);
-                    }
-                }
-            }
-            else
-            {
-                isConnected.set(false);
-            }
-        }
-    };
-
-    private final CuratorWatcher watcher = new CuratorWatcher()
-    {
-        @Override
-        public void process(WatchedEvent event) throws Exception
-        {
-            reset();
-        }
-    };
-
-    private enum State
-    {
-        LATENT,
-        STARTED,
-        CLOSED
-    }
-
-    private final BackgroundCallback backgroundCallback = new BackgroundCallback()
-    {
-        @Override
-        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
-        {
-            processBackgroundResult(event);
-        }
-    };
-
-    public EnsembleTracker(CuratorFramework client)
-    {
-        this.client = client;
-    }
-
-    public void start() throws Exception
-    {
-        Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once");
-        client.getConnectionStateListenable().addListener(connectionStateListener);
-        reset();
-    }
-
-    @Override
-    public void close() throws IOException
-    {
-        if ( state.compareAndSet(State.STARTED, State.CLOSED) )
-        {
-            listeners.clear();
-        }
-        client.getConnectionStateListenable().removeListener(connectionStateListener);
-    }
-
-    /**
-     * Return the ensemble listenable
-     *
-     * @return listenable
-     */
-    public ListenerContainer<EnsembleListener> getListenable()
-    {
-        Preconditions.checkState(state.get() != State.CLOSED, "Closed");
-
-        return listeners;
-    }
-
-    private void reset() throws Exception
-    {
-        client.getConfig().usingWatcher(watcher).inBackground(backgroundCallback).forEnsemble();
-    }
-
-    private void processBackgroundResult(CuratorEvent event) throws Exception
-    {
-        switch ( event.getType() )
-        {
-        case GET_CONFIG:
-        {
-            if ( event.getResultCode() == KeeperException.Code.OK.intValue() )
-            {
-                processConfigData(event.getData());
-            }
-        }
-        }
-    }
-
-    private void processConfigData(byte[] data) throws Exception
-    {
-        Properties properties = new Properties();
-        properties.load(new ByteArrayInputStream(data));
-        QuorumVerifier qv = new QuorumMaj(properties);
-        StringBuilder sb = new StringBuilder();
-        for ( QuorumPeer.QuorumServer server : qv.getAllMembers().values() )
-        {
-            if ( sb.length() != 0 )
-            {
-                sb.append(",");
-            }
-            sb.append(server.clientAddr.getAddress().getHostAddress()).append(":").append(server.clientAddr.getPort());
-        }
-
-        final String connectionString = sb.toString();
-        listeners.forEach
-            (
-                new Function<EnsembleListener, Void>()
-                {
-                    @Override
-                    public Void apply(EnsembleListener listener)
-                    {
-                        try
-                        {
-                            listener.connectionStringUpdated(connectionString);
-                        }
-                        catch ( Exception e )
-                        {
-                            log.error("Calling listener", e);
-                        }
-                        return null;
-                    }
-                }
-            );
-    }
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/5e6cd0e9/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index 297cf9b..133e690 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -25,6 +25,7 @@ import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.api.BackgroundCallback;
 import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.ensemble.EnsembleTracker;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.InstanceSpec;
 import org.apache.curator.test.TestingCluster;


[02/26] curator git commit: [CURATOR-160] Add builders and dsl for ZooKeeper's config and reconfig methods.

Posted by ra...@apache.org.
[CURATOR-160] Add builders and dsl for ZooKeeper's config and reconfig methods.


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

Branch: refs/heads/CURATOR-215
Commit: f37580ec562d8f9467ca037d7d1c740ffdfe40c9
Parents: d4883a8
Author: Ioannis Canellos <io...@gmail.com>
Authored: Thu Nov 6 17:34:47 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Mon Nov 10 13:41:19 2014 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/curator/RetryLoop.java |   3 +-
 .../curator/framework/CuratorFramework.java     |  12 +
 .../api/BackgroundStatConfigurable.java         |  24 ++
 .../framework/api/BackgroundStatable.java       |  24 ++
 .../curator/framework/api/Configurable.java     |  29 ++
 .../curator/framework/api/CuratorEventType.java |  10 +
 .../curator/framework/api/Ensembleable.java     |  24 ++
 .../curator/framework/api/GetConfigBuilder.java |  27 ++
 .../api/JoinBackgroundStatConfigurable.java     |  30 ++
 .../apache/curator/framework/api/Joinable.java  |  31 ++
 .../api/LeaveBackgroundStatConfigurable.java    |  30 ++
 .../apache/curator/framework/api/Leaveable.java |  30 ++
 .../curator/framework/api/Memberable.java       |  31 ++
 .../curator/framework/api/ReconfigBuilder.java  |  26 ++
 .../framework/imps/CuratorFrameworkImpl.java    |  10 +
 .../imps/EnsembleServersAndConfig.java          |  52 ++++
 .../framework/imps/GetConfigBuilderImpl.java    | 187 ++++++++++++
 .../framework/imps/ReconfigBuilderImpl.java     | 216 +++++++++++++
 .../framework/imps/TestReconfiguration.java     | 305 +++++++++++++++++++
 .../org/apache/curator/test/InstanceSpec.java   |   4 +
 .../org/apache/curator/test/TestingCluster.java |   1 +
 21 files changed, 1105 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-client/src/main/java/org/apache/curator/RetryLoop.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/RetryLoop.java b/curator-client/src/main/java/org/apache/curator/RetryLoop.java
index 6b66e82..065ebef 100644
--- a/curator-client/src/main/java/org/apache/curator/RetryLoop.java
+++ b/curator-client/src/main/java/org/apache/curator/RetryLoop.java
@@ -150,7 +150,8 @@ public class RetryLoop
         return (rc == KeeperException.Code.CONNECTIONLOSS.intValue()) ||
             (rc == KeeperException.Code.OPERATIONTIMEOUT.intValue()) ||
             (rc == KeeperException.Code.SESSIONMOVED.intValue()) ||
-            (rc == KeeperException.Code.SESSIONEXPIRED.intValue());
+            (rc == KeeperException.Code.SESSIONEXPIRED.intValue()) ||
+            (rc == KeeperException.Code.NEWCONFIGNOQUORUM.intValue());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
index 9c23ddb..181e4e8 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
@@ -122,6 +122,18 @@ public interface CuratorFramework extends Closeable
     public SetACLBuilder setACL();
 
     /**
+     * Start a reconfig builder
+     * @return builder object
+     */
+    public ReconfigBuilder reconfig();
+
+    /**
+     * Start a getConfig builder
+     * @return
+     */
+    public GetConfigBuilder getConfig();
+
+    /**
      * Start a transaction builder
      *
      * @return builder object

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
new file mode 100644
index 0000000..e46ba89
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface BackgroundStatConfigurable<T> extends
+    BackgroundStatable<Configurable<T>>,
+    Configurable<T> {
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java
new file mode 100644
index 0000000..77c4e96
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface BackgroundStatable<T> extends
+    Backgroundable<T>,
+    Statable<T> {
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
new file mode 100644
index 0000000..a47f9d0
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Configurable<T> {
+
+    /**
+     * Sets the configuration version to use.
+     * @param config The version of the configuration.
+     * @throws Exception
+     */
+    Ensembleable<T> fromConfig(long config) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
index 684d11b..50e9195 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
@@ -69,6 +69,16 @@ public enum CuratorEventType
     SET_ACL,
 
     /**
+     * Corresponds to {@link CuratorFramework#getConfig()}
+     */
+    GET_CONFIG,
+
+    /**
+     * Corresponds to {@link CuratorFramework#reconfig()}
+     */
+    RECONFIG,
+
+    /**
      * Corresponds to {@link Watchable#usingWatcher(Watcher)} or {@link Watchable#watched()}
      */
     WATCHED,

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java
new file mode 100644
index 0000000..c8a82fe
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Ensembleable<T> {
+
+    T forEnsemble() throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
new file mode 100644
index 0000000..c2fdf6c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface GetConfigBuilder extends
+        Watchable<BackgroundStatable<Ensembleable<byte[]>>>,
+        BackgroundStatable<Ensembleable<byte[]>>,
+        Ensembleable<byte[]> {
+}
+
+

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
new file mode 100644
index 0000000..fb18c0c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinBackgroundStatConfigurable extends
+        Joinable<BackgroundStatConfigurable<byte[]>>,
+        BackgroundStatConfigurable<byte[]> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
new file mode 100644
index 0000000..dde5b1c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Joinable<T> {
+
+    /**
+     * Adds one or more servers to joining the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param server The server to joining.
+     * @return this.
+     */
+    T joining(String... server);
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
new file mode 100644
index 0000000..196ffca
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An non-incremental reconfiguration builder.
+ * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface LeaveBackgroundStatConfigurable extends
+        Leaveable<BackgroundStatConfigurable<byte[]>>,
+        BackgroundStatConfigurable<byte[]> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
new file mode 100644
index 0000000..a3c3358
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Leaveable<T> {
+
+    /**
+     * Sets one or more servers to leaving the ensemble.
+     * @param server The server ids.
+     * @return this
+     */
+    T leaving(String... server);
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
new file mode 100644
index 0000000..6ef54c1
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+
+public interface Memberable<T> {
+
+    /**
+     * Sets one or more members that are meant to be part of the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param server The server to add as a member of the ensemble.
+     * @return this.
+     */
+    T withMembers(String... server);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
new file mode 100644
index 0000000..96ebdf7
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface ReconfigBuilder extends
+        Joinable<LeaveBackgroundStatConfigurable>,
+        Leaveable<JoinBackgroundStatConfigurable>,
+        Memberable<BackgroundStatConfigurable<byte[]>> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index cf38e21..53f0a61 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -413,6 +413,16 @@ public class CuratorFrameworkImpl implements CuratorFramework
     }
 
     @Override
+    public ReconfigBuilder reconfig() {
+        return new ReconfigBuilderImpl(this);
+    }
+
+    @Override
+    public GetConfigBuilder getConfig() {
+        return new GetConfigBuilderImpl(this);
+    }
+
+    @Override
     public CuratorTransaction inTransaction()
     {
         Preconditions.checkState(getState() == CuratorFrameworkState.STARTED, "instance must be started before calling this method");

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
new file mode 100644
index 0000000..df78aa7
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import java.util.Collections;
+import java.util.List;
+
+class EnsembleServersAndConfig {
+    private final List<String> joiningServers;
+    private final List<String> leavingServers;
+    private final List<String> members;
+    private final long config;
+
+    EnsembleServersAndConfig(List<String> joiningServers, List<String> leavingServers, List<String> members, long config) {
+        this.joiningServers = joiningServers.isEmpty() ? null : Collections.unmodifiableList(joiningServers);
+        this.leavingServers = leavingServers.isEmpty() ? null : Collections.unmodifiableList(leavingServers);
+        this.members = members.isEmpty() ? null : Collections.unmodifiableList(members);
+        this.config = config;
+    }
+
+    public List<String> getJoiningServers() {
+        return joiningServers;
+    }
+
+    public List<String> getLeavingServers() {
+        return leavingServers;
+    }
+
+    public List<String> getMembers() {
+        return members;
+    }
+
+    public long getConfig() {
+        return config;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
new file mode 100644
index 0000000..54b1862
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.RetryLoop;
+import org.apache.curator.TimeTrace;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.BackgroundStatable;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorEventType;
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.api.Ensembleable;
+import org.apache.curator.framework.api.GetConfigBuilder;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executor;
+
+public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperation<Void> {
+
+    private final CuratorFrameworkImpl client;
+
+    private Backgrounding backgrounding;
+    private Watching watching;
+    private Stat stat;
+
+    public GetConfigBuilderImpl(CuratorFrameworkImpl client) {
+        this.client = client;
+        backgrounding = new Backgrounding();
+        watching = new Watching();
+    }
+
+    @Override
+    public Ensembleable<byte[]> storingStatIn(Stat stat) {
+        this.stat = new Stat();
+        return this;
+    }
+
+    @Override
+    public BackgroundStatable<Ensembleable<byte[]>> watched() {
+        watching = new Watching(true);
+        return this;
+    }
+
+    @Override
+    public GetConfigBuilder usingWatcher(Watcher watcher) {
+        watching = new Watching(client, watcher);
+        return this;
+    }
+
+    @Override
+    public GetConfigBuilder usingWatcher(final CuratorWatcher watcher) {
+        watching = new Watching(client, watcher);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground() {
+        backgrounding = new Backgrounding();
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(Object context) {
+        backgrounding = new Backgrounding(context);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback) {
+        backgrounding = new Backgrounding(callback);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context) {
+        backgrounding = new Backgrounding(callback, context);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
+        backgrounding = new Backgrounding(callback, executor);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
+        backgrounding = new Backgrounding(client, callback, context, executor);
+        return this;
+    }
+
+    private void performBackgroundOperation() {
+        try {
+            client.getZooKeeper().getConfig(watching.getWatcher(),
+                    new AsyncCallback.DataCallback() {
+                        @Override
+                        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+                            try {
+                                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_CONFIG,
+                                        rc, path, null, ctx, stat, data, null, null, null);
+                                backgrounding.getCallback().processResult(client, event);
+                            } catch (Exception e) {
+                                throw new RuntimeException(e);
+                            }
+                        }
+                    }, backgrounding.getContext());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public byte[] forEnsemble() throws Exception {
+        byte[] responseData = null;
+        if ( backgrounding.inBackground() )
+        {
+            client.processBackgroundOperation(new OperationAndData<Void>(this, null, backgrounding.getCallback(), null, backgrounding.getContext()), null);
+        }
+        else
+        {
+            responseData = configInForeground();
+        }
+        return responseData;
+    }
+
+    @Override
+    public void performBackgroundOperation(final OperationAndData<Void> operationAndData) throws Exception
+    {
+        final TimeTrace   trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
+        AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
+        {
+            @Override
+            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat)
+            {
+                trace.commit();
+                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_CONFIG, rc, path, null, ctx, stat, data, null, null, null);
+                client.processBackgroundOperation(operationAndData, event);
+            }
+        };
+        if ( watching.isWatched() )
+        {
+            client.getZooKeeper().getConfig(watching.getWatcher(), callback, backgrounding.getContext());
+        }
+        else
+        {
+            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
+        }
+    }
+
+
+    private byte[] configInForeground() throws Exception {
+        TimeTrace   trace = client.getZookeeperClient().startTracer("GetConfigBuilderImpl-Foreground");
+        try {
+            return RetryLoop.callWithRetry
+                    (
+                            client.getZookeeperClient(),
+                            new Callable<byte[]>() {
+                                @Override
+                                public byte[] call() throws Exception {
+                                    return client.getZooKeeper().getConfig(watching.getWatcher(), stat);
+                                }
+                            }
+                    );
+        } finally {
+            trace.commit();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
new file mode 100644
index 0000000..7a33297
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.RetryLoop;
+import org.apache.curator.TimeTrace;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.BackgroundStatConfigurable;
+import org.apache.curator.framework.api.Configurable;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorEventType;
+import org.apache.curator.framework.api.Ensembleable;
+import org.apache.curator.framework.api.JoinBackgroundStatConfigurable;
+import org.apache.curator.framework.api.LeaveBackgroundStatConfigurable;
+import org.apache.curator.framework.api.ReconfigBuilder;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executor;
+
+public class ReconfigBuilderImpl implements ReconfigBuilder {
+
+    private final CuratorFrameworkImpl client;
+
+    public ReconfigBuilderImpl(CuratorFrameworkImpl client) {
+        this.client = client;
+    }
+
+    private static class ReconfigBuilderBase implements BackgroundStatConfigurable<byte[]>, Ensembleable<byte[]>, BackgroundOperation<EnsembleServersAndConfig> {
+
+        final CuratorFrameworkImpl client;
+        final List<String> joiningServers = new LinkedList<String>();
+        final List<String> leavingServers = new LinkedList<String>();
+        final List<String> members = new LinkedList<String>();
+        Backgrounding backgrounding;
+        Stat stat;
+        long config;
+
+        private ReconfigBuilderBase(CuratorFrameworkImpl client) {
+            this.client = client;
+            backgrounding = new Backgrounding();
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground() {
+            backgrounding = new Backgrounding();
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(Object context) {
+            backgrounding = new Backgrounding(context);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback) {
+            backgrounding = new Backgrounding(callback);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback, Object context) {
+            backgrounding = new Backgrounding(callback, context);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
+            backgrounding = new Backgrounding(callback, executor);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
+            backgrounding = new Backgrounding(client, callback, context, executor);
+            return this;
+        }
+
+        @Override
+        public Ensembleable<byte[]> fromConfig(long config) throws Exception {
+            this.config = config;
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> storingStatIn(Stat stat) {
+            this.stat = stat;
+            return this;
+        }
+
+        @Override
+        public byte[] forEnsemble() throws Exception {
+            if (backgrounding.inBackground()) {
+                client.processBackgroundOperation(new OperationAndData<EnsembleServersAndConfig>(this,
+                        new EnsembleServersAndConfig(joiningServers, leavingServers, members, config),
+                        backgrounding.getCallback(), null, backgrounding.getContext()), null);
+                return new byte[0];
+            } else {
+                return ensembleInForeground();
+            }
+        }
+
+        private byte[] ensembleInForeground() throws Exception {
+            TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Foreground");
+            byte[] responseData = RetryLoop.callWithRetry
+                    (
+                            client.getZookeeperClient(),
+                            new Callable<byte[]>() {
+                                @Override
+                                public byte[] call() throws Exception {
+                                    return client.getZooKeeper().reconfig(
+                                            joiningServers.isEmpty() ? null : joiningServers,
+                                            leavingServers.isEmpty() ? null : leavingServers,
+                                            members.isEmpty() ? null : members,
+                                            config,
+                                            stat
+                                    );
+                                }
+                            }
+                    );
+            trace.commit();
+            return responseData;
+        }
+
+        @Override
+        public void performBackgroundOperation(final OperationAndData<EnsembleServersAndConfig> operationAndData) throws Exception {
+            final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background");
+            AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() {
+                @Override
+                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+                    trace.commit();
+                    CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, data, null, null, null);
+                    client.processBackgroundOperation(operationAndData, event);
+                }
+            };
+            client.getZooKeeper().reconfig(
+                    operationAndData.getData().getJoiningServers(),
+                    operationAndData.getData().getLeavingServers(),
+                    operationAndData.getData().getMembers(),
+                    operationAndData.getData().getConfig(),
+                    callback,
+                    operationAndData.getContext()
+            );
+
+        }
+    }
+
+    private static class JoinReconfigBuilder extends ReconfigBuilderBase implements JoinBackgroundStatConfigurable {
+
+        private JoinReconfigBuilder(CuratorFrameworkImpl client) {
+            super(client);
+        }
+
+        @Override
+        public BackgroundStatConfigurable<byte[]> joining(String... servers) {
+            joiningServers.addAll(Arrays.asList(servers));
+            return this;
+        }
+    }
+
+    private static class LeaveReconfigBuilder extends ReconfigBuilderBase implements LeaveBackgroundStatConfigurable {
+
+        private LeaveReconfigBuilder(CuratorFrameworkImpl client) {
+            super(client);
+        }
+
+        @Override
+        public BackgroundStatConfigurable<byte[]> leaving(String... servers) {
+            leavingServers.addAll(Arrays.asList(servers));
+            return this;
+        }
+    }
+
+
+    @Override
+    public LeaveBackgroundStatConfigurable joining(String... servers) {
+        LeaveReconfigBuilder builder = new LeaveReconfigBuilder(client);
+        builder.joiningServers.addAll(Arrays.asList(servers));
+        return builder;
+    }
+
+    @Override
+    public JoinBackgroundStatConfigurable leaving(String... servers) {
+        JoinReconfigBuilder builder = new JoinReconfigBuilder(client);
+        builder.leavingServers.addAll(Arrays.asList(servers));
+        return builder;
+    }
+
+    @Override
+    public BackgroundStatConfigurable<byte[]> withMembers(String... servers) {
+        ReconfigBuilderBase builder = new ReconfigBuilderBase(client);
+        builder.members.addAll(Arrays.asList(servers));
+        return builder;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
new file mode 100644
index 0000000..e8896ae
--- /dev/null
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -0,0 +1,305 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.InstanceSpec;
+import org.apache.curator.test.TestingCluster;
+import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class TestReconfiguration {
+
+    TestingCluster cluster;
+
+    @BeforeMethod
+    public void setup() throws Exception {
+        cluster = new TestingCluster(5);
+        cluster.start();
+    }
+
+    @AfterMethod
+    public void tearDown() throws IOException {
+        cluster.close();
+    }
+
+    @Test
+    public void testSyncIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            Stat stat = new Stat();
+            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+            Assert.assertNotNull(bytes);
+            QuorumVerifier qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+
+            //Remove Servers
+            bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testAsyncIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+            final BackgroundCallback callback = new BackgroundCallback() {
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                    bytes.set(event.getData());
+                    ((CountDownLatch)event.getContext()).countDown();
+                }
+
+            };
+
+            CountDownLatch latch = new CountDownLatch(1);
+            client.getConfig().inBackground(callback, latch).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            Assert.assertNotNull(bytes.get());
+            QuorumVerifier qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+
+
+            //Remove Servers
+            latch = new CountDownLatch(1);
+            client.reconfig().leaving("1").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            latch = new CountDownLatch(1);
+            client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testSyncNonIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            Stat stat = new Stat();
+            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+            Assert.assertNotNull(bytes);
+            QuorumVerifier qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+            String server3 = getServerString(qv, cluster, 3L);
+            String server4 = getServerString(qv, cluster, 4L);
+            String server5 = getServerString(qv, cluster, 5L);
+
+            //Remove Servers
+            bytes = client.reconfig()
+                    .withMembers("server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig()
+                    .withMembers("server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            bytes = client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testAsyncNonIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+            final BackgroundCallback callback = new BackgroundCallback() {
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                    bytes.set(event.getData());
+                    ((CountDownLatch)event.getContext()).countDown();
+                }
+
+            };
+
+            CountDownLatch latch = new CountDownLatch(1);
+            client.getConfig().inBackground(callback, latch).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            Assert.assertNotNull(bytes.get());
+            QuorumVerifier qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+            String server3 = getServerString(qv, cluster, 3L);
+            String server4 = getServerString(qv, cluster, 4L);
+            String server5 = getServerString(qv, cluster, 5L);
+
+            //Remove Servers
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+            .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+
+    static QuorumVerifier getQuorumVerifier(byte[] bytes) throws Exception {
+        Properties properties = new Properties();
+        properties.load(new StringReader(new String(bytes)));
+        return new QuorumMaj(properties);
+    }
+
+    static InstanceSpec getInstance(TestingCluster cluster, int id) {
+        for (InstanceSpec spec : cluster.getInstances()) {
+            if (spec.getServerId() == id) {
+                return spec;
+            }
+        }
+        throw new IllegalStateException("InstanceSpec with id:" + id + " not found");
+    }
+
+    static String getServerString(QuorumVerifier qv, TestingCluster cluster, long id) throws Exception {
+        String str = qv.getAllMembers().get(id).toString();
+        //check if connection string is already there.
+        if (str.contains(";")) {
+            return str;
+        } else {
+            return str + ";" + getInstance(cluster, (int) id).getConnectString();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
index b39a949..6d495df 100644
--- a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
+++ b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
@@ -70,6 +70,10 @@ public class InstanceSpec
     private final int tickTime;
     private final int maxClientCnxns;
 
+    public static void reset() {
+        nextServerId.set(1);
+    }
+
     public static InstanceSpec newInstanceSpec()
     {
         return new InstanceSpec(null, -1, -1, -1, true, -1, -1, -1);

http://git-wip-us.apache.org/repos/asf/curator/blob/f37580ec/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java b/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
index cd86b72..f6bdbd8 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
@@ -249,6 +249,7 @@ public class TestingCluster implements Closeable
 
     private static Map<InstanceSpec, Collection<InstanceSpec>> makeSpecs(int instanceQty)
     {
+        InstanceSpec.reset();
         ImmutableList.Builder<InstanceSpec> builder = ImmutableList.builder();
         for ( int i = 0; i < instanceQty; ++i )
         {


[07/26] curator git commit: Upgrade to ZooKeeper 3.5.0-alpha.

Posted by ra...@apache.org.
Upgrade to ZooKeeper 3.5.0-alpha.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/271924bc
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/271924bc
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/271924bc

Branch: refs/heads/CURATOR-215
Commit: 271924bc42cb881688f8eba9d2313f091ac55241
Parents: 6a56c51
Author: Ioannis Canellos <io...@gmail.com>
Authored: Thu Nov 6 16:53:09 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 12:58:20 2015 +0300

----------------------------------------------------------------------
 .../framework/recipes/leader/ChaosMonkeyCnxnFactory.java      | 7 -------
 pom.xml                                                       | 2 +-
 2 files changed, 1 insertion(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/271924bc/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/ChaosMonkeyCnxnFactory.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/ChaosMonkeyCnxnFactory.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/ChaosMonkeyCnxnFactory.java
index 5f10c5e..ce5b23d 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/ChaosMonkeyCnxnFactory.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/ChaosMonkeyCnxnFactory.java
@@ -59,13 +59,6 @@ public class ChaosMonkeyCnxnFactory extends NIOServerCnxnFactory
         super.startup(new ChaosMonkeyZookeeperServer(zks));
     }
 
-    /**
-     * Build a connection with a Chaos Monkey ZookeeperServer
-     */
-    protected NIOServerCnxn createConnection(SocketChannel sock, SelectionKey sk) throws IOException
-    {
-        return new NIOServerCnxn(zkServer, sock, sk, this);
-    }
 
     public static class ChaosMonkeyZookeeperServer extends ZooKeeperServer
     {

http://git-wip-us.apache.org/repos/asf/curator/blob/271924bc/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index be3ea33..51e86f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -82,7 +82,7 @@
         <jetty-version>6.1.26</jetty-version>
         <scannotation-version>1.0.2</scannotation-version>
         <resteasy-jaxrs-version>2.3.0.GA</resteasy-jaxrs-version>
-        <zookeeper-version>3.4.6</zookeeper-version>
+        <zookeeper-version>3.5.0-alpha</zookeeper-version>
         <guava-version>16.0.1</guava-version>
         <testng-version>6.8.8</testng-version>
         <swift-version>0.12.0</swift-version>


[03/26] curator git commit: [CURATOR-160] Fix watcher support in GetConfigBuilderImpl.

Posted by ra...@apache.org.
[CURATOR-160] Fix watcher support in GetConfigBuilderImpl.


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

Branch: refs/heads/CURATOR-215
Commit: 034783706ecea85934cc00c0d2f8fb8737e46886
Parents: f37580e
Author: Ioannis Canellos <io...@gmail.com>
Authored: Tue Nov 11 12:28:10 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Tue Nov 11 12:28:10 2014 +0200

----------------------------------------------------------------------
 .../org/apache/curator/framework/imps/GetConfigBuilderImpl.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/03478370/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
index 54b1862..59a621a 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -158,11 +158,11 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperati
         };
         if ( watching.isWatched() )
         {
-            client.getZooKeeper().getConfig(watching.getWatcher(), callback, backgrounding.getContext());
+            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
         }
         else
         {
-            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
+            client.getZooKeeper().getConfig(watching.getWatcher(), callback, backgrounding.getContext());
         }
     }
 


[15/26] curator git commit: Merge branch 'CURATOR-160' of github.com:iocanel/curator into CURATOR-160

Posted by ra...@apache.org.
Merge branch 'CURATOR-160' of github.com:iocanel/curator into CURATOR-160

Conflicts:
	curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
	curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
	curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
	curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
	curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java


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

Branch: refs/heads/CURATOR-215
Commit: ea1a1684198ca2fa317486a881d5f48466fbf8f8
Parents: 36b9ed8 625441b
Author: randgalt <ra...@apache.org>
Authored: Wed May 6 00:00:37 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed May 6 00:00:37 2015 -0500

----------------------------------------------------------------------
 .../api/BackgroundStatConfigEnsembleable.java   |  24 +++++
 .../api/BackgroundStatEnsembleable.java         |  24 +++++
 .../curator/framework/api/Configurable.java     |   2 +-
 .../JoinBackgroundStatConfigEnsembleable.java   |  30 ++++++
 .../LeaveBackgroundStatConfigEnsembleable.java  |  30 ++++++
 .../curator/framework/api/ReconfigBuilder.java  |   6 +-
 .../framework/imps/CreateBuilderImpl.java       |  14 +--
 .../framework/imps/DeleteBuilderImpl.java       | 103 +++++++++----------
 .../framework/imps/GetConfigBuilderImpl.java    |   2 +-
 .../framework/imps/ReconfigBuilderImpl.java     |  48 ++++-----
 .../framework/imps/TestReconfiguration.java     |  32 +++---
 11 files changed, 204 insertions(+), 111 deletions(-)
----------------------------------------------------------------------



[13/26] curator git commit: [CURATOR-160] Add builders and dsl for ZooKeeper's config and reconfig methods.

Posted by ra...@apache.org.
[CURATOR-160] Add builders and dsl for ZooKeeper's config and reconfig methods.


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

Branch: refs/heads/CURATOR-215
Commit: 0e92b562dfb3ac0ec6bfae82b5690473f5ca7594
Parents: e11ef78
Author: Ioannis Canellos <io...@gmail.com>
Authored: Thu Nov 6 17:34:47 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 13:00:30 2015 +0300

----------------------------------------------------------------------
 .../main/java/org/apache/curator/RetryLoop.java |   3 +-
 .../curator/framework/CuratorFramework.java     |  12 +
 .../api/BackgroundStatConfigurable.java         |  24 ++
 .../framework/api/BackgroundStatable.java       |  24 ++
 .../curator/framework/api/Configurable.java     |  29 ++
 .../curator/framework/api/CuratorEventType.java |  10 +
 .../curator/framework/api/Ensembleable.java     |  24 ++
 .../curator/framework/api/GetConfigBuilder.java |  27 ++
 .../api/JoinBackgroundStatConfigurable.java     |  30 ++
 .../apache/curator/framework/api/Joinable.java  |  31 ++
 .../api/LeaveBackgroundStatConfigurable.java    |  30 ++
 .../apache/curator/framework/api/Leaveable.java |  30 ++
 .../curator/framework/api/Memberable.java       |  31 ++
 .../curator/framework/api/ReconfigBuilder.java  |  26 ++
 .../framework/imps/CuratorFrameworkImpl.java    |  10 +
 .../imps/EnsembleServersAndConfig.java          |  52 ++++
 .../framework/imps/GetConfigBuilderImpl.java    | 187 ++++++++++++
 .../framework/imps/ReconfigBuilderImpl.java     | 216 +++++++++++++
 .../framework/imps/TestReconfiguration.java     | 305 +++++++++++++++++++
 .../org/apache/curator/test/InstanceSpec.java   |   4 +
 .../org/apache/curator/test/TestingCluster.java |   1 +
 21 files changed, 1105 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-client/src/main/java/org/apache/curator/RetryLoop.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/RetryLoop.java b/curator-client/src/main/java/org/apache/curator/RetryLoop.java
index 6b66e82..065ebef 100644
--- a/curator-client/src/main/java/org/apache/curator/RetryLoop.java
+++ b/curator-client/src/main/java/org/apache/curator/RetryLoop.java
@@ -150,7 +150,8 @@ public class RetryLoop
         return (rc == KeeperException.Code.CONNECTIONLOSS.intValue()) ||
             (rc == KeeperException.Code.OPERATIONTIMEOUT.intValue()) ||
             (rc == KeeperException.Code.SESSIONMOVED.intValue()) ||
-            (rc == KeeperException.Code.SESSIONEXPIRED.intValue());
+            (rc == KeeperException.Code.SESSIONEXPIRED.intValue()) ||
+            (rc == KeeperException.Code.NEWCONFIGNOQUORUM.intValue());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
index 9c23ddb..181e4e8 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java
@@ -122,6 +122,18 @@ public interface CuratorFramework extends Closeable
     public SetACLBuilder setACL();
 
     /**
+     * Start a reconfig builder
+     * @return builder object
+     */
+    public ReconfigBuilder reconfig();
+
+    /**
+     * Start a getConfig builder
+     * @return
+     */
+    public GetConfigBuilder getConfig();
+
+    /**
      * Start a transaction builder
      *
      * @return builder object

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
new file mode 100644
index 0000000..e46ba89
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface BackgroundStatConfigurable<T> extends
+    BackgroundStatable<Configurable<T>>,
+    Configurable<T> {
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java
new file mode 100644
index 0000000..77c4e96
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface BackgroundStatable<T> extends
+    Backgroundable<T>,
+    Statable<T> {
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
new file mode 100644
index 0000000..a47f9d0
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Configurable<T> {
+
+    /**
+     * Sets the configuration version to use.
+     * @param config The version of the configuration.
+     * @throws Exception
+     */
+    Ensembleable<T> fromConfig(long config) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
index 684d11b..50e9195 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/CuratorEventType.java
@@ -69,6 +69,16 @@ public enum CuratorEventType
     SET_ACL,
 
     /**
+     * Corresponds to {@link CuratorFramework#getConfig()}
+     */
+    GET_CONFIG,
+
+    /**
+     * Corresponds to {@link CuratorFramework#reconfig()}
+     */
+    RECONFIG,
+
+    /**
      * Corresponds to {@link Watchable#usingWatcher(Watcher)} or {@link Watchable#watched()}
      */
     WATCHED,

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java
new file mode 100644
index 0000000..c8a82fe
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Ensembleable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Ensembleable<T> {
+
+    T forEnsemble() throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
new file mode 100644
index 0000000..c2fdf6c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/GetConfigBuilder.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface GetConfigBuilder extends
+        Watchable<BackgroundStatable<Ensembleable<byte[]>>>,
+        BackgroundStatable<Ensembleable<byte[]>>,
+        Ensembleable<byte[]> {
+}
+
+

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
new file mode 100644
index 0000000..fb18c0c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinBackgroundStatConfigurable extends
+        Joinable<BackgroundStatConfigurable<byte[]>>,
+        BackgroundStatConfigurable<byte[]> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
new file mode 100644
index 0000000..dde5b1c
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Joinable.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Joinable<T> {
+
+    /**
+     * Adds one or more servers to joining the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param server The server to joining.
+     * @return this.
+     */
+    T joining(String... server);
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
new file mode 100644
index 0000000..196ffca
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An non-incremental reconfiguration builder.
+ * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface LeaveBackgroundStatConfigurable extends
+        Leaveable<BackgroundStatConfigurable<byte[]>>,
+        BackgroundStatConfigurable<byte[]> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
new file mode 100644
index 0000000..a3c3358
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Leaveable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface Leaveable<T> {
+
+    /**
+     * Sets one or more servers to leaving the ensemble.
+     * @param server The server ids.
+     * @return this
+     */
+    T leaving(String... server);
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
new file mode 100644
index 0000000..6ef54c1
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Memberable.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+
+public interface Memberable<T> {
+
+    /**
+     * Sets one or more members that are meant to be part of the ensemble.
+     * The expected format is server.[id]=[hostname]:[peer port]:[election port]:[type];[client port]
+     * @param server The server to add as a member of the ensemble.
+     * @return this.
+     */
+    T withMembers(String... server);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
new file mode 100644
index 0000000..96ebdf7
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface ReconfigBuilder extends
+        Joinable<LeaveBackgroundStatConfigurable>,
+        Leaveable<JoinBackgroundStatConfigurable>,
+        Memberable<BackgroundStatConfigurable<byte[]>> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index 5034ed9..b9b9c31 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -398,6 +398,16 @@ public class CuratorFrameworkImpl implements CuratorFramework
     }
 
     @Override
+    public ReconfigBuilder reconfig() {
+        return new ReconfigBuilderImpl(this);
+    }
+
+    @Override
+    public GetConfigBuilder getConfig() {
+        return new GetConfigBuilderImpl(this);
+    }
+
+    @Override
     public CuratorTransaction inTransaction()
     {
         Preconditions.checkState(getState() == CuratorFrameworkState.STARTED, "instance must be started before calling this method");

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
new file mode 100644
index 0000000..df78aa7
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleServersAndConfig.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import java.util.Collections;
+import java.util.List;
+
+class EnsembleServersAndConfig {
+    private final List<String> joiningServers;
+    private final List<String> leavingServers;
+    private final List<String> members;
+    private final long config;
+
+    EnsembleServersAndConfig(List<String> joiningServers, List<String> leavingServers, List<String> members, long config) {
+        this.joiningServers = joiningServers.isEmpty() ? null : Collections.unmodifiableList(joiningServers);
+        this.leavingServers = leavingServers.isEmpty() ? null : Collections.unmodifiableList(leavingServers);
+        this.members = members.isEmpty() ? null : Collections.unmodifiableList(members);
+        this.config = config;
+    }
+
+    public List<String> getJoiningServers() {
+        return joiningServers;
+    }
+
+    public List<String> getLeavingServers() {
+        return leavingServers;
+    }
+
+    public List<String> getMembers() {
+        return members;
+    }
+
+    public long getConfig() {
+        return config;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
new file mode 100644
index 0000000..54b1862
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -0,0 +1,187 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.RetryLoop;
+import org.apache.curator.TimeTrace;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.BackgroundStatable;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorEventType;
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.api.Ensembleable;
+import org.apache.curator.framework.api.GetConfigBuilder;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executor;
+
+public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperation<Void> {
+
+    private final CuratorFrameworkImpl client;
+
+    private Backgrounding backgrounding;
+    private Watching watching;
+    private Stat stat;
+
+    public GetConfigBuilderImpl(CuratorFrameworkImpl client) {
+        this.client = client;
+        backgrounding = new Backgrounding();
+        watching = new Watching();
+    }
+
+    @Override
+    public Ensembleable<byte[]> storingStatIn(Stat stat) {
+        this.stat = new Stat();
+        return this;
+    }
+
+    @Override
+    public BackgroundStatable<Ensembleable<byte[]>> watched() {
+        watching = new Watching(true);
+        return this;
+    }
+
+    @Override
+    public GetConfigBuilder usingWatcher(Watcher watcher) {
+        watching = new Watching(client, watcher);
+        return this;
+    }
+
+    @Override
+    public GetConfigBuilder usingWatcher(final CuratorWatcher watcher) {
+        watching = new Watching(client, watcher);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground() {
+        backgrounding = new Backgrounding();
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(Object context) {
+        backgrounding = new Backgrounding(context);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback) {
+        backgrounding = new Backgrounding(callback);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context) {
+        backgrounding = new Backgrounding(callback, context);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
+        backgrounding = new Backgrounding(callback, executor);
+        return this;
+    }
+
+    @Override
+    public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
+        backgrounding = new Backgrounding(client, callback, context, executor);
+        return this;
+    }
+
+    private void performBackgroundOperation() {
+        try {
+            client.getZooKeeper().getConfig(watching.getWatcher(),
+                    new AsyncCallback.DataCallback() {
+                        @Override
+                        public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+                            try {
+                                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_CONFIG,
+                                        rc, path, null, ctx, stat, data, null, null, null);
+                                backgrounding.getCallback().processResult(client, event);
+                            } catch (Exception e) {
+                                throw new RuntimeException(e);
+                            }
+                        }
+                    }, backgrounding.getContext());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public byte[] forEnsemble() throws Exception {
+        byte[] responseData = null;
+        if ( backgrounding.inBackground() )
+        {
+            client.processBackgroundOperation(new OperationAndData<Void>(this, null, backgrounding.getCallback(), null, backgrounding.getContext()), null);
+        }
+        else
+        {
+            responseData = configInForeground();
+        }
+        return responseData;
+    }
+
+    @Override
+    public void performBackgroundOperation(final OperationAndData<Void> operationAndData) throws Exception
+    {
+        final TimeTrace   trace = client.getZookeeperClient().startTracer("GetDataBuilderImpl-Background");
+        AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback()
+        {
+            @Override
+            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat)
+            {
+                trace.commit();
+                CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.GET_CONFIG, rc, path, null, ctx, stat, data, null, null, null);
+                client.processBackgroundOperation(operationAndData, event);
+            }
+        };
+        if ( watching.isWatched() )
+        {
+            client.getZooKeeper().getConfig(watching.getWatcher(), callback, backgrounding.getContext());
+        }
+        else
+        {
+            client.getZooKeeper().getConfig(false, callback, backgrounding.getContext());
+        }
+    }
+
+
+    private byte[] configInForeground() throws Exception {
+        TimeTrace   trace = client.getZookeeperClient().startTracer("GetConfigBuilderImpl-Foreground");
+        try {
+            return RetryLoop.callWithRetry
+                    (
+                            client.getZookeeperClient(),
+                            new Callable<byte[]>() {
+                                @Override
+                                public byte[] call() throws Exception {
+                                    return client.getZooKeeper().getConfig(watching.getWatcher(), stat);
+                                }
+                            }
+                    );
+        } finally {
+            trace.commit();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
new file mode 100644
index 0000000..7a33297
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -0,0 +1,216 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.RetryLoop;
+import org.apache.curator.TimeTrace;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.BackgroundStatConfigurable;
+import org.apache.curator.framework.api.Configurable;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorEventType;
+import org.apache.curator.framework.api.Ensembleable;
+import org.apache.curator.framework.api.JoinBackgroundStatConfigurable;
+import org.apache.curator.framework.api.LeaveBackgroundStatConfigurable;
+import org.apache.curator.framework.api.ReconfigBuilder;
+import org.apache.zookeeper.AsyncCallback;
+import org.apache.zookeeper.data.Stat;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executor;
+
+public class ReconfigBuilderImpl implements ReconfigBuilder {
+
+    private final CuratorFrameworkImpl client;
+
+    public ReconfigBuilderImpl(CuratorFrameworkImpl client) {
+        this.client = client;
+    }
+
+    private static class ReconfigBuilderBase implements BackgroundStatConfigurable<byte[]>, Ensembleable<byte[]>, BackgroundOperation<EnsembleServersAndConfig> {
+
+        final CuratorFrameworkImpl client;
+        final List<String> joiningServers = new LinkedList<String>();
+        final List<String> leavingServers = new LinkedList<String>();
+        final List<String> members = new LinkedList<String>();
+        Backgrounding backgrounding;
+        Stat stat;
+        long config;
+
+        private ReconfigBuilderBase(CuratorFrameworkImpl client) {
+            this.client = client;
+            backgrounding = new Backgrounding();
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground() {
+            backgrounding = new Backgrounding();
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(Object context) {
+            backgrounding = new Backgrounding(context);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback) {
+            backgrounding = new Backgrounding(callback);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback, Object context) {
+            backgrounding = new Backgrounding(callback, context);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
+            backgrounding = new Backgrounding(callback, executor);
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
+            backgrounding = new Backgrounding(client, callback, context, executor);
+            return this;
+        }
+
+        @Override
+        public Ensembleable<byte[]> fromConfig(long config) throws Exception {
+            this.config = config;
+            return this;
+        }
+
+        @Override
+        public Configurable<byte[]> storingStatIn(Stat stat) {
+            this.stat = stat;
+            return this;
+        }
+
+        @Override
+        public byte[] forEnsemble() throws Exception {
+            if (backgrounding.inBackground()) {
+                client.processBackgroundOperation(new OperationAndData<EnsembleServersAndConfig>(this,
+                        new EnsembleServersAndConfig(joiningServers, leavingServers, members, config),
+                        backgrounding.getCallback(), null, backgrounding.getContext()), null);
+                return new byte[0];
+            } else {
+                return ensembleInForeground();
+            }
+        }
+
+        private byte[] ensembleInForeground() throws Exception {
+            TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Foreground");
+            byte[] responseData = RetryLoop.callWithRetry
+                    (
+                            client.getZookeeperClient(),
+                            new Callable<byte[]>() {
+                                @Override
+                                public byte[] call() throws Exception {
+                                    return client.getZooKeeper().reconfig(
+                                            joiningServers.isEmpty() ? null : joiningServers,
+                                            leavingServers.isEmpty() ? null : leavingServers,
+                                            members.isEmpty() ? null : members,
+                                            config,
+                                            stat
+                                    );
+                                }
+                            }
+                    );
+            trace.commit();
+            return responseData;
+        }
+
+        @Override
+        public void performBackgroundOperation(final OperationAndData<EnsembleServersAndConfig> operationAndData) throws Exception {
+            final TimeTrace trace = client.getZookeeperClient().startTracer("ReconfigBuilderImpl-Background");
+            AsyncCallback.DataCallback callback = new AsyncCallback.DataCallback() {
+                @Override
+                public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
+                    trace.commit();
+                    CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.RECONFIG, rc, path, null, ctx, stat, data, null, null, null);
+                    client.processBackgroundOperation(operationAndData, event);
+                }
+            };
+            client.getZooKeeper().reconfig(
+                    operationAndData.getData().getJoiningServers(),
+                    operationAndData.getData().getLeavingServers(),
+                    operationAndData.getData().getMembers(),
+                    operationAndData.getData().getConfig(),
+                    callback,
+                    operationAndData.getContext()
+            );
+
+        }
+    }
+
+    private static class JoinReconfigBuilder extends ReconfigBuilderBase implements JoinBackgroundStatConfigurable {
+
+        private JoinReconfigBuilder(CuratorFrameworkImpl client) {
+            super(client);
+        }
+
+        @Override
+        public BackgroundStatConfigurable<byte[]> joining(String... servers) {
+            joiningServers.addAll(Arrays.asList(servers));
+            return this;
+        }
+    }
+
+    private static class LeaveReconfigBuilder extends ReconfigBuilderBase implements LeaveBackgroundStatConfigurable {
+
+        private LeaveReconfigBuilder(CuratorFrameworkImpl client) {
+            super(client);
+        }
+
+        @Override
+        public BackgroundStatConfigurable<byte[]> leaving(String... servers) {
+            leavingServers.addAll(Arrays.asList(servers));
+            return this;
+        }
+    }
+
+
+    @Override
+    public LeaveBackgroundStatConfigurable joining(String... servers) {
+        LeaveReconfigBuilder builder = new LeaveReconfigBuilder(client);
+        builder.joiningServers.addAll(Arrays.asList(servers));
+        return builder;
+    }
+
+    @Override
+    public JoinBackgroundStatConfigurable leaving(String... servers) {
+        JoinReconfigBuilder builder = new JoinReconfigBuilder(client);
+        builder.leavingServers.addAll(Arrays.asList(servers));
+        return builder;
+    }
+
+    @Override
+    public BackgroundStatConfigurable<byte[]> withMembers(String... servers) {
+        ReconfigBuilderBase builder = new ReconfigBuilderBase(client);
+        builder.members.addAll(Arrays.asList(servers));
+        return builder;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
new file mode 100644
index 0000000..e8896ae
--- /dev/null
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -0,0 +1,305 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.InstanceSpec;
+import org.apache.curator.test.TestingCluster;
+import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class TestReconfiguration {
+
+    TestingCluster cluster;
+
+    @BeforeMethod
+    public void setup() throws Exception {
+        cluster = new TestingCluster(5);
+        cluster.start();
+    }
+
+    @AfterMethod
+    public void tearDown() throws IOException {
+        cluster.close();
+    }
+
+    @Test
+    public void testSyncIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            Stat stat = new Stat();
+            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+            Assert.assertNotNull(bytes);
+            QuorumVerifier qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+
+            //Remove Servers
+            bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testAsyncIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+            final BackgroundCallback callback = new BackgroundCallback() {
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                    bytes.set(event.getData());
+                    ((CountDownLatch)event.getContext()).countDown();
+                }
+
+            };
+
+            CountDownLatch latch = new CountDownLatch(1);
+            client.getConfig().inBackground(callback, latch).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            Assert.assertNotNull(bytes.get());
+            QuorumVerifier qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+
+
+            //Remove Servers
+            latch = new CountDownLatch(1);
+            client.reconfig().leaving("1").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            latch = new CountDownLatch(1);
+            client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testSyncNonIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            Stat stat = new Stat();
+            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+            Assert.assertNotNull(bytes);
+            QuorumVerifier qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+            String server3 = getServerString(qv, cluster, 3L);
+            String server4 = getServerString(qv, cluster, 4L);
+            String server5 = getServerString(qv, cluster, 5L);
+
+            //Remove Servers
+            bytes = client.reconfig()
+                    .withMembers("server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig()
+                    .withMembers("server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            bytes = client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            bytes = client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+            qv = getQuorumVerifier(bytes);
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testAsyncNonIncremental() throws Exception {
+        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
+        client.start();
+        client.blockUntilConnected();
+        try {
+            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+            final BackgroundCallback callback = new BackgroundCallback() {
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                    bytes.set(event.getData());
+                    ((CountDownLatch)event.getContext()).countDown();
+                }
+
+            };
+
+            CountDownLatch latch = new CountDownLatch(1);
+            client.getConfig().inBackground(callback, latch).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            Assert.assertNotNull(bytes.get());
+            QuorumVerifier qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+            String server1 = getServerString(qv, cluster, 1L);
+            String server2 = getServerString(qv, cluster, 2L);
+            String server3 = getServerString(qv, cluster, 3L);
+            String server4 = getServerString(qv, cluster, 4L);
+            String server5 = getServerString(qv, cluster, 5L);
+
+            //Remove Servers
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+            .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+            //Add Servers
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 4);
+            latch = new CountDownLatch(1);
+            client.reconfig()
+                    .withMembers("server.1=" + server1,
+                            "server.2=" + server2,
+                            "server.3=" + server3,
+                            "server.4=" + server4,
+                            "server.5=" + server5)
+                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+            latch.await(5, TimeUnit.SECONDS);
+            qv = getQuorumVerifier(bytes.get());
+            Assert.assertEquals(qv.getAllMembers().size(), 5);
+        } finally {
+            client.close();
+        }
+    }
+
+
+    static QuorumVerifier getQuorumVerifier(byte[] bytes) throws Exception {
+        Properties properties = new Properties();
+        properties.load(new StringReader(new String(bytes)));
+        return new QuorumMaj(properties);
+    }
+
+    static InstanceSpec getInstance(TestingCluster cluster, int id) {
+        for (InstanceSpec spec : cluster.getInstances()) {
+            if (spec.getServerId() == id) {
+                return spec;
+            }
+        }
+        throw new IllegalStateException("InstanceSpec with id:" + id + " not found");
+    }
+
+    static String getServerString(QuorumVerifier qv, TestingCluster cluster, long id) throws Exception {
+        String str = qv.getAllMembers().get(id).toString();
+        //check if connection string is already there.
+        if (str.contains(";")) {
+            return str;
+        } else {
+            return str + ";" + getInstance(cluster, (int) id).getConnectString();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
index b39a949..6d495df 100644
--- a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
+++ b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
@@ -70,6 +70,10 @@ public class InstanceSpec
     private final int tickTime;
     private final int maxClientCnxns;
 
+    public static void reset() {
+        nextServerId.set(1);
+    }
+
     public static InstanceSpec newInstanceSpec()
     {
         return new InstanceSpec(null, -1, -1, -1, true, -1, -1, -1);

http://git-wip-us.apache.org/repos/asf/curator/blob/0e92b562/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java b/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
index cd86b72..f6bdbd8 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingCluster.java
@@ -249,6 +249,7 @@ public class TestingCluster implements Closeable
 
     private static Map<InstanceSpec, Collection<InstanceSpec>> makeSpecs(int instanceQty)
     {
+        InstanceSpec.reset();
         ImmutableList.Builder<InstanceSpec> builder = ImmutableList.builder();
         for ( int i = 0; i < instanceQty; ++i )
         {


[14/26] curator git commit: Merge branch 'CURATOR-3.0' into CURATOR-160

Posted by ra...@apache.org.
Merge branch 'CURATOR-3.0' into CURATOR-160


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/36b9ed88
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/36b9ed88
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/36b9ed88

Branch: refs/heads/CURATOR-215
Commit: 36b9ed888bb6178dfb1a5a1c90927f6e9bc8d3c9
Parents: 7ab1b37 6d5136e
Author: randgalt <ra...@apache.org>
Authored: Tue May 5 23:55:43 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 5 23:55:43 2015 -0500

----------------------------------------------------------------------
 .../org/apache/curator/utils/ThreadUtils.java   |   5 +
 .../java/org/apache/curator/utils/ZKPaths.java  | 103 ++++-
 .../org/apache/curator/utils/TestZKPaths.java   |  11 +
 .../main/java/discovery/InstanceDetails.java    |   2 +-
 .../org/apache/curator/framework/AuthInfo.java  |  51 +++
 .../framework/CuratorFrameworkFactory.java      | 127 ++++--
 .../framework/imps/CreateBuilderImpl.java       |  16 +-
 .../framework/imps/CuratorFrameworkImpl.java    | 116 +++---
 .../imps/CuratorTempFrameworkImpl.java          |  10 +-
 .../framework/imps/DeleteBuilderImpl.java       | 103 ++---
 .../curator/framework/imps/NamespaceFacade.java |   8 +-
 .../curator/framework/imps/NamespaceImpl.java   |   6 +-
 .../curator/framework/imps/TestFramework.java   | 349 ++++++++++------
 .../framework/imps/TestFrameworkBackground.java |   4 +-
 .../framework/imps/TestFrameworkEdges.java      |  85 +++-
 .../framework/recipes/cache/TreeCache.java      |   2 +-
 .../framework/recipes/locks/ChildReaper.java    | 157 +++++++-
 .../locks/InterProcessReadWriteLock.java        |   3 +-
 .../recipes/locks/InterProcessSemaphoreV2.java  |   7 +
 .../curator/framework/recipes/locks/Reaper.java |  65 ++-
 .../recipes/nodes/PersistentEphemeralNode.java  |  54 ++-
 .../framework/client/TestBackgroundStates.java  |  14 +-
 ...estResetConnectionWithBackgroundFailure.java |   8 +-
 .../framework/recipes/cache/TestTreeCache.java  |  43 ++
 .../recipes/leader/TestLeaderSelector.java      |  67 ++++
 .../recipes/locks/TestChildReaper.java          | 248 +++++++++++-
 .../locks/TestInterProcessSemaphore.java        |  40 ++
 .../framework/recipes/locks/TestReaper.java     |  90 ++++-
 .../nodes/TestPersistentEphemeralNode.java      | 125 +++++-
 .../TestPersistentEphemeralNodeListener.java    |   9 +-
 .../contexts/GenericDiscoveryContext.java       |   8 +-
 .../contexts/IntegerDiscoveryContext.java       |   4 +-
 .../server/contexts/StringDiscoveryContext.java |   4 +-
 .../entity/JsonServiceInstanceMarshaller.java   |   6 +-
 .../entity/JsonServiceInstancesMarshaller.java  |   8 +-
 .../entity/JsonServiceNamesMarshaller.java      |   8 +-
 .../discovery/server/rest/DiscoveryContext.java |   4 +-
 .../server/jetty_jersey/ServiceDetails.java     |   4 +-
 curator-x-discovery/pom.xml                     |  14 +-
 .../x/discovery/ServiceDiscoveryBuilder.java    |  45 ++-
 .../curator/x/discovery/ServiceInstance.java    |   6 +-
 .../details/JsonInstanceSerializer.java         |   4 +-
 .../discovery/details/ServiceDiscoveryImpl.java | 245 ++++++++----
 .../x/discovery/TestServiceDiscovery.java       | 266 -------------
 .../discovery/details/TestServiceDiscovery.java | 394 +++++++++++++++++++
 .../discovery/details/TestWatchedInstances.java |  94 +++++
 curator-x-rpc/pom.xml                           |  19 +
 .../java/org/apache/curator/x/rpc/RpcTests.java |   6 +-
 pom.xml                                         |  87 +---
 49 files changed, 2311 insertions(+), 843 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/36b9ed88/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------


[25/26] curator git commit: fixed inBackground() calls

Posted by ra...@apache.org.
fixed inBackground() calls


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

Branch: refs/heads/CURATOR-215
Commit: fc45a4ec8ab3f5e00c3ec04f03a80e5dda555f5e
Parents: 5c8833c
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 12:40:08 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 12:40:08 2015 -0500

----------------------------------------------------------------------
 .../org/apache/curator/framework/imps/GetConfigBuilderImpl.java    | 2 +-
 .../org/apache/curator/framework/imps/ReconfigBuilderImpl.java     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/fc45a4ec/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
index b65f863..c9bbbf6 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -80,7 +80,7 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperati
     @Override
     public Ensembleable<byte[]> inBackground()
     {
-        backgrounding = new Backgrounding();
+        backgrounding = new Backgrounding(true);
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/fc45a4ec/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
index 761c8ad..f4dba90 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -203,7 +203,7 @@ public class ReconfigBuilderImpl implements
     @Override
     public ReconfigBuilderMain inBackground()
     {
-        backgrounding = new Backgrounding();
+        backgrounding = new Backgrounding(true);
         return this;
     }
 


[24/26] curator git commit: escape underscores

Posted by ra...@apache.org.
escape underscores


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/5c8833ca
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/5c8833ca
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/5c8833ca

Branch: refs/heads/CURATOR-215
Commit: 5c8833ca727cc92e43bedb3694d611890ca9d9ce
Parents: 7536465
Author: randgalt <ra...@apache.org>
Authored: Sat May 9 10:52:33 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Sat May 9 10:52:33 2015 -0500

----------------------------------------------------------------------
 curator-framework/src/site/confluence/index.confluence | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/5c8833ca/curator-framework/src/site/confluence/index.confluence
----------------------------------------------------------------------
diff --git a/curator-framework/src/site/confluence/index.confluence b/curator-framework/src/site/confluence/index.confluence
index bb1807e..c41b244 100644
--- a/curator-framework/src/site/confluence/index.confluence
+++ b/curator-framework/src/site/confluence/index.confluence
@@ -63,14 +63,14 @@ CuratorEvent depend on the type of event which is exposed via the getType() meth
 |CREATE|getResultCode() and getPath()|
 |DELETE|getResultCode() and getPath()|
 |EXISTS|getResultCode(), getPath() and getStat()|
-|GET_DATA|getResultCode(), getPath(), getStat() and getData()|
-|SET_DATA|getResultCode(), getPath() and getStat()|
+|GET\_DATA|getResultCode(), getPath(), getStat() and getData()|
+|SET\_DATA|getResultCode(), getPath() and getStat()|
 |CHILDREN|getResultCode(), getPath(), getStat(), getChildren()|
 |SYNC|getResultCode(), getStat()|
-|GET_ACL|getResultCode(), getACLList()|
-|SET_ACL|getResultCode()|
+|GET\_ACL|getResultCode(), getACLList()|
+|SET\_ACL|getResultCode()|
 |WATCHED|getWatchedEvent()|
-|GET_CONFIG|getResultCode(), getData()|
+|GET\_CONFIG|getResultCode(), getData()|
 |RECONFIG|getResultCode(), getData()|
 
 h2. Namespaces


[11/26] curator git commit: [CURATOR-160] Made Configurable optional. Fix storingStatIn in GetConfigBuilderImpl.

Posted by ra...@apache.org.
[CURATOR-160] Made Configurable optional. Fix storingStatIn in GetConfigBuilderImpl.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/625441b5
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/625441b5
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/625441b5

Branch: refs/heads/CURATOR-215
Commit: 625441b588bf3a29bcec34edaa4d59a8fb720846
Parents: 59292d8
Author: Ioannis Canellos <io...@gmail.com>
Authored: Fri Apr 17 12:57:28 2015 +0300
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Fri Apr 17 13:00:30 2015 +0300

----------------------------------------------------------------------
 .../api/BackgroundStatConfigEnsembleable.java   | 24 ++++++++++
 .../api/BackgroundStatConfigurable.java         | 24 ----------
 .../api/BackgroundStatEnsembleable.java         | 24 ++++++++++
 .../curator/framework/api/Configurable.java     |  2 +-
 .../JoinBackgroundStatConfigEnsembleable.java   | 30 ++++++++++++
 .../api/JoinBackgroundStatConfigurable.java     | 30 ------------
 .../LeaveBackgroundStatConfigEnsembleable.java  | 30 ++++++++++++
 .../api/LeaveBackgroundStatConfigurable.java    | 30 ------------
 .../curator/framework/api/ReconfigBuilder.java  |  6 +--
 .../framework/imps/GetConfigBuilderImpl.java    |  2 +-
 .../framework/imps/ReconfigBuilderImpl.java     | 48 ++++++++++----------
 .../framework/imps/TestReconfiguration.java     | 32 ++++++-------
 12 files changed, 153 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java
new file mode 100644
index 0000000..f109b0f
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigEnsembleable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface BackgroundStatConfigEnsembleable<T> extends
+        Configurable<BackgroundStatEnsembleable<T>>,
+        BackgroundStatEnsembleable<T> {
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
deleted file mode 100644
index e46ba89..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatConfigurable.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-public interface BackgroundStatConfigurable<T> extends
-    BackgroundStatable<Configurable<T>>,
-    Configurable<T> {
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java
new file mode 100644
index 0000000..62f666d
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/BackgroundStatEnsembleable.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+public interface BackgroundStatEnsembleable<T> extends
+    BackgroundStatable<Ensembleable<T>>,
+    Ensembleable<T> {
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
index a47f9d0..39e2c0c 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/Configurable.java
@@ -25,5 +25,5 @@ public interface Configurable<T> {
      * @param config The version of the configuration.
      * @throws Exception
      */
-    Ensembleable<T> fromConfig(long config) throws Exception;
+    BackgroundStatEnsembleable<byte[]> fromConfig(long config) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java
new file mode 100644
index 0000000..ba45efd
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigEnsembleable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An incremental reconfiguration builder.
+ * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface JoinBackgroundStatConfigEnsembleable extends
+        Joinable<BackgroundStatConfigEnsembleable<byte[]>>,
+        BackgroundStatConfigEnsembleable<byte[]> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
deleted file mode 100644
index fb18c0c..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/JoinBackgroundStatConfigurable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An incremental reconfiguration builder.
- * This builder has access only to the incremental reconfiguration methods joining and leaving, so that we prevent
- * mixing concepts that can't be used together.
- */
-public interface JoinBackgroundStatConfigurable extends
-        Joinable<BackgroundStatConfigurable<byte[]>>,
-        BackgroundStatConfigurable<byte[]> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java
new file mode 100644
index 0000000..a6316c1
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigEnsembleable.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.api;
+
+/**
+ * An non-incremental reconfiguration builder.
+ * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
+ * mixing concepts that can't be used together.
+ */
+public interface LeaveBackgroundStatConfigEnsembleable extends
+        Leaveable<BackgroundStatConfigEnsembleable<byte[]>>,
+        BackgroundStatConfigEnsembleable<byte[]> {
+
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java b/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
deleted file mode 100644
index 196ffca..0000000
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/LeaveBackgroundStatConfigurable.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.curator.framework.api;
-
-/**
- * An non-incremental reconfiguration builder.
- * This builder has access only to the non-incremental reconfiguration methods withMembers, so that we prevent
- * mixing concepts that can't be used together.
- */
-public interface LeaveBackgroundStatConfigurable extends
-        Leaveable<BackgroundStatConfigurable<byte[]>>,
-        BackgroundStatConfigurable<byte[]> {
-
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
index 96ebdf7..f05b99e 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/ReconfigBuilder.java
@@ -19,8 +19,8 @@
 package org.apache.curator.framework.api;
 
 public interface ReconfigBuilder extends
-        Joinable<LeaveBackgroundStatConfigurable>,
-        Leaveable<JoinBackgroundStatConfigurable>,
-        Memberable<BackgroundStatConfigurable<byte[]>> {
+        Joinable<LeaveBackgroundStatConfigEnsembleable>,
+        Leaveable<JoinBackgroundStatConfigEnsembleable>,
+        Memberable<BackgroundStatConfigEnsembleable<byte[]>> {
 
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
index 59a621a..d331a0a 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/GetConfigBuilderImpl.java
@@ -50,7 +50,7 @@ public class GetConfigBuilderImpl implements GetConfigBuilder, BackgroundOperati
 
     @Override
     public Ensembleable<byte[]> storingStatIn(Stat stat) {
-        this.stat = new Stat();
+        this.stat = stat;
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
index 7a33297..5489691 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/ReconfigBuilderImpl.java
@@ -21,13 +21,13 @@ package org.apache.curator.framework.imps;
 import org.apache.curator.RetryLoop;
 import org.apache.curator.TimeTrace;
 import org.apache.curator.framework.api.BackgroundCallback;
-import org.apache.curator.framework.api.BackgroundStatConfigurable;
-import org.apache.curator.framework.api.Configurable;
+import org.apache.curator.framework.api.BackgroundStatConfigEnsembleable;
+import org.apache.curator.framework.api.BackgroundStatEnsembleable;
 import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.framework.api.CuratorEventType;
 import org.apache.curator.framework.api.Ensembleable;
-import org.apache.curator.framework.api.JoinBackgroundStatConfigurable;
-import org.apache.curator.framework.api.LeaveBackgroundStatConfigurable;
+import org.apache.curator.framework.api.JoinBackgroundStatConfigEnsembleable;
+import org.apache.curator.framework.api.LeaveBackgroundStatConfigEnsembleable;
 import org.apache.curator.framework.api.ReconfigBuilder;
 import org.apache.zookeeper.AsyncCallback;
 import org.apache.zookeeper.data.Stat;
@@ -46,7 +46,7 @@ public class ReconfigBuilderImpl implements ReconfigBuilder {
         this.client = client;
     }
 
-    private static class ReconfigBuilderBase implements BackgroundStatConfigurable<byte[]>, Ensembleable<byte[]>, BackgroundOperation<EnsembleServersAndConfig> {
+    private static class ReconfigBuilderBase implements BackgroundStatConfigEnsembleable<byte[]>, Ensembleable<byte[]>, BackgroundOperation<EnsembleServersAndConfig> {
 
         final CuratorFrameworkImpl client;
         final List<String> joiningServers = new LinkedList<String>();
@@ -62,49 +62,49 @@ public class ReconfigBuilderImpl implements ReconfigBuilder {
         }
 
         @Override
-        public Configurable<byte[]> inBackground() {
+        public Ensembleable<byte[]> inBackground() {
             backgrounding = new Backgrounding();
             return this;
         }
 
         @Override
-        public Configurable<byte[]> inBackground(Object context) {
+        public Ensembleable<byte[]> inBackground(Object context) {
             backgrounding = new Backgrounding(context);
             return this;
         }
 
         @Override
-        public Configurable<byte[]> inBackground(BackgroundCallback callback) {
+        public Ensembleable<byte[]> inBackground(BackgroundCallback callback) {
             backgrounding = new Backgrounding(callback);
             return this;
         }
 
         @Override
-        public Configurable<byte[]> inBackground(BackgroundCallback callback, Object context) {
+        public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context) {
             backgrounding = new Backgrounding(callback, context);
             return this;
         }
 
         @Override
-        public Configurable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
+        public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Executor executor) {
             backgrounding = new Backgrounding(callback, executor);
             return this;
         }
 
         @Override
-        public Configurable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
+        public Ensembleable<byte[]> inBackground(BackgroundCallback callback, Object context, Executor executor) {
             backgrounding = new Backgrounding(client, callback, context, executor);
             return this;
         }
 
         @Override
-        public Ensembleable<byte[]> fromConfig(long config) throws Exception {
+        public BackgroundStatEnsembleable<byte[]> fromConfig(long config) throws Exception {
             this.config = config;
             return this;
         }
 
         @Override
-        public Configurable<byte[]> storingStatIn(Stat stat) {
+        public Ensembleable<byte[]> storingStatIn(Stat stat) {
             this.stat = stat;
             return this;
         }
@@ -166,27 +166,27 @@ public class ReconfigBuilderImpl implements ReconfigBuilder {
         }
     }
 
-    private static class JoinReconfigBuilder extends ReconfigBuilderBase implements JoinBackgroundStatConfigurable {
+    private static class JoinReconfigBuilderConfig extends ReconfigBuilderBase implements JoinBackgroundStatConfigEnsembleable {
 
-        private JoinReconfigBuilder(CuratorFrameworkImpl client) {
+        private JoinReconfigBuilderConfig(CuratorFrameworkImpl client) {
             super(client);
         }
 
         @Override
-        public BackgroundStatConfigurable<byte[]> joining(String... servers) {
+        public BackgroundStatConfigEnsembleable<byte[]> joining(String... servers) {
             joiningServers.addAll(Arrays.asList(servers));
             return this;
         }
     }
 
-    private static class LeaveReconfigBuilder extends ReconfigBuilderBase implements LeaveBackgroundStatConfigurable {
+    private static class LeaveReconfigBuilderConfig extends ReconfigBuilderBase implements LeaveBackgroundStatConfigEnsembleable {
 
-        private LeaveReconfigBuilder(CuratorFrameworkImpl client) {
+        private LeaveReconfigBuilderConfig(CuratorFrameworkImpl client) {
             super(client);
         }
 
         @Override
-        public BackgroundStatConfigurable<byte[]> leaving(String... servers) {
+        public BackgroundStatConfigEnsembleable<byte[]> leaving(String... servers) {
             leavingServers.addAll(Arrays.asList(servers));
             return this;
         }
@@ -194,21 +194,21 @@ public class ReconfigBuilderImpl implements ReconfigBuilder {
 
 
     @Override
-    public LeaveBackgroundStatConfigurable joining(String... servers) {
-        LeaveReconfigBuilder builder = new LeaveReconfigBuilder(client);
+    public LeaveBackgroundStatConfigEnsembleable joining(String... servers) {
+        LeaveReconfigBuilderConfig builder = new LeaveReconfigBuilderConfig(client);
         builder.joiningServers.addAll(Arrays.asList(servers));
         return builder;
     }
 
     @Override
-    public JoinBackgroundStatConfigurable leaving(String... servers) {
-        JoinReconfigBuilder builder = new JoinReconfigBuilder(client);
+    public JoinBackgroundStatConfigEnsembleable leaving(String... servers) {
+        JoinReconfigBuilderConfig builder = new JoinReconfigBuilderConfig(client);
         builder.leavingServers.addAll(Arrays.asList(servers));
         return builder;
     }
 
     @Override
-    public BackgroundStatConfigurable<byte[]> withMembers(String... servers) {
+    public BackgroundStatConfigEnsembleable<byte[]> withMembers(String... servers) {
         ReconfigBuilderBase builder = new ReconfigBuilderBase(client);
         builder.members.addAll(Arrays.asList(servers));
         return builder;

http://git-wip-us.apache.org/repos/asf/curator/blob/625441b5/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index faec551..44f9d00 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -101,14 +101,14 @@ public class TestReconfiguration {
         String server2 = getServerString(qv, cluster, 2L);
 
         //Remove Servers
-        bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        bytes = client.reconfig().leaving("1").fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
 
-        bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        bytes = client.reconfig().leaving("2").fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 3);
 
@@ -116,14 +116,14 @@ public class TestReconfiguration {
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
 
         //Add Servers
-        bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        bytes = client.reconfig().joining("server.2=" + server2).fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
 
-        bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        bytes = client.reconfig().joining("server.1=" + server1).fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 5);
 
@@ -157,27 +157,27 @@ public class TestReconfiguration {
 
 
         //Remove Servers
-        client.reconfig().leaving("1").inBackground(callback).fromConfig(qv.getVersion()).forEnsemble();
+        client.reconfig().leaving("1").fromConfig(qv.getVersion()).inBackground(callback).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
-        client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        client.reconfig().leaving("2").fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 3);
 
         //Add Servers
-        client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        client.reconfig().joining("server.2=" + server2).fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
 
-        client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        client.reconfig().joining("server.1=" + server1).fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
         qv = getQuorumVerifier(bytes.get());
@@ -203,7 +203,7 @@ public class TestReconfiguration {
                         "server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
@@ -214,7 +214,7 @@ public class TestReconfiguration {
                 .withMembers("server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
 
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 3);
@@ -228,7 +228,7 @@ public class TestReconfiguration {
                         "server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 4);
 
@@ -241,7 +241,7 @@ public class TestReconfiguration {
                         "server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).storingStatIn(stat).forEnsemble();
         qv = getQuorumVerifier(bytes);
         Assert.assertEquals(qv.getAllMembers().size(), 5);
 
@@ -279,7 +279,7 @@ public class TestReconfiguration {
                         "server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
@@ -289,7 +289,7 @@ public class TestReconfiguration {
                 .withMembers("server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
         qv = getQuorumVerifier(bytes.get());
@@ -301,7 +301,7 @@ public class TestReconfiguration {
                         "server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
         qv = getQuorumVerifier(bytes.get());
@@ -313,7 +313,7 @@ public class TestReconfiguration {
                         "server.3=" + server3,
                         "server.4=" + server4,
                         "server.5=" + server5)
-                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+                .fromConfig(qv.getVersion()).inBackground(callback, latch).forEnsemble();
         waitOnDelegateListener.waitForEvent();
         Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
         qv = getQuorumVerifier(bytes.get());


[05/26] curator git commit: [CURATOR-160] Add EnsembleListener and EnsembleTracker. Implement a DynamicEnsembleProvider. TestReconfiguration now also tests the DynamicEnsembleProvider.

Posted by ra...@apache.org.
[CURATOR-160] Add EnsembleListener and EnsembleTracker. Implement a DynamicEnsembleProvider. TestReconfiguration now also tests the DynamicEnsembleProvider.


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

Branch: refs/heads/CURATOR-215
Commit: ad4889e1b6d608c977583e956aac377429223107
Parents: 019ed27
Author: Ioannis Canellos <io...@gmail.com>
Authored: Tue Nov 11 16:35:57 2014 +0200
Committer: Ioannis Canellos <io...@gmail.com>
Committed: Tue Nov 11 16:35:57 2014 +0200

----------------------------------------------------------------------
 .../curator/ensemble/EnsembleListener.java      |  24 +
 .../dynamic/DynamicEnsembleProvider.java        |  61 +++
 .../curator/framework/imps/EnsembleTracker.java | 167 +++++++
 .../framework/imps/TestReconfiguration.java     | 489 +++++++++++--------
 4 files changed, 538 insertions(+), 203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/ad4889e1/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java b/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java
new file mode 100644
index 0000000..8f963cd
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/ensemble/EnsembleListener.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.ensemble;
+
+public interface EnsembleListener {
+
+    void connectionStringUpdated(String connectionString);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/ad4889e1/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java b/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java
new file mode 100644
index 0000000..70b755f
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/ensemble/dynamic/DynamicEnsembleProvider.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.ensemble.dynamic;
+
+import com.google.common.base.Preconditions;
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.ensemble.EnsembleProvider;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class DynamicEnsembleProvider implements EnsembleProvider, EnsembleListener {
+
+    private final AtomicReference<String> connectionString = new AtomicReference<String>();
+
+    /**
+     * The connection string to use
+     *
+     * @param connectionString connection string
+     */
+    public DynamicEnsembleProvider(String connectionString)
+    {
+        this.connectionString.set(Preconditions.checkNotNull(connectionString, "connectionString cannot be null"));
+    }
+
+    @Override
+    public void start() throws Exception {
+        // NOP
+    }
+
+    @Override
+    public String getConnectionString() {
+        return connectionString.get();
+    }
+
+    @Override
+    public void close() throws IOException {
+        // NOP
+    }
+
+    @Override
+    public void connectionStringUpdated(String connectionString) {
+        this.connectionString.set(connectionString);
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/ad4889e1/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
new file mode 100644
index 0000000..a789e42
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/EnsembleTracker.java
@@ -0,0 +1,167 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.CuratorWatcher;
+import org.apache.curator.framework.listen.ListenerContainer;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.framework.state.ConnectionStateListener;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
+import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Tracks changes to the ensemble and notifies registered {@link org.apache.curator.ensemble.EnsembleListener} instances.
+ */
+public class EnsembleTracker implements Closeable {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final CuratorFramework client;
+    private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
+    private final ListenerContainer<EnsembleListener> listeners = new ListenerContainer<EnsembleListener>();
+    private final AtomicBoolean isConnected = new AtomicBoolean(true);
+    private final ConnectionStateListener connectionStateListener = new ConnectionStateListener() {
+        @Override
+        public void stateChanged(CuratorFramework client, ConnectionState newState) {
+            if ((newState == ConnectionState.CONNECTED) || (newState == ConnectionState.RECONNECTED)) {
+                if (isConnected.compareAndSet(false, true)) {
+                    try {
+                        reset();
+                    } catch (Exception e) {
+                        log.error("Trying to reset after reconnection", e);
+                    }
+                }
+            } else {
+                isConnected.set(false);
+            }
+        }
+    };
+
+    private final CuratorWatcher watcher = new CuratorWatcher() {
+        @Override
+        public void process(WatchedEvent event) throws Exception {
+            reset();
+        }
+    };
+
+
+    private enum State {
+        LATENT,
+        STARTED,
+        CLOSED
+    }
+
+    private final BackgroundCallback backgroundCallback = new BackgroundCallback() {
+        @Override
+        public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+            processBackgroundResult(event);
+        }
+    };
+
+
+    public EnsembleTracker(CuratorFramework client) {
+        this.client = client;
+    }
+
+    public void start() throws Exception {
+        Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Cannot be started more than once");
+        client.getConnectionStateListenable().addListener(connectionStateListener);
+        reset();
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (state.compareAndSet(State.STARTED, State.CLOSED)) {
+            listeners.clear();
+        }
+        client.getConnectionStateListenable().removeListener(connectionStateListener);
+    }
+
+    /**
+     * Return the ensemble listenable
+     *
+     * @return listenable
+     */
+    public ListenerContainer<EnsembleListener> getListenable()
+    {
+        Preconditions.checkState(state.get() != State.CLOSED, "Closed");
+
+        return listeners;
+    }
+
+    private void reset() throws Exception {
+        client.getConfig().usingWatcher(watcher).inBackground(backgroundCallback).forEnsemble();
+    }
+
+    private void processBackgroundResult(CuratorEvent event) throws Exception {
+        switch (event.getType()) {
+            case GET_CONFIG: {
+                if (event.getResultCode() == KeeperException.Code.OK.intValue()) {
+                    processConfigData(event.getData());
+                }
+            }
+        }
+    }
+
+    private void processConfigData(byte[] data) throws Exception {
+        Properties properties = new Properties();
+        properties.load(new ByteArrayInputStream(data));
+        QuorumVerifier qv = new QuorumMaj(properties);
+        StringBuilder sb = new StringBuilder();
+        for (QuorumPeer.QuorumServer server : qv.getAllMembers().values()) {
+            if (sb.length() != 0) {
+                sb.append(",");
+            }
+            sb.append(server.clientAddr.getAddress().getHostAddress()).append(":").append(server.clientAddr.getPort());
+        }
+
+        final String connectionString = sb.toString();
+        listeners.forEach
+                (
+                        new Function<EnsembleListener, Void>() {
+                            @Override
+                            public Void apply(EnsembleListener listener) {
+                                try {
+                                    listener.connectionStringUpdated(connectionString);
+                                } catch (Exception e) {
+                                    log.error("Calling listener", e);
+                                }
+                                return null;
+                            }
+                        }
+                );
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/ad4889e1/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
index e8896ae..faec551 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java
@@ -18,6 +18,8 @@
  */
 package org.apache.curator.framework.imps;
 
+import org.apache.curator.ensemble.EnsembleListener;
+import org.apache.curator.ensemble.dynamic.DynamicEnsembleProvider;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.api.BackgroundCallback;
@@ -35,246 +37,287 @@ import org.testng.annotations.Test;
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 
 public class TestReconfiguration {
 
     TestingCluster cluster;
+    DynamicEnsembleProvider dynamicEnsembleProvider;
+    WaitOnDelegateListener waitOnDelegateListener;
+    EnsembleTracker ensembleTracker;
+    CuratorFramework client;
+
+    String connectionString1to5;
+    String connectionString2to5;
+    String connectionString3to5;
 
     @BeforeMethod
     public void setup() throws Exception {
         cluster = new TestingCluster(5);
         cluster.start();
+
+        connectionString1to5 = cluster.getConnectString();
+        connectionString2to5 = getConnectionString(cluster, 2,3,4,5);
+        connectionString3to5 = getConnectionString(cluster, 3,4,5);
+
+        dynamicEnsembleProvider = new DynamicEnsembleProvider(connectionString1to5);
+        client = CuratorFrameworkFactory.builder()
+                .ensembleProvider(dynamicEnsembleProvider)
+                .retryPolicy(new RetryOneTime(1))
+                .build();
+        client.start();
+        client.blockUntilConnected();
+
+        //Wrap around the dynamic ensemble provider, so that we can wait until it has received the event.
+        waitOnDelegateListener = new WaitOnDelegateListener(dynamicEnsembleProvider);
+        ensembleTracker = new EnsembleTracker(client);
+        ensembleTracker.getListenable().addListener(waitOnDelegateListener);
+        ensembleTracker.start();
+        //Wait for the initial event.
+        waitOnDelegateListener.waitForEvent();
     }
 
     @AfterMethod
     public void tearDown() throws IOException {
+        ensembleTracker.close();
+        client.close();
         cluster.close();
     }
 
     @Test
     public void testSyncIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            Stat stat = new Stat();
-            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
-            Assert.assertNotNull(bytes);
-            QuorumVerifier qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-
-            //Remove Servers
-            bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        Stat stat = new Stat();
+        byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+        Assert.assertNotNull(bytes);
+        QuorumVerifier qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+
+        //Remove Servers
+        bytes = client.reconfig().leaving("1").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig().leaving("2").storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+
+        //Add Servers
+        bytes = client.reconfig().joining("server.2=" + server2).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig().joining("server.1=" + server1).storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
     }
 
     @Test
     public void testAsyncIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
-            final BackgroundCallback callback = new BackgroundCallback() {
-                @Override
-                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
-                    bytes.set(event.getData());
-                    ((CountDownLatch)event.getContext()).countDown();
+        final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+        final BackgroundCallback callback = new BackgroundCallback() {
+            @Override
+            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                bytes.set(event.getData());
+                //We only need the latch on getConfig.
+                if (event.getContext() != null) {
+                    ((CountDownLatch) event.getContext()).countDown();
                 }
+            }
 
-            };
-
-            CountDownLatch latch = new CountDownLatch(1);
-            client.getConfig().inBackground(callback, latch).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            Assert.assertNotNull(bytes.get());
-            QuorumVerifier qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-
-
-            //Remove Servers
-            latch = new CountDownLatch(1);
-            client.reconfig().leaving("1").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            latch = new CountDownLatch(1);
-            client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        };
+
+        CountDownLatch latch = new CountDownLatch(1);
+        client.getConfig().inBackground(callback, latch).forEnsemble();
+        latch.await(5, TimeUnit.SECONDS);
+        Assert.assertNotNull(bytes.get());
+        QuorumVerifier qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+
+
+        //Remove Servers
+        client.reconfig().leaving("1").inBackground(callback).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        client.reconfig().leaving("2").inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        //Add Servers
+        client.reconfig().joining("server.2=" + server2).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+
+        client.reconfig().joining("server.1=" + server1).inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
     }
 
     @Test
     public void testSyncNonIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            Stat stat = new Stat();
-            byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
-            Assert.assertNotNull(bytes);
-            QuorumVerifier qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-            String server3 = getServerString(qv, cluster, 3L);
-            String server4 = getServerString(qv, cluster, 4L);
-            String server5 = getServerString(qv, cluster, 5L);
-
-            //Remove Servers
-            bytes = client.reconfig()
-                    .withMembers("server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig()
-                    .withMembers("server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            bytes = client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            bytes = client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
-            qv = getQuorumVerifier(bytes);
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        Stat stat = new Stat();
+        byte[] bytes = client.getConfig().storingStatIn(stat).forEnsemble();
+        Assert.assertNotNull(bytes);
+        QuorumVerifier qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+        String server3 = getServerString(qv, cluster, 3L);
+        String server4 = getServerString(qv, cluster, 4L);
+        String server5 = getServerString(qv, cluster, 5L);
+
+        //Remove Servers
+        bytes = client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig()
+                .withMembers("server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+
+        //Add Servers
+        bytes = client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+
+        bytes = client.reconfig()
+                .withMembers("server.1=" + server1,
+                        "server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .storingStatIn(stat).fromConfig(qv.getVersion()).forEnsemble();
+        qv = getQuorumVerifier(bytes);
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
     }
 
     @Test
     public void testAsyncNonIncremental() throws Exception {
-        CuratorFramework client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), new RetryOneTime(1));
-        client.start();
-        client.blockUntilConnected();
-        try {
-            final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
-            final BackgroundCallback callback = new BackgroundCallback() {
-                @Override
-                public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
-                    bytes.set(event.getData());
-                    ((CountDownLatch)event.getContext()).countDown();
-                }
+        final AtomicReference<byte[]> bytes = new AtomicReference<byte[]>();
+        final BackgroundCallback callback = new BackgroundCallback() {
+            @Override
+            public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
+                bytes.set(event.getData());
+                ((CountDownLatch) event.getContext()).countDown();
+            }
 
-            };
-
-            CountDownLatch latch = new CountDownLatch(1);
-            client.getConfig().inBackground(callback, latch).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            Assert.assertNotNull(bytes.get());
-            QuorumVerifier qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-            String server1 = getServerString(qv, cluster, 1L);
-            String server2 = getServerString(qv, cluster, 2L);
-            String server3 = getServerString(qv, cluster, 3L);
-            String server4 = getServerString(qv, cluster, 4L);
-            String server5 = getServerString(qv, cluster, 5L);
-
-            //Remove Servers
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-            .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 3);
-
-            //Add Servers
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 4);
-            latch = new CountDownLatch(1);
-            client.reconfig()
-                    .withMembers("server.1=" + server1,
-                            "server.2=" + server2,
-                            "server.3=" + server3,
-                            "server.4=" + server4,
-                            "server.5=" + server5)
-                    .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
-            latch.await(5, TimeUnit.SECONDS);
-            qv = getQuorumVerifier(bytes.get());
-            Assert.assertEquals(qv.getAllMembers().size(), 5);
-        } finally {
-            client.close();
-        }
+        };
+
+        CountDownLatch latch = new CountDownLatch(1);
+        client.getConfig().inBackground(callback, latch).forEnsemble();
+        latch.await(5, TimeUnit.SECONDS);
+        Assert.assertNotNull(bytes.get());
+        QuorumVerifier qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
+        String server1 = getServerString(qv, cluster, 1L);
+        String server2 = getServerString(qv, cluster, 2L);
+        String server3 = getServerString(qv, cluster, 3L);
+        String server4 = getServerString(qv, cluster, 4L);
+        String server5 = getServerString(qv, cluster, 5L);
+
+        //Remove Servers
+        client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        client.reconfig()
+                .withMembers("server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString3to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 3);
+
+        //Add Servers
+        client.reconfig()
+                .withMembers("server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString2to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 4);
+
+        client.reconfig()
+                .withMembers("server.1=" + server1,
+                        "server.2=" + server2,
+                        "server.3=" + server3,
+                        "server.4=" + server4,
+                        "server.5=" + server5)
+                .inBackground(callback, latch).fromConfig(qv.getVersion()).forEnsemble();
+        waitOnDelegateListener.waitForEvent();
+        Assert.assertEquals(dynamicEnsembleProvider.getConnectionString(), connectionString1to5);
+        qv = getQuorumVerifier(bytes.get());
+        Assert.assertEquals(qv.getAllMembers().size(), 5);
     }
 
 
@@ -302,4 +345,44 @@ public class TestReconfiguration {
             return str + ";" + getInstance(cluster, (int) id).getConnectString();
         }
     }
+
+    static String getConnectionString(TestingCluster cluster, long... ids) throws Exception {
+        StringBuilder sb = new StringBuilder();
+        Map<Long, InstanceSpec> specs = new HashMap<Long, InstanceSpec>();
+        for (InstanceSpec spec : cluster.getInstances()) {
+            specs.put(new Long(spec.getServerId()), spec);
+        }
+        for (long id : ids) {
+            if (sb.length() != 0) {
+                sb.append(",");
+            }
+            sb.append(specs.get(id).getConnectString());
+        }
+        return sb.toString();
+    }
+
+    //Simple EnsembleListener that can wait until the delegate handles the event.
+    private static class WaitOnDelegateListener implements EnsembleListener {
+        private CountDownLatch latch = new CountDownLatch(1);
+
+        private final EnsembleListener delegate;
+
+        private WaitOnDelegateListener(EnsembleListener delegate) {
+            this.delegate = delegate;
+        }
+
+        @Override
+        public void connectionStringUpdated(String connectionString) {
+            delegate.connectionStringUpdated(connectionString);
+            latch.countDown();
+        }
+
+        public void waitForEvent() throws InterruptedException, TimeoutException {
+            if (latch.await(5, TimeUnit.SECONDS)) {
+                latch = new CountDownLatch(1);
+            } else {
+                throw new TimeoutException("Failed to receive event in time.");
+            }
+        }
+    };
 }
\ No newline at end of file