Skip to content
Browse files

remove duplicated proto in java source tree.

  • Loading branch information...
1 parent 5f8012e commit cb79c7b8408843f7432ea6b78e14274aa12ecc10 @chenshuo committed Apr 24, 2012
View
1 java/README
@@ -0,0 +1 @@
+Set muduo.includedir in pom.xml before building.
View
30 java/pom.xml
@@ -12,6 +12,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <muduo.includedir>../../build/debug-install/include/muduo/net/protorpc</muduo.includedir>
</properties>
<build>
@@ -39,7 +40,34 @@
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
- <id>compile-protoc</id>
+ <id>compile-rpc-proto</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="target/generated-sources"/>
+ <path id="proto.path">
+ <fileset dir="${muduo.includedir}">
+ <include name="*.proto" />
+ </fileset>
+ </path>
+ <path id="proto.path2">
+ <pathelement location="${muduo.includedir}" />
+ </path>
+ <pathconvert pathsep=" " property="proto.files" refid="proto.path" />
+ <pathconvert pathsep=" " property="proto.include" refid="proto.path2" />
+ <exec executable="protoc" failonerror="true">
+ <arg value="--java_out=target/generated-sources"/>
+ <arg value="-I${proto.include}" />
+ <arg line="${proto.files}"/>
+ </exec>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>compile-protos</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
View
34 java/src/main/java/com/chenshuo/muduo/protorpc/rpc.proto
@@ -1,34 +0,0 @@
-package muduo.net;
-option java_package = "com.chenshuo.muduo.protorpc";
-option java_outer_classname = "RpcProto";
-
-enum MessageType
-{
- REQUEST = 1;
- RESPONSE = 2;
- ERROR = 3;
-}
-
-enum ErrorCode
-{
- NO_ERROR = 0;
- WRONG_PROTO = 1;
- NO_SERVICE = 2;
- NO_METHOD = 3;
- INVALID_REQUEST = 4;
- INVALID_RESPONSE = 5;
-}
-
-message RpcMessage
-{
- required MessageType type = 1;
- required fixed64 id = 2;
-
- optional string service = 3;
- optional string method = 4;
- optional bytes request = 5;
-
- optional bytes response = 6;
-
- optional ErrorCode error = 7;
-}
View
48 java/src/test/java/com/chenshuo/muduo/protorpc/RpcList.java
@@ -0,0 +1,48 @@
+package com.chenshuo.muduo.protorpc;
+
+import java.net.InetSocketAddress;
+
+import com.chenshuo.muduo.protorpc.RpcServiceProto.ListRpcRequest;
+import com.chenshuo.muduo.protorpc.RpcServiceProto.ListRpcResponse;
+import com.chenshuo.muduo.protorpc.RpcServiceProto.RpcService;
+
+public class RpcList {
+
+ private RpcClient client;
+ private RpcChannel channel;
+ RpcService.BlockingInterface rpcService;
+
+ public RpcList(InetSocketAddress addr) {
+ client = new RpcClient();
+ channel = client.blockingConnect(addr);
+ rpcService = RpcService.newBlockingStub(channel);
+ }
+
+ public void close() {
+ channel.disconnect();
+ client.stop();
+ }
+
+ public void listRpc(boolean listMethod) throws Exception {
+ ListRpcRequest request = ListRpcRequest.newBuilder().setListMethod(listMethod).build();
+ ListRpcResponse response = rpcService.listRpc(null, request);
+ System.out.println(response);
+ }
+
+ public void listOneService(String service, boolean listMethod) throws Exception {
+ ListRpcRequest request = ListRpcRequest.newBuilder().setServiceName(service).setListMethod(listMethod).build();
+ ListRpcResponse response = rpcService.listRpc(null, request);
+ System.out.println(response);
+ }
+
+ public static void main(String[] args) throws Exception {
+ InetSocketAddress addr = new InetSocketAddress(args[0], Integer.parseInt(args[1]));
+ RpcList rpcList = new RpcList(addr);
+ rpcList.listRpc(false);
+ rpcList.listRpc(true);
+ rpcList.listOneService("xxx", false);
+ rpcList.listOneService("zurg.SlaveService", false);
+ rpcList.listOneService("zurg.SlaveService", true);
+ rpcList.close();
+ }
+}

0 comments on commit cb79c7b

Please sign in to comment.
Something went wrong with that request. Please try again.