Repository: curator
Updated Branches:
refs/heads/CURATOR-111 [created] 7fc3e6507
Patch v1: Add authorization(List<AuthInfo)
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/71dc640b
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/71dc640b
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/71dc640b
Branch: refs/heads/CURATOR-111
Commit: 71dc640b663057a6acaae1f9af93aea48fee3de9
Parents: de1d38c
Author: Karthik Kambatla <ka...@cloudera.com>
Authored: Mon Dec 29 14:16:55 2014 -0800
Committer: Karthik Kambatla <ka...@cloudera.com>
Committed: Mon Dec 29 14:16:55 2014 -0800
----------------------------------------------------------------------
.../org/apache/curator/framework/AuthInfo.java | 51 ++++++++++++++++++++
.../framework/CuratorFrameworkFactory.java | 23 +++++++++
.../framework/imps/CuratorFrameworkImpl.java | 40 ++++++---------
.../curator/framework/imps/TestFramework.java | 45 +++++++++++++++++
4 files changed, 133 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/71dc640b/curator-framework/src/main/java/org/apache/curator/framework/AuthInfo.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/AuthInfo.java b/curator-framework/src/main/java/org/apache/curator/framework/AuthInfo.java
new file mode 100644
index 0000000..2f879c5
--- /dev/null
+++ b/curator-framework/src/main/java/org/apache/curator/framework/AuthInfo.java
@@ -0,0 +1,51 @@
+/**
+ * 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;
+
+import java.util.Arrays;
+
+public class AuthInfo
+{
+ final String scheme;
+ final byte[] auth;
+
+ public AuthInfo(String scheme, byte[] auth)
+ {
+ this.scheme = scheme;
+ this.auth = auth;
+ }
+
+ public String getScheme() {
+ return scheme;
+ }
+
+ public byte[] getAuth() {
+ return auth;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "AuthInfo{" +
+ "scheme='" + scheme + '\'' +
+ ", auth=" + Arrays.toString(auth) +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/71dc640b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
index 2d21fb7..4d695e4 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
@@ -34,7 +34,9 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
@@ -106,6 +108,7 @@ public class CuratorFrameworkFactory
private String namespace;
private String authScheme = null;
private byte[] authValue = null;
+ private List<AuthInfo> authInfos = null;
private byte[] defaultData = LOCAL_ADDRESS;
private CompressionProvider compressionProvider = DEFAULT_COMPRESSION_PROVIDER;
private ZookeeperFactory zookeeperFactory = DEFAULT_ZOOKEEPER_FACTORY;
@@ -165,6 +168,21 @@ public class CuratorFrameworkFactory
}
/**
+ * Add connection authorization. The supplied authInfos are appended to those added via call to
+ * {@link #authorization(java.lang.String, byte[])} for backward compatibility.
+ *
+ * Subsequent calls to this method overwrite the prior calls.
+ *
+ * @param authInfos list of {@link AuthInfo} objects with scheme and auth
+ * @return this
+ */
+ public Builder authorization(List<AuthInfo> authInfos) {
+ this.authInfos = new ArrayList<AuthInfo>(authInfos.size());
+ this.authInfos.addAll(authInfos);
+ return this;
+ }
+
+ /**
* Set the list of servers to connect to. IMPORTANT: use either this or {@link #ensembleProvider(EnsembleProvider)}
* but not both.
*
@@ -356,6 +374,11 @@ public class CuratorFrameworkFactory
return (authValue != null) ? Arrays.copyOf(authValue, authValue.length) : null;
}
+ public List<AuthInfo> getAuthInfos()
+ {
+ return authInfos;
+ }
+
public byte[] getDefaultData()
{
return defaultData;
http://git-wip-us.apache.org/repos/asf/curator/blob/71dc640b/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 c4b1349..f7b08a6 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
@@ -24,6 +24,7 @@ import org.apache.curator.CuratorConnectionLossException;
import org.apache.curator.CuratorZookeeperClient;
import org.apache.curator.RetryLoop;
import org.apache.curator.TimeTrace;
+import org.apache.curator.framework.AuthInfo;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.*;
@@ -43,7 +44,10 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.DelayQueue;
@@ -65,7 +69,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
private final BlockingQueue<OperationAndData<?>> backgroundOperations;
private final NamespaceImpl namespace;
private final ConnectionStateManager connectionStateManager;
- private final AtomicReference<AuthInfo> authInfo = new AtomicReference<AuthInfo>();
+ private final List<AuthInfo> authInfos;
private final byte[] defaultData;
private final FailedDeleteManager failedDeleteManager;
private final CompressionProvider compressionProvider;
@@ -86,27 +90,6 @@ public class CuratorFrameworkImpl implements CuratorFramework
private final AtomicReference<CuratorFrameworkState> state;
- private static class AuthInfo
- {
- final String scheme;
- final byte[] auth;
-
- private AuthInfo(String scheme, byte[] auth)
- {
- this.scheme = scheme;
- this.auth = auth;
- }
-
- @Override
- public String toString()
- {
- return "AuthInfo{" +
- "scheme='" + scheme + '\'' +
- ", auth=" + Arrays.toString(auth) +
- '}';
- }
- }
-
public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder)
{
ZookeeperFactory localZookeeperFactory = makeZookeeperFactory(builder.getZookeeperFactory());
@@ -155,9 +138,14 @@ public class CuratorFrameworkImpl implements CuratorFramework
byte[] builderDefaultData = builder.getDefaultData();
defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0];
+ authInfos = new ArrayList<AuthInfo>();
if ( builder.getAuthScheme() != null )
{
- authInfo.set(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
+ authInfos.add(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
+ }
+ if ( builder.getAuthInfos() != null )
+ {
+ authInfos.addAll(builder.getAuthInfos());
}
failedDeleteManager = new FailedDeleteManager(this);
@@ -172,10 +160,9 @@ public class CuratorFrameworkImpl implements CuratorFramework
public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception
{
ZooKeeper zooKeeper = actualZookeeperFactory.newZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly);
- AuthInfo auth = authInfo.get();
- if ( auth != null )
+ for (AuthInfo auth : authInfos)
{
- zooKeeper.addAuthInfo(auth.scheme, auth.auth);
+ zooKeeper.addAuthInfo(auth.getScheme(), auth.getAuth());
}
return zooKeeper;
@@ -208,6 +195,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
namespaceFacadeCache = parent.namespaceFacadeCache;
namespace = new NamespaceImpl(this, null);
state = parent.state;
+ authInfos = parent.authInfos;
}
@Override
http://git-wip-us.apache.org/repos/asf/curator/blob/71dc640b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index 93d346b..0f51b25 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@ -19,6 +19,7 @@
package org.apache.curator.framework.imps;
import com.google.common.collect.Lists;
+import org.apache.curator.framework.AuthInfo;
import org.apache.curator.test.BaseClassForTests;
import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.framework.CuratorFramework;
@@ -42,6 +43,8 @@ import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.annotations.Test;
+
+import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
@@ -169,10 +172,16 @@ public class TestFramework extends BaseClassForTests
@Test
public void testCreateACL() throws Exception
{
+ // Add a few authInfos
+ List<AuthInfo> authInfos = new ArrayList<AuthInfo>();
+ authInfos.add(new AuthInfo("digest", "me1:pass1".getBytes()));
+ authInfos.add(new AuthInfo("digest", "me2:pass2".getBytes()));
+
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
CuratorFramework client = builder
.connectString(server.getConnectString())
.authorization("digest", "me:pass".getBytes())
+ .authorization(authInfos)
.retryPolicy(new RetryOneTime(1))
.build();
client.start();
@@ -183,6 +192,7 @@ public class TestFramework extends BaseClassForTests
client.create().withACL(aclList).forPath("/test", "test".getBytes());
client.close();
+ // Try setting data with me:pass
client = builder
.connectString(server.getConnectString())
.authorization("digest", "me:pass".getBytes())
@@ -199,6 +209,41 @@ public class TestFramework extends BaseClassForTests
}
client.close();
+ // Try setting data with me1:pass1
+ client = builder
+ .connectString(server.getConnectString())
+ .authorization("digest", "me1:pass1".getBytes())
+ .retryPolicy(new RetryOneTime(1))
+ .build();
+ client.start();
+ try
+ {
+ client.setData().forPath("/test", "test".getBytes());
+ }
+ catch ( KeeperException.NoAuthException e )
+ {
+ Assert.fail("Auth failed");
+ }
+ client.close();
+
+ // Try setting data with me2:pass2
+ client = builder
+ .connectString(server.getConnectString())
+ .authorization("digest", "me:pass2".getBytes())
+ .retryPolicy(new RetryOneTime(1))
+ .build();
+ client.start();
+ try
+ {
+ client.setData().forPath("/test", "test".getBytes());
+ }
+ catch ( KeeperException.NoAuthException e )
+ {
+ Assert.fail("Auth failed");
+ }
+ client.close();
+
+ // Try setting data with something:else
client = builder
.connectString(server.getConnectString())
.authorization("digest", "something:else".getBytes())
[3/3] curator git commit: Use Guava
Posted by ra...@apache.org.
Use Guava
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7fc3e650
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7fc3e650
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7fc3e650
Branch: refs/heads/CURATOR-111
Commit: 7fc3e6507d5bcbb16c696906bed529c23df88e34
Parents: 58ecd64
Author: randgalt <ra...@apache.org>
Authored: Mon Jan 12 16:03:35 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon Jan 12 16:03:35 2015 -0500
----------------------------------------------------------------------
.../framework/CuratorFrameworkFactory.java | 73 +++++++++----------
.../framework/imps/CuratorFrameworkImpl.java | 77 ++++++++++----------
2 files changed, 76 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/7fc3e650/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
index 38fe911..ae26f2c 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
@@ -16,8 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.curator.framework;
+import com.google.common.collect.ImmutableList;
import org.apache.curator.RetryPolicy;
import org.apache.curator.ensemble.EnsembleProvider;
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
@@ -34,7 +36,6 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadFactory;
@@ -45,23 +46,23 @@ import java.util.concurrent.TimeUnit;
*/
public class CuratorFrameworkFactory
{
- private static final int DEFAULT_SESSION_TIMEOUT_MS = Integer.getInteger("curator-default-session-timeout", 60 * 1000);
- private static final int DEFAULT_CONNECTION_TIMEOUT_MS = Integer.getInteger("curator-default-connection-timeout", 15 * 1000);
+ private static final int DEFAULT_SESSION_TIMEOUT_MS = Integer.getInteger("curator-default-session-timeout", 60 * 1000);
+ private static final int DEFAULT_CONNECTION_TIMEOUT_MS = Integer.getInteger("curator-default-connection-timeout", 15 * 1000);
- private static final byte[] LOCAL_ADDRESS = getLocalAddress();
+ private static final byte[] LOCAL_ADDRESS = getLocalAddress();
- private static final CompressionProvider DEFAULT_COMPRESSION_PROVIDER = new GzipCompressionProvider();
- private static final DefaultZookeeperFactory DEFAULT_ZOOKEEPER_FACTORY = new DefaultZookeeperFactory();
- private static final DefaultACLProvider DEFAULT_ACL_PROVIDER = new DefaultACLProvider();
- private static final long DEFAULT_INACTIVE_THRESHOLD_MS = (int)TimeUnit.MINUTES.toMillis(3);
- private static final int DEFAULT_CLOSE_WAIT_MS = (int)TimeUnit.SECONDS.toMillis(1);
+ private static final CompressionProvider DEFAULT_COMPRESSION_PROVIDER = new GzipCompressionProvider();
+ private static final DefaultZookeeperFactory DEFAULT_ZOOKEEPER_FACTORY = new DefaultZookeeperFactory();
+ private static final DefaultACLProvider DEFAULT_ACL_PROVIDER = new DefaultACLProvider();
+ private static final long DEFAULT_INACTIVE_THRESHOLD_MS = (int)TimeUnit.MINUTES.toMillis(3);
+ private static final int DEFAULT_CLOSE_WAIT_MS = (int)TimeUnit.SECONDS.toMillis(1);
/**
* Return a new builder that builds a CuratorFramework
*
* @return new builder
*/
- public static Builder builder()
+ public static Builder builder()
{
return new Builder();
}
@@ -69,9 +70,8 @@ public class CuratorFrameworkFactory
/**
* Create a new client with default session timeout and default connection timeout
*
- *
* @param connectString list of servers to connect to
- * @param retryPolicy retry policy to use
+ * @param retryPolicy retry policy to use
* @return client
*/
public static CuratorFramework newClient(String connectString, RetryPolicy retryPolicy)
@@ -82,11 +82,10 @@ public class CuratorFrameworkFactory
/**
* Create a new client
*
- *
- * @param connectString list of servers to connect to
- * @param sessionTimeoutMs session timeout
+ * @param connectString list of servers to connect to
+ * @param sessionTimeoutMs session timeout
* @param connectionTimeoutMs connection timeout
- * @param retryPolicy retry policy to use
+ * @param retryPolicy retry policy to use
* @return client
*/
public static CuratorFramework newClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, RetryPolicy retryPolicy)
@@ -101,21 +100,21 @@ public class CuratorFrameworkFactory
public static class Builder
{
- private EnsembleProvider ensembleProvider;
- private int sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT_MS;
- private int connectionTimeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS;
- private int maxCloseWaitMs = DEFAULT_CLOSE_WAIT_MS;
- private RetryPolicy retryPolicy;
- private ThreadFactory threadFactory = null;
- private String namespace;
- private String authScheme = null;
- private byte[] authValue = null;
- private List<AuthInfo> authInfos = null;
- private byte[] defaultData = LOCAL_ADDRESS;
+ private EnsembleProvider ensembleProvider;
+ private int sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT_MS;
+ private int connectionTimeoutMs = DEFAULT_CONNECTION_TIMEOUT_MS;
+ private int maxCloseWaitMs = DEFAULT_CLOSE_WAIT_MS;
+ private RetryPolicy retryPolicy;
+ private ThreadFactory threadFactory = null;
+ private String namespace;
+ private String authScheme = null;
+ private byte[] authValue = null;
+ private List<AuthInfo> authInfos = null;
+ private byte[] defaultData = LOCAL_ADDRESS;
private CompressionProvider compressionProvider = DEFAULT_COMPRESSION_PROVIDER;
- private ZookeeperFactory zookeeperFactory = DEFAULT_ZOOKEEPER_FACTORY;
- private ACLProvider aclProvider = DEFAULT_ACL_PROVIDER;
- private boolean canBeReadOnly = false;
+ private ZookeeperFactory zookeeperFactory = DEFAULT_ZOOKEEPER_FACTORY;
+ private ACLProvider aclProvider = DEFAULT_ACL_PROVIDER;
+ private boolean canBeReadOnly = false;
/**
* Apply the current values and build a new CuratorFramework
@@ -147,7 +146,7 @@ public class CuratorFrameworkFactory
* are limited. Further, the connection will be closed after <code>inactiveThresholdMs</code> milliseconds of inactivity.
*
* @param inactiveThreshold number of milliseconds of inactivity to cause connection close
- * @param unit threshold unit
+ * @param unit threshold unit
* @return temp instance
*/
public CuratorTempFramework buildTemp(long inactiveThreshold, TimeUnit unit)
@@ -159,10 +158,10 @@ public class CuratorFrameworkFactory
* Add connection authorization
*
* @param scheme the scheme
- * @param auth the auth bytes
+ * @param auth the auth bytes
* @return this
*/
- public Builder authorization(String scheme, byte[] auth)
+ public Builder authorization(String scheme, byte[] auth)
{
this.authScheme = scheme;
this.authValue = (auth != null) ? Arrays.copyOf(auth, auth.length) : null;
@@ -172,15 +171,15 @@ public class CuratorFrameworkFactory
/**
* Add connection authorization. The supplied authInfos are appended to those added via call to
* {@link #authorization(java.lang.String, byte[])} for backward compatibility.
- *
+ * <p/>
* Subsequent calls to this method overwrite the prior calls.
*
* @param authInfos list of {@link AuthInfo} objects with scheme and auth
* @return this
*/
- public Builder authorization(List<AuthInfo> authInfos) {
- this.authInfos = new ArrayList<AuthInfo>(authInfos.size());
- this.authInfos.addAll(authInfos);
+ public Builder authorization(List<AuthInfo> authInfos)
+ {
+ this.authInfos = ImmutableList.copyOf(authInfos);
return this;
}
http://git-wip-us.apache.org/repos/asf/curator/blob/7fc3e650/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 c38617d..e8785be 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
@@ -22,7 +22,7 @@ package org.apache.curator.framework.imps;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
-
+import com.google.common.collect.ImmutableList;
import org.apache.curator.CuratorConnectionLossException;
import org.apache.curator.CuratorZookeeperClient;
import org.apache.curator.RetryLoop;
@@ -47,8 +47,6 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.BlockingQueue;
@@ -122,19 +120,24 @@ public class CuratorFrameworkImpl implements CuratorFramework
byte[] builderDefaultData = builder.getDefaultData();
defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0];
+ authInfos = buildAuths(builder);
- authInfos = new ArrayList<AuthInfo>();
+ failedDeleteManager = new FailedDeleteManager(this);
+ namespaceFacadeCache = new NamespaceFacadeCache(this);
+ }
+
+ private List<AuthInfo> buildAuths(CuratorFrameworkFactory.Builder builder)
+ {
+ ImmutableList.Builder<AuthInfo> builder1 = ImmutableList.builder();
if ( builder.getAuthScheme() != null )
{
- authInfos.add(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
+ builder1.add(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
}
if ( builder.getAuthInfos() != null )
{
- authInfos.addAll(builder.getAuthInfos());
+ builder1.addAll(builder.getAuthInfos());
}
-
- failedDeleteManager = new FailedDeleteManager(this);
- namespaceFacadeCache = new NamespaceFacadeCache(this);
+ return builder1.build();
}
private ZookeeperFactory makeZookeeperFactory(final ZookeeperFactory actualZookeeperFactory)
@@ -145,7 +148,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception
{
ZooKeeper zooKeeper = actualZookeeperFactory.newZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly);
- for (AuthInfo auth : authInfos)
+ for ( AuthInfo auth : authInfos )
{
zooKeeper.addAuthInfo(auth.getScheme(), auth.getAuth());
}
@@ -251,14 +254,14 @@ public class CuratorFrameworkImpl implements CuratorFramework
executorService = Executors.newFixedThreadPool(2, threadFactory); // 1 for listeners, 1 for background ops
executorService.submit(new Callable<Object>()
+ {
+ @Override
+ public Object call() throws Exception
{
- @Override
- public Object call() throws Exception
- {
- backgroundOperationsLoop();
- return null;
- }
- });
+ backgroundOperationsLoop();
+ return null;
+ }
+ });
}
catch ( Exception e )
{
@@ -273,22 +276,22 @@ public class CuratorFrameworkImpl implements CuratorFramework
if ( state.compareAndSet(CuratorFrameworkState.STARTED, CuratorFrameworkState.STOPPED) )
{
listeners.forEach(new Function<CuratorListener, Void>()
+ {
+ @Override
+ public Void apply(CuratorListener listener)
{
- @Override
- public Void apply(CuratorListener listener)
+ CuratorEvent event = new CuratorEventImpl(CuratorFrameworkImpl.this, CuratorEventType.CLOSING, 0, null, null, null, null, null, null, null, null);
+ try
{
- CuratorEvent event = new CuratorEventImpl(CuratorFrameworkImpl.this, CuratorEventType.CLOSING, 0, null, null, null, null, null, null, null, null);
- try
- {
- listener.eventReceived(CuratorFrameworkImpl.this, event);
- }
- catch ( Exception e )
- {
- log.error("Exception while sending Closing event", e);
- }
- return null;
+ listener.eventReceived(CuratorFrameworkImpl.this, event);
}
- });
+ catch ( Exception e )
+ {
+ log.error("Exception while sending Closing event", e);
+ }
+ return null;
+ }
+ });
if ( executorService != null )
{
@@ -550,14 +553,14 @@ public class CuratorFrameworkImpl implements CuratorFramework
final String localReason = reason;
unhandledErrorListeners.forEach(new Function<UnhandledErrorListener, Void>()
+ {
+ @Override
+ public Void apply(UnhandledErrorListener listener)
{
- @Override
- public Void apply(UnhandledErrorListener listener)
- {
- listener.unhandledError(localReason, e);
- return null;
- }
- });
+ listener.unhandledError(localReason, e);
+ return null;
+ }
+ });
if ( debugUnhandledErrorListener != null )
{
[2/3] curator git commit: Merge branch 'CURATOR-111' of
https://github.com/kambatla/curator into CURATOR-111
Posted by ra...@apache.org.
Merge branch 'CURATOR-111' of https://github.com/kambatla/curator into CURATOR-111
Conflicts:
curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/58ecd64f
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/58ecd64f
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/58ecd64f
Branch: refs/heads/CURATOR-111
Commit: 58ecd64f0b0b05590f2bcd350d17c173a5c791ab
Parents: 84699d3 71dc640
Author: randgalt <ra...@apache.org>
Authored: Mon Jan 12 15:55:20 2015 -0500
Committer: randgalt <ra...@apache.org>
Committed: Mon Jan 12 15:55:20 2015 -0500
----------------------------------------------------------------------
.../org/apache/curator/framework/AuthInfo.java | 51 ++++++++++++++++++++
.../framework/CuratorFrameworkFactory.java | 23 +++++++++
.../framework/imps/CuratorFrameworkImpl.java | 42 ++++++----------
.../curator/framework/imps/TestFramework.java | 44 +++++++++++++++++
4 files changed, 132 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/58ecd64f/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/58ecd64f/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --cc curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index fc462d4,f7b08a6..c38617d
--- 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
@@@ -60,60 -60,36 +63,39 @@@ import java.util.concurrent.atomic.Atom
public class CuratorFrameworkImpl implements CuratorFramework
{
-
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final CuratorZookeeperClient client;
- private final ListenerContainer<CuratorListener> listeners;
- private final ListenerContainer<UnhandledErrorListener> unhandledErrorListeners;
- private final ThreadFactory threadFactory;
- private final BlockingQueue<OperationAndData<?>> backgroundOperations;
- private final NamespaceImpl namespace;
- private final ConnectionStateManager connectionStateManager;
- private final List<AuthInfo> authInfos;
- private final byte[] defaultData;
- private final FailedDeleteManager failedDeleteManager;
- private final CompressionProvider compressionProvider;
- private final ACLProvider aclProvider;
- private final NamespaceFacadeCache namespaceFacadeCache;
- private final NamespaceWatcherMap namespaceWatcherMap = new NamespaceWatcherMap(this);
-
- private volatile ExecutorService executorService;
- private final AtomicBoolean logAsErrorConnectionErrors = new AtomicBoolean(false);
-
- private static final boolean LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL = !Boolean.getBoolean(DebugUtils.PROPERTY_LOG_ONLY_FIRST_CONNECTION_ISSUE_AS_ERROR_LEVEL);
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private final CuratorZookeeperClient client;
+ private final ListenerContainer<CuratorListener> listeners;
+ private final ListenerContainer<UnhandledErrorListener> unhandledErrorListeners;
+ private final ThreadFactory threadFactory;
+ private final int maxCloseWaitMs;
+ private final BlockingQueue<OperationAndData<?>> backgroundOperations;
+ private final NamespaceImpl namespace;
+ private final ConnectionStateManager connectionStateManager;
- private final AtomicReference<AuthInfo> authInfo = new AtomicReference<AuthInfo>();
++ private final List<AuthInfo> authInfos;
+ private final byte[] defaultData;
+ private final FailedDeleteManager failedDeleteManager;
+ private final CompressionProvider compressionProvider;
+ private final ACLProvider aclProvider;
+ private final NamespaceFacadeCache namespaceFacadeCache;
+ private final NamespaceWatcherMap namespaceWatcherMap = new NamespaceWatcherMap(this);
+
+ private volatile ExecutorService executorService;
+ private final AtomicBoolean logAsErrorConnectionErrors = new AtomicBoolean(false);
+
+ private static final boolean LOG_ALL_CONNECTION_ISSUES_AS_ERROR_LEVEL = !Boolean.getBoolean(DebugUtils.PROPERTY_LOG_ONLY_FIRST_CONNECTION_ISSUE_AS_ERROR_LEVEL);
interface DebugBackgroundListener
{
- void listen(OperationAndData<?> data);
+ void listen(OperationAndData<?> data);
}
- volatile DebugBackgroundListener debugListener = null;
- private final AtomicReference<CuratorFrameworkState> state;
+ volatile DebugBackgroundListener debugListener = null;
+ @VisibleForTesting
+ public volatile UnhandledErrorListener debugUnhandledErrorListener = null;
+
+ private final AtomicReference<CuratorFrameworkState> state;
- private static class AuthInfo
- {
- final String scheme;
- final byte[] auth;
-
- private AuthInfo(String scheme, byte[] auth)
- {
- this.scheme = scheme;
- this.auth = auth;
- }
-
- @Override
- public String toString()
- {
- return "AuthInfo{" +
- "scheme='" + scheme + '\'' +
- ", auth=" + Arrays.toString(auth) +
- '}';
- }
- }
-
public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder)
{
ZookeeperFactory localZookeeperFactory = makeZookeeperFactory(builder.getZookeeperFactory());
@@@ -138,12 -135,17 +120,17 @@@
aclProvider = builder.getAclProvider();
state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);
- byte[] builderDefaultData = builder.getDefaultData();
+ byte[] builderDefaultData = builder.getDefaultData();
defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0];
+ authInfos = new ArrayList<AuthInfo>();
if ( builder.getAuthScheme() != null )
{
- authInfo.set(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
+ authInfos.add(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
+ }
+ if ( builder.getAuthInfos() != null )
+ {
+ authInfos.addAll(builder.getAuthInfos());
}
failedDeleteManager = new FailedDeleteManager(this);
@@@ -238,8 -226,9 +225,7 @@@
log.info("Starting");
if ( !state.compareAndSet(CuratorFrameworkState.LATENT, CuratorFrameworkState.STARTED) )
{
- IllegalStateException ise = new IllegalStateException("Cannot be started more than once");
- throw ise;
- IllegalStateException error = new IllegalStateException();
- log.error("Cannot be started more than once", error);
- throw error;
++ throw new IllegalStateException("Cannot be started more than once");
}
try
http://git-wip-us.apache.org/repos/asf/curator/blob/58ecd64f/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
----------------------------------------------------------------------
diff --cc curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index 5a640db,0f51b25..c98dd0f
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@@ -19,6 -19,9 +19,7 @@@
package org.apache.curator.framework.imps;
import com.google.common.collect.Lists;
+ import org.apache.curator.framework.AuthInfo;
-import org.apache.curator.test.BaseClassForTests;
-import org.apache.curator.utils.CloseableUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.BackgroundCallback;
@@@ -41,6 -43,8 +42,7 @@@ import org.apache.zookeeper.data.ACL
import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.annotations.Test;
-
+ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;