curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [7/8] git commit: transitioned to Dropwizard config and logging
Date Wed, 28 May 2014 17:33:57 GMT
transitioned to Dropwizard config and logging


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

Branch: refs/heads/curator-rpc
Commit: 49d0294657d242f366db4a0e0654f429100c4b85
Parents: 078d7be
Author: randgalt <randgalt@apache.org>
Authored: Wed May 28 12:14:59 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Wed May 28 12:14:59 2014 -0500

----------------------------------------------------------------------
 .../curator/x/rpc/CuratorProjectionServer.java  | 94 ++++----------------
 .../AuthorizationConfiguration.java             | 27 ++++++
 ...dedExponentialBackoffRetryConfiguration.java | 51 +++++++++++
 .../x/rpc/configuration/Configuration.java      | 46 ++++++----
 .../rpc/configuration/ConfigurationBuilder.java | 20 +++--
 .../x/rpc/configuration/ConfigurationX.java     | 54 -----------
 .../configuration/ConnectionConfiguration.java  | 53 ++++++++---
 .../ExponentialBackoffRetryConfiguration.java   | 32 +++----
 .../configuration/RetryNTimesConfiguration.java | 40 +++++++++
 .../configuration/RetryPolicyConfiguration.java | 10 +++
 .../curator/x/rpc/configuration/RetryType.java  |  6 --
 .../src/main/resources/curator/help.txt         | 13 +++
 .../configuration/TestConfigurationBuilder.java | 25 +++++-
 .../resources/configuration/connections.json    | 27 ++++++
 14 files changed, 303 insertions(+), 195 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
index 40e543f..2769e98 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
@@ -24,21 +24,18 @@ import com.facebook.swift.service.ThriftServer;
 import com.facebook.swift.service.ThriftServiceProcessor;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import io.airlift.configuration.ConfigurationFactory;
-import io.airlift.configuration.ConfigurationLoader;
-import io.airlift.configuration.ConfigurationMetadata;
-import io.airlift.units.DataSize;
-import io.airlift.units.Duration;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
 import org.apache.curator.x.rpc.configuration.Configuration;
+import org.apache.curator.x.rpc.configuration.ConfigurationBuilder;
 import org.apache.curator.x.rpc.idl.event.EventService;
 import org.apache.curator.x.rpc.idl.projection.CuratorProjectionService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.io.File;
 import java.io.IOException;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
+import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.concurrent.atomic.AtomicReference;
 
 public class CuratorProjectionServer
@@ -56,29 +53,27 @@ public class CuratorProjectionServer
         STOPPED
     }
 
-    public static void main(String[] args) throws IOException
+    public static void main(String[] args) throws Exception
     {
-        if ( (args.length == 0) || args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("-h")
|| args[0].equalsIgnoreCase("--help") )
+        if ( (args.length != 1) || args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("-h")
|| args[0].equalsIgnoreCase("--help") )
         {
             printHelp();
             return;
         }
 
-        Map<String, String> options;
+        String configurationSource;
         File f = new File(args[0]);
         if ( f.exists() )
         {
-            options = new ConfigurationLoader().loadPropertiesFrom(f.getPath());
+            configurationSource = Files.toString(f, Charset.defaultCharset());
         }
         else
         {
-            System.out.println("First argument is not a file. Treating the command line as
a list of field/values");
-            options = buildOptions(args);
+            System.out.println("First argument is not a file. Treating the command line as
a json object");
+            configurationSource = args[0];
         }
 
-        ConfigurationFactory configurationFactory = new ConfigurationFactory(options);
-
-        Configuration configuration = configurationFactory.build(Configuration.class);
+        Configuration configuration = new ConfigurationBuilder(configurationSource).build();
 
         final CuratorProjectionServer server = new CuratorProjectionServer(configuration);
         server.start();
@@ -102,7 +97,7 @@ public class CuratorProjectionServer
         EventService eventService = new EventService(rpcManager, configuration.getPingTime().toMillis());
         CuratorProjectionService projectionService = new CuratorProjectionService(rpcManager);
         ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(),
Lists.<ThriftEventHandler>newArrayList(), projectionService, eventService);
-        server = new ThriftServer(processor, configuration);
+        server = new ThriftServer(processor, configuration.getThrift());
     }
 
     public void start()
@@ -111,7 +106,7 @@ public class CuratorProjectionServer
 
         server.start();
 
-        log.info("Server listening on port: " + configuration.getPort());
+        log.info("Server listening on port: " + configuration.getThrift().getPort());
     }
 
     public void stop()
