curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [01/14] git commit: wip
Date Tue, 27 May 2014 13:57:23 GMT
Repository: curator
Updated Branches:
  refs/heads/curator-rpc [created] abf5fddae


wip


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

Branch: refs/heads/curator-rpc
Commit: b949f57b49600f53aa63d1f9fdad8a71e7d7a4df
Parents: cab78e6
Author: randgalt <randgalt@apache.org>
Authored: Sun May 25 23:04:50 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Sun May 25 23:04:50 2014 -0500

----------------------------------------------------------------------
 curator-x-rpc/pom.xml                           | 24 +++++++++++++
 .../curator/x/rpc/CuratorProjectionServer.java  | 20 +++++++++++
 .../curator/x/rpc/idl/CuratorProjection.java    | 23 +++++++++++++
 .../x/rpc/idl/CuratorProjectionService.java     | 36 ++++++++++++++++++++
 .../x/rpc/idl/CuratorProjectionSpec.java        |  8 +++++
 curator-x-rpc/src/main/scripts/generate.sh      | 25 ++++++++++++++
 curator-x-rpc/src/main/thrift/curator.thrift    | 16 +++++++++
 pom.xml                                         | 14 ++++++++
 8 files changed, 166 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/curator-x-rpc/pom.xml
----------------------------------------------------------------------
diff --git a/curator-x-rpc/pom.xml b/curator-x-rpc/pom.xml
new file mode 100644
index 0000000..42de982
--- /dev/null
+++ b/curator-x-rpc/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>apache-curator</artifactId>
+        <groupId>org.apache.curator</groupId>
+        <version>2.5.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>curator-x-rpc</artifactId>
+    <version>2.5.1-SNAPSHOT</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-recipes</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.facebook.swift</groupId>
+            <artifactId>swift-service</artifactId>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/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
new file mode 100644
index 0000000..22a5e3a
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/CuratorProjectionServer.java
@@ -0,0 +1,20 @@
+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.collect.Lists;
+import org.apache.curator.x.rpc.idl.CuratorProjectionService;
+
+public class CuratorProjectionServer
+{
+    public static void main(String[] args)
+    {
+        CuratorProjectionService projectionService = new CuratorProjectionService();
+        ThriftServiceProcessor processor = new ThriftServiceProcessor(new ThriftCodecManager(),
Lists.<ThriftEventHandler>newArrayList(), projectionService);
+        ThriftServer server = new ThriftServer(processor, new ThriftServerConfig().setPort(8899));
 // TODO
+        server.start();
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjection.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjection.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjection.java
new file mode 100644
index 0000000..85864c5
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjection.java
@@ -0,0 +1,23 @@
+package org.apache.curator.x.rpc.idl;
+
+import com.facebook.swift.codec.ThriftConstructor;
+import com.facebook.swift.codec.ThriftField;
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class CuratorProjection
+{
+    private final String id;
+
+    @ThriftConstructor
+    public CuratorProjection(String id)
+    {
+        this.id = id;
+    }
+
+    @ThriftField(1)
+    public String getId()
+    {
+        return id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
new file mode 100644
index 0000000..dd5bf33
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionService.java
@@ -0,0 +1,36 @@
+package org.apache.curator.x.rpc.idl;
+
+import com.facebook.swift.service.ThriftMethod;
+import com.facebook.swift.service.ThriftService;
+import com.google.common.collect.Maps;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import java.util.Map;
+import java.util.UUID;
+
+@ThriftService("curator")
+public class CuratorProjectionService
+{
+    private final Map<String, CuratorFramework> projections = Maps.newConcurrentMap();
+
+    @ThriftMethod
+    public CuratorProjection newCuratorProjection(CuratorProjectionSpec spec)
+    {
+        CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new
RetryOneTime(1));
+        String id = UUID.randomUUID().toString();
+        client.start();
+        projections.put(id, client);
+        return new CuratorProjection(id);
+    }
+
+    @ThriftMethod
+    public void closeCuratorProjection(CuratorProjection projection)
+    {
+        CuratorFramework client = projections.remove(projection.getId());
+        if ( client != null )
+        {
+            client.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionSpec.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionSpec.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionSpec.java
new file mode 100644
index 0000000..cf45632
--- /dev/null
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/CuratorProjectionSpec.java
@@ -0,0 +1,8 @@
+package org.apache.curator.x.rpc.idl;
+
+import com.facebook.swift.codec.ThriftStruct;
+
+@ThriftStruct
+public class CuratorProjectionSpec
+{
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/curator-x-rpc/src/main/scripts/generate.sh
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/scripts/generate.sh b/curator-x-rpc/src/main/scripts/generate.sh
new file mode 100755
index 0000000..ae3d575
--- /dev/null
+++ b/curator-x-rpc/src/main/scripts/generate.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+if (( $# != 1 )); then
+    echo "missing argument: path to swift2thrift-generator-cli-N.N.N-standalone.jar"
+    exit
+fi
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+BASE_DIR="$( cd "$DIR/../../../.." && pwd )"
+
+RPC_PATH="$BASE_DIR/curator-x-rpc/target/classes"
+CLASSES=""
+for f in `ls -m1 $RPC_PATH/org/apache/curator/x/rpc/idl/*.class | xargs -n 1 basename | sed
s/\.[^\.]*$//`; do CLASSES="$CLASSES $f"; done;
+
+THRIFT_DIR="$BASE_DIR/curator-x-rpc/src/main/thrift"
+
+PATHS="$1"
+PATHS="$PATHS:$BASE_DIR/curator-client/target/classes"
+PATHS="$PATHS:$BASE_DIR/curator-framework/target/classes"
+PATHS="$PATHS:$BASE_DIR/curator-recipes/target/classes"
+PATHS="$PATHS:$RPC_PATH"
+
+PACKAGE="org.apache.curator.x.rpc.idl"
+
+java -cp $PATHS com.facebook.swift.generator.swift2thrift.Main -namespace cpp org.apache.curator
-out "$THRIFT_DIR/curator.thrift" -package $PACKAGE $CLASSES

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/curator-x-rpc/src/main/thrift/curator.thrift
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/thrift/curator.thrift b/curator-x-rpc/src/main/thrift/curator.thrift
new file mode 100644
index 0000000..754002f
--- /dev/null
+++ b/curator-x-rpc/src/main/thrift/curator.thrift
@@ -0,0 +1,16 @@
+namespace java.swift org.apache.curator.x.rpc.idl
+namespace cpp org.apache.curator
+
+
+
+struct CuratorProjection {
+  1: string id;
+}
+
+struct CuratorProjectionSpec {
+}
+
+service curator {
+  void closeCuratorProjection(1: CuratorProjection projection);
+  CuratorProjection newCuratorProjection(1: CuratorProjectionSpec spec);
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/b949f57b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 78dd849..d9675c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,6 +84,7 @@
         <zookeeper-version>3.4.6</zookeeper-version>
         <guava-version>16.0.1</guava-version>
         <testng-version>6.8.8</testng-version>
+        <swift-version>0.12.0</swift-version>
 
         <!-- OSGi Properties -->
         <osgi.export.package />
@@ -253,6 +254,7 @@
         <module>curator-examples</module>
         <module>curator-x-discovery</module>
         <module>curator-x-discovery-server</module>
+        <module>curator-x-rpc</module>
     </modules>
 
     <dependencyManagement>
@@ -412,6 +414,18 @@
                 <artifactId>testng</artifactId>
                 <version>${testng-version}</version>
             </dependency>
+
+            <dependency>
+                <groupId>com.facebook.swift</groupId>
+                <artifactId>swift-codec</artifactId>
+                <version>${swift-version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.facebook.swift</groupId>
+                <artifactId>swift-service</artifactId>
+                <version>${swift-version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 


Mime
View raw message