curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject git commit: more work on CLI
Date Tue, 27 May 2014 22:40:58 GMT
Repository: curator
Updated Branches:
  refs/heads/curator-rpc 7f90dc40f -> f261b0cfd


more work on CLI


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

Branch: refs/heads/curator-rpc
Commit: f261b0cfd6c548f3c8768243b1feda53b484d5cd
Parents: 7f90dc4
Author: randgalt <randgalt@apache.org>
Authored: Tue May 27 17:40:51 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Tue May 27 17:40:51 2014 -0500

----------------------------------------------------------------------
 .../org/apache/curator/x/rpc/Configuration.java | 30 ++++++++++++
 .../org/apache/curator/x/rpc/CuratorEntry.java  |  2 +-
 .../curator/x/rpc/CuratorProjectionServer.java  | 49 +++++++++-----------
 .../curator/x/rpc/idl/event/EventService.java   |  4 +-
 4 files changed, 55 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/f261b0cf/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/Configuration.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/Configuration.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/Configuration.java
index 9c9eb77..ea361b3 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/Configuration.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/Configuration.java
@@ -1,7 +1,37 @@
 package org.apache.curator.x.rpc;
 
 import com.facebook.swift.service.ThriftServerConfig;
+import io.airlift.configuration.Config;
+import io.airlift.configuration.ConfigDescription;
+import io.airlift.units.Duration;
+import java.util.concurrent.TimeUnit;
 
 public class Configuration extends ThriftServerConfig
 {
+    private Duration projectionExpiration = new Duration(3, TimeUnit.MINUTES);
+    private Duration pingTime = new Duration(5, TimeUnit.SECONDS);
+
+    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;
+    }
+
+    public Duration getPingTime()
+    {
+        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;
+    }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/f261b0cf/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorEntry.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorEntry.java b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorEntry.java
index c0e3524..52f025d 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorEntry.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorEntry.java
@@ -66,7 +66,7 @@ public class CuratorEntry implements Closeable
         }
     }
 
-    public RpcCuratorEvent pollForEvent(int maxWaitMs) throws InterruptedException
+    public RpcCuratorEvent pollForEvent(long maxWaitMs) throws InterruptedException
     {
         if ( state.get() == State.OPEN )
         {

http://git-wip-us.apache.org/repos/asf/curator/blob/f261b0cf/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 987071a..f5e49f4 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
@@ -34,7 +34,6 @@ import org.apache.curator.x.rpc.idl.event.EventService;
 import org.apache.curator.x.rpc.idl.projection.CuratorProjectionService;
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
@@ -90,13 +89,13 @@ public class CuratorProjectionServer
         Runtime.getRuntime().addShutdownHook(hook);
     }
 
-    public CuratorProjectionServer(Configuration thriftServerConfig)
+    public CuratorProjectionServer(Configuration configuration)
     {
-        rpcManager = new RpcManager(TimeUnit.SECONDS.toMillis(10));
-        EventService eventService = new EventService(rpcManager, 5000); // TODO
+        rpcManager = new RpcManager(configuration.getProjectionExpiration().toMillis());
+        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, thriftServerConfig);
+        server = new ThriftServer(processor, configuration);
     }
 
     public void start()
@@ -121,37 +120,33 @@ public class CuratorProjectionServer
         System.out.println();
         System.out.println("Arguments:");
         System.out.println("\t<none>              show this help");
-        System.out.println("\t<path>              path to a JSON configuration file");
+        System.out.println("\t<path>              path to a properties configuration
file");
         System.out.println("\t<field value> ...   list of values that would be in the
JSON configuration file");
         System.out.println();
-        System.out.println("Values:");
 
+        System.out.println("Values:");
         ConfigurationMetadata<Configuration> metadata = ConfigurationMetadata.getConfigurationMetadata(Configuration.class);
         for ( ConfigurationMetadata.AttributeMetadata attributeMetadata : metadata.getAttributes().values()
)
         {
             ConfigurationMetadata.InjectionPointMetaData injectionPoint = attributeMetadata.getInjectionPoint();
-            System.out.println("\t" + injectionPoint.getProperty() + ": " + getType(attributeMetadata.getGetter()));
-        }
-    }
-
-    private static String getType(Method method)
-    {
-        Class<?> type = method.getReturnType();
-        String result = type.getSimpleName();
-        if ( type.equals(Duration.class) )
-        {
-            result += example(new Duration(10, TimeUnit.MINUTES));
-        }
-        else if ( type.equals(DataSize.class) )
-        {
-            result += example(new DataSize(1.5, DataSize.Unit.GIGABYTE));
+            System.out.println("\t" + injectionPoint.getProperty() + ": " + attributeMetadata.getGetter().getReturnType().getSimpleName());
+            if ( attributeMetadata.getDescription() != null )
+            {
+                System.out.println("\t\t" + attributeMetadata.getDescription());
+            }
+            System.out.println();
         }
-        return result;
-    }
 
-    private static String example(Object s)
-    {
-        return " (e.g. \"" + 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 Map<String, String> buildOptions(String[] args) throws IOException

http://git-wip-us.apache.org/repos/asf/curator/blob/f261b0cf/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/EventService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/EventService.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/EventService.java
index 939eaeb..13598c8 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/EventService.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/EventService.java
@@ -10,9 +10,9 @@ import org.apache.curator.x.rpc.idl.projection.CuratorProjection;
 public class EventService
 {
     private final RpcManager rpcManager;
-    private final int pingTimeMs;
+    private final long pingTimeMs;
 
-    public EventService(RpcManager rpcManager, int pingTimeMs)
+    public EventService(RpcManager rpcManager, long pingTimeMs)
     {
         this.rpcManager = rpcManager;
         this.pingTimeMs = pingTimeMs;


Mime
View raw message