@@ -127,64 +122,9 @@ public class CuratorProjectionServer
         }
     }
 
-    private static void printHelp()
+    private static void printHelp() throws IOException
     {
-        System.out.println("Curator RPC - an RPC server for using Apache Curator APIs and
recipes from non JVM languages.");
-        System.out.println();
-        System.out.println("Arguments:");
-        System.out.println("\t<none>              show this help");
-        System.out.println("\t<path>              path to a properties configuration
file");
-        System.out.println("\t<field value> ...   list of properties of the form: \"field1
value1 ... fieldN valueN\"");
-        System.out.println();
-
-        Map<String, String> valuesMap = Maps.newTreeMap();
-
-        buildMetaData(valuesMap, ConfigurationMetadata.getConfigurationMetadata(Configuration.class));
-
-        System.out.println("Values:");
-        for ( String s : valuesMap.values() )
-        {
-            System.out.println(s);
-        }
-
-        System.out.println("Special Types Examples:");
-        System.out.println("\t" + Duration.class.getSimpleName());
-        System.out.println("\t\t" + new Duration(10, TimeUnit.MINUTES));
-        System.out.println("\t\t" + new Duration(5, TimeUnit.MILLISECONDS));
-        System.out.println("\t\t" + new Duration(1.5, TimeUnit.HOURS));
-        System.out.println("\t" + DataSize.class.getSimpleName());
-        System.out.println("\t\t" + new DataSize(1.5, DataSize.Unit.GIGABYTE));
-        System.out.println("\t\t" + new DataSize(10, DataSize.Unit.BYTE));
-        System.out.println("\t\t" + new DataSize(.4, DataSize.Unit.MEGABYTE));
-        System.out.println();
-    }
-
-    private static void buildMetaData(Map<String, String> valuesMap, ConfigurationMetadata<?>
metadata)
-    {
-        for ( ConfigurationMetadata.AttributeMetadata attributeMetadata : metadata.getAttributes().values()
)
-        {
-            int index = 0;
-            ConfigurationMetadata.InjectionPointMetaData injectionPoint = attributeMetadata.getInjectionPoint();
-            valuesMap.put(injectionPoint.getProperty() + index++, "\t" + injectionPoint.getProperty()
+ ": " + attributeMetadata.getGetter().getReturnType().getSimpleName());
-            if ( attributeMetadata.getDescription() != null )
-            {
-                valuesMap.put(injectionPoint.getProperty() + index++, "\t\t" + attributeMetadata.getDescription());
-            }
-            valuesMap.put(injectionPoint.getProperty() + index, "");
-        }
-    }
-
-    private static Map<String, String> buildOptions(String[] args) throws IOException
-    {
-        Map<String, String> options = Maps.newHashMap();
-        for ( int i = 0; i < args.length; i += 2 )
-        {
-            if ( (i + 1) >= args.length )
-            {
-                throw new IOException("Bad command line. Must be list of fields and values
of the form: \"field1 value1 ... fieldN valueN\"");
-            }
-            options.put(args[i], args[i + 1]);
-        }
-        return options;
+        URL helpUrl = Resources.getResource("curator/help.txt");
+        System.out.println(Resources.toString(helpUrl, Charset.defaultCharset()));
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
new file mode 100644
index 0000000..3bbc347
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/AuthorizationConfiguration.java
@@ -0,0 +1,27 @@
+package org.apache.curator.x.rpc.configuration;
+
+public class AuthorizationConfiguration
+{
+    private String scheme;
+    private String auth;
+
+    public String getScheme()
+    {
+        return scheme;
+    }
+
+    public void setScheme(String scheme)
+    {
+        this.scheme = scheme;
+    }
+
+    public String getAuth()
+    {
+        return auth;
+    }
+
+    public void setAuth(String auth)
+    {
+        this.auth = auth;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
new file mode 100644
index 0000000..5c582ef
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/BoundedExponentialBackoffRetryConfiguration.java
@@ -0,0 +1,51 @@
+package org.apache.curator.x.rpc.configuration;
+
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import io.airlift.units.Duration;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.retry.BoundedExponentialBackoffRetry;
+import java.util.concurrent.TimeUnit;
+
+@JsonTypeName("bounded-exponential-backoff")
+public class BoundedExponentialBackoffRetryConfiguration extends RetryPolicyConfiguration
+{
+    private Duration baseSleepTime = new Duration(100, TimeUnit.MILLISECONDS);
+    private Duration maxSleepTime = new Duration(30, TimeUnit.SECONDS);
+    private int maxRetries = 3;
+
+    @Override
+    public RetryPolicy build()
+    {
+        return new BoundedExponentialBackoffRetry((int)baseSleepTime.toMillis(), (int)maxSleepTime.toMillis(),
maxRetries);
+    }
+
+    public Duration getBaseSleepTime()
+    {
+        return baseSleepTime;
+    }
+
+    public void setBaseSleepTime(Duration baseSleepTime)
+    {
+        this.baseSleepTime = baseSleepTime;
+    }
+
+    public int getMaxRetries()
+    {
+        return maxRetries;
+    }
+
+    public void setMaxRetries(int maxRetries)
+    {
+        this.maxRetries = maxRetries;
+    }
+
+    public Duration getMaxSleepTime()
+    {
+        return maxSleepTime;
+    }
+
+    public void setMaxSleepTime(Duration maxSleepTime)
+    {
+        this.maxSleepTime = maxSleepTime;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
index 799ab9b..e567cac 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/Configuration.java
@@ -1,28 +1,45 @@
 package org.apache.curator.x.rpc.configuration;
 
 import com.facebook.swift.service.ThriftServerConfig;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-import io.airlift.configuration.Config;
-import io.airlift.configuration.ConfigDescription;
+import com.google.common.collect.Lists;
 import io.airlift.units.Duration;
+import io.dropwizard.logging.LoggingFactory;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-public class Configuration extends ThriftServerConfig
+public class Configuration
 {
+    private ThriftServerConfig thrift = new ThriftServerConfig();
+    private LoggingFactory logging = new LoggingFactory();
     private Duration projectionExpiration = new Duration(3, TimeUnit.MINUTES);
     private Duration pingTime = new Duration(5, TimeUnit.SECONDS);
-    private List<String> connectionNames = ImmutableList.of();
+    private List<ConnectionConfiguration> connections = Lists.newArrayList();
+
+    public LoggingFactory getLogging()
+    {
+        return logging;
+    }
+
+    public void setLogging(LoggingFactory logging)
+    {
+        this.logging = logging;
+    }
+
+    public ThriftServerConfig getThrift()
+    {
+        return thrift;
+    }
+
+    public void setThrift(ThriftServerConfig thrift)
+    {
+        this.thrift = thrift;
+    }
 
     public Duration getProjectionExpiration()
     {
         return projectionExpiration;
     }
 
-    @Config("curator.projection-expiration")
-    @ConfigDescription("Curator projection instances will be expired after this amount of
inactivity - default is 3 minutes")
     public void setProjectionExpiration(Duration projectionExpiration)
     {
         this.projectionExpiration = projectionExpiration;
@@ -33,21 +50,18 @@ public class Configuration extends ThriftServerConfig
         return pingTime;
     }
 
-    @Config("curator.ping-time")
-    @ConfigDescription("Calls to getNextEvent() will return PING after this duration - default
is 5 seconds")
     public void setPingTime(Duration pingTime)
     {
         this.pingTime = pingTime;
     }
 
-    public List<String> getConnectionNames()
+    public List<ConnectionConfiguration> getConnections()
     {
-        return connectionNames;
+        return connections;
     }
 
-    @Config("curator.connection.names")
-    public void setConnectionNames(String connectionNames)
+    public void setConnections(List<ConnectionConfiguration> connections)
     {
-        this.connectionNames = Splitter.on(",").trimResults().splitToList(connectionNames);
+        this.connections = connections;
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
index f8f5760..4d9fd60 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationBuilder.java
@@ -3,7 +3,6 @@ package org.apache.curator.x.rpc.configuration;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
 import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver;
-import io.dropwizard.configuration.ConfigurationException;
 import io.dropwizard.configuration.ConfigurationFactory;
 import io.dropwizard.configuration.ConfigurationFactoryFactory;
 import io.dropwizard.configuration.ConfigurationSourceProvider;
@@ -21,7 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 
-class ConfigurationBuilder
+public class ConfigurationBuilder
 {
     private final String configurationSource;
 
@@ -30,23 +29,30 @@ class ConfigurationBuilder
         LoggingFactory.bootstrap();
     }
 
-    ConfigurationBuilder(String configurationSource)
+    public ConfigurationBuilder(String configurationSource)
     {
         this.configurationSource = configurationSource;
     }
 
-    ConfigurationX build() throws IOException, ConfigurationException
+    public Configuration build() throws Exception
     {
         ObjectMapper mapper = new ObjectMapper();
         mapper.registerModule(new LogbackModule());
         mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy());
         SubtypeResolver subtypeResolver = new StdSubtypeResolver();
-        subtypeResolver.registerSubtypes(ConsoleAppenderFactory.class, FileAppenderFactory.class,
SyslogAppenderFactory.class);
+        subtypeResolver.registerSubtypes
+        (
+            ConsoleAppenderFactory.class,
+            FileAppenderFactory.class,
+            SyslogAppenderFactory.class,
+            ExponentialBackoffRetryConfiguration.class,
+            RetryNTimesConfiguration.class
+        );
         mapper.setSubtypeResolver(subtypeResolver);
 
         ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
-        ConfigurationFactoryFactory<ConfigurationX> factoryFactory = new DefaultConfigurationFactoryFactory<ConfigurationX>();
-        ConfigurationFactory<ConfigurationX> configurationFactory = factoryFactory.create(ConfigurationX.class,
validatorFactory.getValidator(), mapper, "curator");
+        ConfigurationFactoryFactory<Configuration> factoryFactory = new DefaultConfigurationFactoryFactory<Configuration>();
+        ConfigurationFactory<Configuration> configurationFactory = factoryFactory.create(Configuration.class,
validatorFactory.getValidator(), mapper, "curator");
         ConfigurationSourceProvider provider = new ConfigurationSourceProvider()
         {
             @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
deleted file mode 100644
index e9be8e1..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConfigurationX.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.apache.curator.x.rpc.configuration;
-
-import com.facebook.swift.service.ThriftServerConfig;
-import io.airlift.units.Duration;
-import io.dropwizard.logging.LoggingFactory;
-import java.util.concurrent.TimeUnit;
-
-public class ConfigurationX
-{
-    private ThriftServerConfig thrift = new ThriftServerConfig();
-    private LoggingFactory logging = new LoggingFactory();
-    private Duration projectionExpiration = new Duration(3, TimeUnit.MINUTES);
-    private Duration pingTime = new Duration(5, TimeUnit.SECONDS);
-
-    public LoggingFactory getLogging()
-    {
-        return logging;
-    }
-
-    public void setLogging(LoggingFactory logging)
-    {
-        this.logging = logging;
-    }
-
-    public ThriftServerConfig getThrift()
-    {
-        return thrift;
-    }
-
-    public void setThrift(ThriftServerConfig thrift)
-    {
-        this.thrift = thrift;
-    }
-
-    public Duration getProjectionExpiration()
-    {
-        return projectionExpiration;
-    }
-
-    public void setProjectionExpiration(Duration projectionExpiration)
-    {
-        this.projectionExpiration = projectionExpiration;
-    }
-
-    public Duration getPingTime()
-    {
-        return pingTime;
-    }
-
-    public void setPingTime(Duration pingTime)
-    {
-        this.pingTime = pingTime;
-    }
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
index 8209c6a..3e2f9a2 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ConnectionConfiguration.java
@@ -1,24 +1,34 @@
 package org.apache.curator.x.rpc.configuration;
 
-import io.airlift.configuration.Config;
-import io.airlift.configuration.ConfigDescription;
 import io.airlift.units.Duration;
+import javax.validation.constraints.NotNull;
 import java.util.concurrent.TimeUnit;
 
 public class ConnectionConfiguration
 {
+    @NotNull private String name;
     private String connectionString = "localhost:2181";
     private Duration sessionLength = new Duration(1, TimeUnit.MINUTES);
     private Duration connectionTimeout = new Duration(15, TimeUnit.SECONDS);
-    private RetryType retryType;
+    private AuthorizationConfiguration authorization = null;
+    private String namespace = null;
+    private RetryPolicyConfiguration retry = new ExponentialBackoffRetryConfiguration();
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
 
     public String getConnectionString()
     {
         return connectionString;
     }
 
-    @Config("curator.connection.$CONNECTION-NAME$.connection-string")
-    @ConfigDescription("Default ZooKeeper connection string. E.g. \"foo.com:2181,bar.com:2181\"")
     public void setConnectionString(String connectionString)
     {
         this.connectionString = connectionString;
@@ -29,8 +39,6 @@ public class ConnectionConfiguration
         return sessionLength;
     }
 
-    @Config("curator.connection.$CONNECTION-NAME$.session-length")
-    @ConfigDescription("Session length. Default is 1 minute")
     public void setSessionLength(Duration sessionLength)
     {
         this.sessionLength = sessionLength;
@@ -41,21 +49,38 @@ public class ConnectionConfiguration
         return connectionTimeout;
     }
 
-    @Config("curator.connection.$CONNECTION-NAME$.connection-timeout")
-    @ConfigDescription("Connection timeout. Default is 15 seconds")
     public void setConnectionTimeout(Duration connectionTimeout)
     {
         this.connectionTimeout = connectionTimeout;
     }
 
-    public RetryType getRetryType()
+    public AuthorizationConfiguration getAuthorization()
+    {
+        return authorization;
+    }
+
+    public void setAuthorization(AuthorizationConfiguration authorization)
+    {
+        this.authorization = authorization;
+    }
+
+    public String getNamespace()
+    {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace)
+    {
+        this.namespace = namespace;
+    }
+
+    public RetryPolicyConfiguration getRetry()
     {
-        return retryType;
+        return retry;
     }
 
-    @Config("curator.connection.$CONNECTION-NAME$.retry.type")
-    public void setRetryType(RetryType retryType)
+    public void setRetry(RetryPolicyConfiguration retry)
     {
-        this.retryType = retryType;
+        this.retry = retry;
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
index 41b8db8..7e02592 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/ExponentialBackoffRetryConfiguration.java
@@ -1,20 +1,28 @@
 package org.apache.curator.x.rpc.configuration;
 
-import io.airlift.configuration.Config;
+import com.fasterxml.jackson.annotation.JsonTypeName;
 import io.airlift.units.Duration;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import java.util.concurrent.TimeUnit;
 
-public class ExponentialBackoffRetryConfiguration
+@JsonTypeName("exponential-backoff")
+public class ExponentialBackoffRetryConfiguration extends RetryPolicyConfiguration
 {
-    private Duration baseSleepTime;
-    private int maxRetries;
-    private Duration maxSleep;
+    private Duration baseSleepTime = new Duration(100, TimeUnit.MILLISECONDS);
+    private int maxRetries = 3;
+
+    @Override
+    public RetryPolicy build()
+    {
+        return new ExponentialBackoffRetry((int)baseSleepTime.toMillis(), maxRetries);
+    }
 
     public Duration getBaseSleepTime()
     {
         return baseSleepTime;
     }
 
-    @Config("curator.retry.exponential.base-sleep-time")
     public void setBaseSleepTime(Duration baseSleepTime)
     {
         this.baseSleepTime = baseSleepTime;
@@ -25,20 +33,8 @@ public class ExponentialBackoffRetryConfiguration
         return maxRetries;
     }
 
-    @Config("curator.retry.exponential.max-retries")
     public void setMaxRetries(int maxRetries)
     {
         this.maxRetries = maxRetries;
     }
-
-    public Duration getMaxSleep()
-    {
-        return maxSleep;
-    }
-
-    @Config("curator.retry.exponential.max-sleep")
-    public void setMaxSleep(Duration maxSleep)
-    {
-        this.maxSleep = maxSleep;
-    }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java
new file mode 100644
index 0000000..97b25f2
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryNTimesConfiguration.java
@@ -0,0 +1,40 @@
+package org.apache.curator.x.rpc.configuration;
+
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import io.airlift.units.Duration;
+import org.apache.curator.RetryPolicy;
+import org.apache.curator.retry.RetryNTimes;
+import java.util.concurrent.TimeUnit;
+
+@JsonTypeName("ntimes")
+public class RetryNTimesConfiguration extends RetryPolicyConfiguration
+{
+    private Duration sleepBetweenRetries = new Duration(100, TimeUnit.MILLISECONDS);
+    private int n = 3;
+
+    @Override
+    public RetryPolicy build()
+    {
+        return new RetryNTimes(n, (int)sleepBetweenRetries.toMillis());
+    }
+
+    public Duration getSleepBetweenRetries()
+    {
+        return sleepBetweenRetries;
+    }
+
+    public void setSleepBetweenRetries(Duration sleepBetweenRetries)
+    {
+        this.sleepBetweenRetries = sleepBetweenRetries;
+    }
+
+    public int getN()
+    {
+        return n;
+    }
+
+    public void setN(int n)
+    {
+        this.n = n;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
new file mode 100644
index 0000000..463e148
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryPolicyConfiguration.java
@@ -0,0 +1,10 @@
+package org.apache.curator.x.rpc.configuration;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import org.apache.curator.RetryPolicy;
+
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
+public abstract class RetryPolicyConfiguration
+{
+    public abstract RetryPolicy build();
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryType.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryType.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryType.java
deleted file mode 100644
index 7e4761a..0000000
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/configuration/RetryType.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.apache.curator.x.rpc.configuration;
-
-public enum RetryType
-{
-    ExponentialBackoffRetry,
-}

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/main/resources/curator/help.txt
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/resources/curator/help.txt b/curator-x-rpc/src/main/resources/curator/help.txt
new file mode 100644
index 0000000..086654e
--- /dev/null
+++ b/curator-x-rpc/src/main/resources/curator/help.txt
@@ -0,0 +1,13 @@
+Curator RPC - an RPC server for using Apache Curator APIs and recipes from non JVM languages.
+
+Arguments:
+    <none>    show this help
+    <path>    path to a JSON or YAML configuration file
+    <string>  JSON or YAML object for configuration
+
+Curator RPC uses Dropwizard for configuration. The format is JSON or YAML (your choice).
+
+Curator also uses Dropwizard's logging module. The configuration for it is described here:
+http://dropwizard.readthedocs.org/en/latest/manual/configuration.html#logging
+
+TODO - more details to follow

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
b/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
index caf5af3..467af3c 100644
--- a/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
+++ b/curator-x-rpc/src/test/java/org/apache/curator/x/rpc/configuration/TestConfigurationBuilder.java
@@ -5,6 +5,8 @@ import com.google.common.collect.Sets;
 import com.google.common.io.Resources;
 import io.airlift.units.Duration;
 import io.dropwizard.logging.AppenderFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.retry.RetryNTimes;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 import java.net.URL;
@@ -17,7 +19,7 @@ public class TestConfigurationBuilder
     @Test
     public void testSimple() throws Exception
     {
-        ConfigurationX configuration = loadTestConfiguration("configuration/simple.json");
+        Configuration configuration = loadTestConfiguration("configuration/simple.json");
         Assert.assertEquals(configuration.getThrift().getPort(), 1234);
         Assert.assertEquals(configuration.getPingTime(), new Duration(10, TimeUnit.SECONDS));
     }
@@ -25,7 +27,7 @@ public class TestConfigurationBuilder
     @Test
     public void testLogging() throws Exception
     {
-        ConfigurationX configuration = loadTestConfiguration("configuration/logging.json");
+        Configuration configuration = loadTestConfiguration("configuration/logging.json");
         Assert.assertEquals(configuration.getLogging().getLevel(), Level.INFO);
         Assert.assertEquals(configuration.getLogging().getAppenders().size(), 2);
 
@@ -37,7 +39,24 @@ public class TestConfigurationBuilder
         Assert.assertEquals(types, Sets.newHashSet("FileAppenderFactory", "ConsoleAppenderFactory"));
     }
 
-    private ConfigurationX loadTestConfiguration(String name) throws Exception
+    @Test
+    public void testConnections() throws Exception
+    {
+        Configuration configuration = loadTestConfiguration("configuration/connections.json");
+        Assert.assertEquals(configuration.getConnections().size(), 2);
+
+        Assert.assertEquals(configuration.getConnections().get(0).getName(), "test");
+        Assert.assertEquals(configuration.getConnections().get(0).getConnectionString(),
"one:1,two:2");
+        Assert.assertEquals(configuration.getConnections().get(0).getConnectionTimeout(),
new Duration(20, TimeUnit.SECONDS));
+        Assert.assertEquals(configuration.getConnections().get(0).getRetry().build().getClass(),
ExponentialBackoffRetry.class);
+
+        Assert.assertEquals(configuration.getConnections().get(1).getName(), "alt");
+        Assert.assertEquals(configuration.getConnections().get(1).getConnectionString(),
"three:3,four:4");
+        Assert.assertEquals(configuration.getConnections().get(1).getConnectionTimeout(),
new Duration(30, TimeUnit.SECONDS));
+        Assert.assertEquals(configuration.getConnections().get(1).getRetry().build().getClass(),
RetryNTimes.class);
+    }
+
+    private Configuration loadTestConfiguration(String name) throws Exception
     {
         URL resource = Resources.getResource(name);
         String source = Resources.toString(resource, Charset.defaultCharset());

http://git-wip-us.apache.org/repos/asf/curator/blob/49d02946/curator-x-rpc/src/test/resources/configuration/connections.json
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/test/resources/configuration/connections.json b/curator-x-rpc/src/test/resources/configuration/connections.json
new file mode 100644
index 0000000..fb5f84a
--- /dev/null
+++ b/curator-x-rpc/src/test/resources/configuration/connections.json
@@ -0,0 +1,27 @@
+{
+    "connections": [
+        {
+            "name": "test",
+            "connectionString": "one:1,two:2",
+            "sessionLength": "3m",
+            "connectionTimeout": "20s",
+            "retry": {
+                "type": "exponential-backoff",
+                "baseSleepTime": "1s",
+                "maxRetries": 10
+            }
+        },
+
+        {
+            "name": "alt",
+            "connectionString": "three:3,four:4",
+            "sessionLength": "4m",
+            "connectionTimeout": "30s",
+            "retry": {
+                "type": "ntimes",
+                "sleepBetweenRetries": "1m",
+                "n": 10
+            }
+        }
+    ]
+}
\ No newline at end of file


Mime
View raw message