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 2014/05/28 00:17:52 UTC
[1/3] git commit: null checks
Repository: curator
Updated Branches:
refs/heads/curator-rpc 01e9cb0a8 -> 7f90dc40f
null checks
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/3b577984
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/3b577984
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/3b577984
Branch: refs/heads/curator-rpc
Commit: 3b5779841b02fd33e186dfc28bba463c7451dea8
Parents: 01e9cb0
Author: randgalt <ra...@apache.org>
Authored: Tue May 27 15:44:29 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 27 15:44:29 2014 -0500
----------------------------------------------------------------------
.../src/main/java/org/apache/curator/x/rpc/CuratorEntry.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/3b577984/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 bd6f207..c0e3524 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
@@ -101,13 +101,13 @@ public class CuratorEntry implements Closeable
public <T> T getThing(String id, Class<T> clazz)
{
- Entry entry = things.get(id);
+ Entry entry = (id != null) ? things.get(id) : null;
return cast(clazz, entry);
}
public boolean closeThing(String id)
{
- Entry entry = things.remove(id);
+ Entry entry = (id != null) ? things.remove(id) : null;
if ( entry != null )
{
//noinspection unchecked
[3/3] git commit: Beginnings of CLI
Posted by ra...@apache.org.
Beginnings of CLI
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7f90dc40
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7f90dc40
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7f90dc40
Branch: refs/heads/curator-rpc
Commit: 7f90dc40f7bc1c3a26a82b69a8377d741038a55a
Parents: 65b1ff4
Author: randgalt <ra...@apache.org>
Authored: Tue May 27 17:17:42 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 27 17:17:42 2014 -0500
----------------------------------------------------------------------
curator-x-rpc/pom.xml | 5 --
.../org/apache/curator/x/rpc/Configuration.java | 6 ---
.../curator/x/rpc/CuratorProjectionServer.java | 55 +++++++-------------
3 files changed, 19 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/7f90dc40/curator-x-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rpc/pom.xml b/curator-x-rpc/pom.xml
index ff6bc52..cf2442c 100644
--- a/curator-x-rpc/pom.xml
+++ b/curator-x-rpc/pom.xml
@@ -22,11 +22,6 @@
</dependency>
<dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/curator/blob/7f90dc40/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 a89016c..9c9eb77 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,13 +1,7 @@
package org.apache.curator.x.rpc;
import com.facebook.swift.service.ThriftServerConfig;
-import io.airlift.configuration.Config;
public class Configuration extends ThriftServerConfig
{
- @Config("hey")
- public void setHey(int hey)
- {
-
- }
}
http://git-wip-us.apache.org/repos/asf/curator/blob/7f90dc40/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 4606177..987071a 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,22 +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.io.Files;
-import io.airlift.configuration.Config;
+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 org.apache.curator.x.rpc.idl.event.EventService;
import org.apache.curator.x.rpc.idl.projection.CuratorProjectionService;
-import org.codehaus.jackson.map.AnnotationIntrospector;
-import org.codehaus.jackson.map.DeserializationConfig;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.introspect.AnnotatedMethod;
-import org.codehaus.jackson.map.introspect.NopAnnotationIntrospector;
-import org.codehaus.jackson.node.ObjectNode;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
-import java.nio.charset.Charset;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -64,31 +60,20 @@ public class CuratorProjectionServer
return;
}
- ObjectMapper objectMapper = new ObjectMapper();
- String options;
+ Map<String, String> options;
File f = new File(args[0]);
if ( f.exists() )
{
- options = Files.toString(f, Charset.defaultCharset());
+ options = new ConfigurationLoader().loadPropertiesFrom(f.getPath());
}
else
{
System.out.println("First argument is not a file. Treating the command line as a list of field/values");
- options = buildOptions(objectMapper, args);
+ options = buildOptions(args);
}
- AnnotationIntrospector introspector = new NopAnnotationIntrospector()
- {
- @Override
- public String findSettablePropertyName(AnnotatedMethod am)
- {
- Config config = am.getAnnotated().getAnnotation(Config.class);
- return (config != null) ? config.value() : super.findSettablePropertyName(am);
- }
- };
- DeserializationConfig deserializationConfig = objectMapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
- objectMapper.setDeserializationConfig(deserializationConfig);
- Configuration configuration = objectMapper.reader().withType(Configuration.class).readValue(options);
+ ConfigurationFactory configurationFactory = new ConfigurationFactory(options);
+ Configuration configuration = configurationFactory.build(Configuration.class);
final CuratorProjectionServer server = new CuratorProjectionServer(configuration);
server.start();
@@ -141,19 +126,17 @@ public class CuratorProjectionServer
System.out.println();
System.out.println("Values:");
- for ( Method method : Configuration.class.getMethods() )
+ ConfigurationMetadata<Configuration> metadata = ConfigurationMetadata.getConfigurationMetadata(Configuration.class);
+ for ( ConfigurationMetadata.AttributeMetadata attributeMetadata : metadata.getAttributes().values() )
{
- Config config = method.getAnnotation(Config.class);
- if ( (config != null) && (method.getParameterTypes().length == 1) )
- {
- System.out.println("\t" + config.value() + ": " + getType(method));
- }
+ ConfigurationMetadata.InjectionPointMetaData injectionPoint = attributeMetadata.getInjectionPoint();
+ System.out.println("\t" + injectionPoint.getProperty() + ": " + getType(attributeMetadata.getGetter()));
}
}
private static String getType(Method method)
{
- Class<?> type = method.getParameterTypes()[0];
+ Class<?> type = method.getReturnType();
String result = type.getSimpleName();
if ( type.equals(Duration.class) )
{
@@ -171,17 +154,17 @@ public class CuratorProjectionServer
return " (e.g. \"" + s + "\")";
}
- private static String buildOptions(ObjectMapper objectMapper, String[] args) throws IOException
+ private static Map<String, String> buildOptions(String[] args) throws IOException
{
- ObjectNode node = objectMapper.createObjectNode();
+ 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\"");
}
- node.put(args[i], args[i + 1]);
+ options.put(args[i], args[i + 1]);
}
- return objectMapper.writeValueAsString(node);
+ return options;
}
}
[2/3] git commit: temp checkin
Posted by ra...@apache.org.
temp checkin
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/65b1ff41
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/65b1ff41
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/65b1ff41
Branch: refs/heads/curator-rpc
Commit: 65b1ff417c369e6494522b703f6d938ef4d5895d
Parents: 3b57798
Author: randgalt <ra...@apache.org>
Authored: Tue May 27 17:01:23 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue May 27 17:01:23 2014 -0500
----------------------------------------------------------------------
curator-x-rpc/pom.xml | 5 +
.../org/apache/curator/x/rpc/Configuration.java | 13 ++
.../curator/x/rpc/CuratorProjectionServer.java | 153 ++++++++++++++++++-
3 files changed, 167 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/65b1ff41/curator-x-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rpc/pom.xml b/curator-x-rpc/pom.xml
index cf2442c..ff6bc52 100644
--- a/curator-x-rpc/pom.xml
+++ b/curator-x-rpc/pom.xml
@@ -22,6 +22,11 @@
</dependency>
<dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/curator/blob/65b1ff41/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
new file mode 100644
index 0000000..a89016c
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/Configuration.java
@@ -0,0 +1,13 @@
+package org.apache.curator.x.rpc;
+
+import com.facebook.swift.service.ThriftServerConfig;
+import io.airlift.configuration.Config;
+
+public class Configuration extends ThriftServerConfig
+{
+ @Config("hey")
+ public void setHey(int hey)
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/65b1ff41/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 75c304b..4606177 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
@@ -21,22 +21,167 @@ package org.apache.curator.x.rpc;
import com.facebook.swift.codec.ThriftCodecManager;
import com.facebook.swift.service.ThriftEventHandler;
import com.facebook.swift.service.ThriftServer;
-import com.facebook.swift.service.ThriftServerConfig;
import com.facebook.swift.service.ThriftServiceProcessor;
+import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import io.airlift.configuration.Config;
+import io.airlift.units.DataSize;
+import io.airlift.units.Duration;
import org.apache.curator.x.rpc.idl.event.EventService;
import org.apache.curator.x.rpc.idl.projection.CuratorProjectionService;
+import org.codehaus.jackson.map.AnnotationIntrospector;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.introspect.AnnotatedMethod;
+import org.codehaus.jackson.map.introspect.NopAnnotationIntrospector;
+import org.codehaus.jackson.node.ObjectNode;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
public class CuratorProjectionServer
{
- public static void main(String[] args)
+ private final RpcManager rpcManager;
+ private final ThriftServer server;
+ private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
+
+ private enum State
+ {
+ LATENT,
+ STARTED,
+ STOPPED
+ }
+
+ public static void main(String[] args) throws IOException
+ {
+ if ( (args.length == 0) || args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("-h") || args[0].equalsIgnoreCase("--help") )
+ {
+ printHelp();
+ return;
+ }
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ String options;
+ File f = new File(args[0]);
+ if ( f.exists() )
+ {
+ options = 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(objectMapper, args);
+ }
+
+ AnnotationIntrospector introspector = new NopAnnotationIntrospector()
+ {
+ @Override
+ public String findSettablePropertyName(AnnotatedMethod am)
+ {
+ Config config = am.getAnnotated().getAnnotation(Config.class);
+ return (config != null) ? config.value() : super.findSettablePropertyName(am);
+ }
+ };
+ DeserializationConfig deserializationConfig = objectMapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
+ objectMapper.setDeserializationConfig(deserializationConfig);
+ Configuration configuration = objectMapper.reader().withType(Configuration.class).readValue(options);
+
+ final CuratorProjectionServer server = new CuratorProjectionServer(configuration);
+ server.start();
+
+ Runnable shutdown = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ server.stop();
+ }
+ };
+ Thread hook = new Thread(shutdown);
+ Runtime.getRuntime().addShutdownHook(hook);
+ }
+
+ public CuratorProjectionServer(Configuration thriftServerConfig)
{
- RpcManager rpcManager = new RpcManager(TimeUnit.SECONDS.toMillis(10)); // TODO
+ rpcManager = new RpcManager(TimeUnit.SECONDS.toMillis(10));
EventService eventService = new EventService(rpcManager, 5000); // TODO
CuratorProjectionService projectionService = new CuratorProjectionService(rpcManager);
ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(), Lists.<ThriftEventHandler>newArrayList(), projectionService, eventService);
- ThriftServer server = new ThriftServer(processor, new ThriftServerConfig().setPort(8899)); // TODO
+ server = new ThriftServer(processor, thriftServerConfig);
+ }
+
+ public void start()
+ {
+ Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTED), "Already started");
+
server.start();
}
+
+ public void stop()
+ {
+ if ( state.compareAndSet(State.STARTED, State.STOPPED) )
+ {
+ rpcManager.close();
+ server.close();
+ }
+ }
+
+ private static void printHelp()
+ {
+ 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 JSON 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:");
+
+ for ( Method method : Configuration.class.getMethods() )
+ {
+ Config config = method.getAnnotation(Config.class);
+ if ( (config != null) && (method.getParameterTypes().length == 1) )
+ {
+ System.out.println("\t" + config.value() + ": " + getType(method));
+ }
+ }
+ }
+
+ private static String getType(Method method)
+ {
+ Class<?> type = method.getParameterTypes()[0];
+ 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));
+ }
+ return result;
+ }
+
+ private static String example(Object s)
+ {
+ return " (e.g. \"" + s + "\")";
+ }
+
+ private static String buildOptions(ObjectMapper objectMapper, String[] args) throws IOException
+ {
+ ObjectNode node = objectMapper.createObjectNode();
+ 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\"");
+ }
+ node.put(args[i], args[i + 1]);
+ }
+ return objectMapper.writeValueAsString(node);
+ }
}