├── README.md ├── gRPC ├── golang │ ├── .gitignore │ ├── gen.sh │ ├── protos │ │ └── helloworld.proto │ └── src │ │ ├── client │ │ └── main.go │ │ ├── greeter │ │ └── helloworld.pb.go │ │ └── server │ │ └── main.go ├── java │ ├── .gitignore │ ├── dependency-reduced-pom.xml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── colobu │ │ │ └── rpctest │ │ │ ├── AppClient.java │ │ │ └── AppServer.java │ │ └── proto │ │ └── greeter.proto └── scala │ ├── .gitignore │ ├── README.md │ ├── project │ ├── Build.scala │ ├── build.properties │ └── plugins.sbt │ └── src │ ├── main │ ├── proto │ │ └── greeter.proto │ └── scala │ │ └── com │ │ └── colobu │ │ └── rpctest │ │ ├── AppClient.scala │ │ ├── AppServer.scala │ │ ├── GreeterGrpc.java │ │ └── GreeterOuterClass.java │ ├── templates │ └── bash-template │ └── universal │ └── conf │ └── application.conf └── thrift ├── golang ├── .gitignore ├── gen.sh ├── src │ ├── client │ │ └── main.go │ ├── greeter │ │ ├── constants.go │ │ ├── greeter-remote │ │ │ └── greeter-remote.go │ │ ├── greeter.go │ │ └── ttypes.go │ └── server │ │ └── main.go └── thrift │ └── helloworld.thrift ├── java ├── .gitignore ├── dependency-reduced-pom.xml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── colobu │ │ └── rpctest │ │ ├── AppClient.java │ │ ├── AppServer.java │ │ └── GreeterHandler.java │ └── thrift │ └── helloworld.thrift └── scala ├── .gitignore ├── README.md ├── project ├── Build.scala ├── build.properties └── plugins.sbt └── src ├── main ├── java │ └── com │ │ └── colobu │ │ └── rpctest │ │ └── Greeter.java ├── scala │ └── com │ │ └── colobu │ │ └── rpctest │ │ ├── AppClient.scala │ │ └── AppServer.scala └── thrift │ └── helloworld.thrift ├── templates └── bash-template └── universal └── conf └── application.conf /README.md: -------------------------------------------------------------------------------- 1 | ### Simple Thrift and gRPC performance test 2 | 3 | use a simple "helloworld" prototype to test thrift and gRPC. 4 | All servers and clients are implemented by Golang, Java And Scala 5 | 6 | Test result as follows (milliseconds/10000 calls). The first value is using one client to test servers and the second value is using 20 clients to test concurrently. 7 | 8 | | | Golang | Java | Scala | 9 | | ----- | ----- | ----- | ----- | 10 | | **Thrift** | 470/231 | 404/381 | 387/355 | 11 | | **gRPC** | 1375/970 | 4478/4205 | 4733/448 | 12 | 13 | -------------------------------------------------------------------------------- /gRPC/golang/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | pkg/ 3 | -------------------------------------------------------------------------------- /gRPC/golang/gen.sh: -------------------------------------------------------------------------------- 1 | #go get github.com/golang/protobuf/protoc-gen-go 2 | #go get github.com/golang/protobuf/proto 3 | #go get golang.org/x/net/context 4 | #go get google.golang.org/grpc 5 | 6 | protoc -I protos protos/helloworld.proto --go_out=plugins=grpc:src/greeter -------------------------------------------------------------------------------- /gRPC/golang/protos/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_package = "com.colobu.rpctest"; 4 | 5 | package greeter; 6 | 7 | // The greeting service definition. 8 | service Greeter { 9 | // Sends a greeting 10 | rpc SayHello (HelloRequest) returns (HelloReply) {} 11 | } 12 | 13 | // The request message containing the user's name. 14 | message HelloRequest { 15 | string name = 1; 16 | } 17 | 18 | // The response message containing the greetings 19 | message HelloReply { 20 | string message = 1; 21 | } -------------------------------------------------------------------------------- /gRPC/golang/src/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | "strconv" 8 | "sync" 9 | "time" 10 | 11 | pb "greeter" 12 | 13 | "golang.org/x/net/context" 14 | "google.golang.org/grpc" 15 | ) 16 | 17 | const ( 18 | address = "localhost:50051" 19 | defaultName = "world" 20 | ) 21 | 22 | func invoke(c pb.GreeterClient, name string) { 23 | r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name}) 24 | if err != nil { 25 | log.Fatalf("could not greet: %v", err) 26 | } 27 | _ = r 28 | } 29 | 30 | func syncTest(c pb.GreeterClient, name string) { 31 | i := 10000 32 | t := time.Now().UnixNano() 33 | for ; i>0; i-- { 34 | invoke(c, name) 35 | } 36 | fmt.Println("took", (time.Now().UnixNano() - t) / 1000000, "ms") 37 | } 38 | 39 | 40 | func asyncTest(c [20]pb.GreeterClient, name string) { 41 | var wg sync.WaitGroup 42 | wg.Add(10000) 43 | 44 | i := 10000 45 | t := time.Now().UnixNano() 46 | for ; i>0; i-- { 47 | go func() {invoke(c[i % 20], name);wg.Done()}() 48 | } 49 | wg.Wait() 50 | fmt.Println("took", (time.Now().UnixNano() - t) / 1000000, "ms") 51 | } 52 | 53 | 54 | func main() { 55 | // Set up a connection to the server. 56 | conn, err := grpc.Dial(address) 57 | if err != nil { 58 | log.Fatalf("did not connect: %v", err) 59 | } 60 | defer conn.Close() 61 | var c [20]pb.GreeterClient 62 | 63 | 64 | // Contact the server and print out its response. 65 | name := defaultName 66 | sync := true 67 | if len(os.Args) > 1 { 68 | sync, err = strconv.ParseBool(os.Args[1]) 69 | } 70 | 71 | //warm up 72 | i := 0 73 | for ; i < 20; i++ { 74 | c[i] = pb.NewGreeterClient(conn) 75 | invoke(c[i], name) 76 | } 77 | 78 | if sync { 79 | syncTest(c[0], name) 80 | } else { 81 | asyncTest(c, name) 82 | } 83 | } -------------------------------------------------------------------------------- /gRPC/golang/src/greeter/helloworld.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. 2 | // source: helloworld.proto 3 | // DO NOT EDIT! 4 | 5 | /* 6 | Package greeter is a generated protocol buffer package. 7 | 8 | It is generated from these files: 9 | helloworld.proto 10 | 11 | It has these top-level messages: 12 | HelloRequest 13 | HelloReply 14 | */ 15 | package greeter 16 | 17 | import proto "github.com/golang/protobuf/proto" 18 | 19 | import ( 20 | context "golang.org/x/net/context" 21 | grpc "google.golang.org/grpc" 22 | ) 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ context.Context 26 | var _ grpc.ClientConn 27 | 28 | // Reference imports to suppress errors if they are not otherwise used. 29 | var _ = proto.Marshal 30 | 31 | // The request message containing the user's name. 32 | type HelloRequest struct { 33 | Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` 34 | } 35 | 36 | func (m *HelloRequest) Reset() { *m = HelloRequest{} } 37 | func (m *HelloRequest) String() string { return proto.CompactTextString(m) } 38 | func (*HelloRequest) ProtoMessage() {} 39 | 40 | // The response message containing the greetings 41 | type HelloReply struct { 42 | Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"` 43 | } 44 | 45 | func (m *HelloReply) Reset() { *m = HelloReply{} } 46 | func (m *HelloReply) String() string { return proto.CompactTextString(m) } 47 | func (*HelloReply) ProtoMessage() {} 48 | 49 | // Client API for Greeter service 50 | 51 | type GreeterClient interface { 52 | // Sends a greeting 53 | SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) 54 | } 55 | 56 | type greeterClient struct { 57 | cc *grpc.ClientConn 58 | } 59 | 60 | func NewGreeterClient(cc *grpc.ClientConn) GreeterClient { 61 | return &greeterClient{cc} 62 | } 63 | 64 | func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { 65 | out := new(HelloReply) 66 | err := grpc.Invoke(ctx, "/greeter.Greeter/SayHello", in, out, c.cc, opts...) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, nil 71 | } 72 | 73 | // Server API for Greeter service 74 | 75 | type GreeterServer interface { 76 | // Sends a greeting 77 | SayHello(context.Context, *HelloRequest) (*HelloReply, error) 78 | } 79 | 80 | func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { 81 | s.RegisterService(&_Greeter_serviceDesc, srv) 82 | } 83 | 84 | func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { 85 | in := new(HelloRequest) 86 | if err := codec.Unmarshal(buf, in); err != nil { 87 | return nil, err 88 | } 89 | out, err := srv.(GreeterServer).SayHello(ctx, in) 90 | if err != nil { 91 | return nil, err 92 | } 93 | return out, nil 94 | } 95 | 96 | var _Greeter_serviceDesc = grpc.ServiceDesc{ 97 | ServiceName: "greeter.Greeter", 98 | HandlerType: (*GreeterServer)(nil), 99 | Methods: []grpc.MethodDesc{ 100 | { 101 | MethodName: "SayHello", 102 | Handler: _Greeter_SayHello_Handler, 103 | }, 104 | }, 105 | Streams: []grpc.StreamDesc{}, 106 | } 107 | -------------------------------------------------------------------------------- /gRPC/golang/src/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | 7 | pb "greeter" 8 | "golang.org/x/net/context" 9 | "google.golang.org/grpc" 10 | ) 11 | 12 | const ( 13 | port = ":50051" 14 | ) 15 | 16 | type server struct{} 17 | 18 | // SayHello implements helloworld.GreeterServer 19 | func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { 20 | return &pb.HelloReply{Message: "Hello " + in.Name}, nil 21 | } 22 | 23 | func main() { 24 | lis, err := net.Listen("tcp", port) 25 | if err != nil { 26 | log.Fatalf("failed to listen: %v", err) 27 | } 28 | s := grpc.NewServer() 29 | pb.RegisterGreeterServer(s, &server{}) 30 | s.Serve(lis) 31 | } -------------------------------------------------------------------------------- /gRPC/java/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .settings/ 3 | target/ 4 | *.iml 5 | *.log* 6 | .cache 7 | .classpath 8 | .project 9 | .DS_Store 10 | -------------------------------------------------------------------------------- /gRPC/java/dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.colobu.rpctest 5 | grpctest 6 | grpctest 7 | 1.0-SNAPSHOT 8 | http://maven.apache.org 9 | 10 | 11 | 12 | kr.motd.maven 13 | os-maven-plugin 14 | 1.2.3.Final 15 | 16 | 17 | 18 | 19 | com.google.protobuf.tools 20 | maven-protoc-plugin 21 | 0.4.2 22 | 23 | 24 | 25 | compile 26 | compile-custom 27 | 28 | 29 | 30 | 31 | com.google.protobuf:protoc:3.0.0-alpha-3.1:exe:${os.detected.classifier} 32 | grpc-java 33 | io.grpc:protoc-gen-grpc-java:0.7.1:exe:${os.detected.classifier} 34 | 35 | 36 | 37 | maven-shade-plugin 38 | 2.4.1 39 | 40 | 41 | package 42 | 43 | shade 44 | 45 | 46 | 47 | 48 | com.colobu.rpctest.AppServer 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | never 61 | 62 | 63 | false 64 | 65 | central 66 | Central Repository 67 | https://repo.maven.apache.org/maven2 68 | 69 | 70 | protoc-plugin 71 | https://dl.bintray.com/sergei-ivanov/maven/ 72 | 73 | 74 | 75 | 76 | junit 77 | junit 78 | 3.8.1 79 | test 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /gRPC/java/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.colobu.rpctest 5 | grpctest 6 | jar 7 | 1.0-SNAPSHOT 8 | grpctest 9 | http://maven.apache.org 10 | 11 | 12 | io.grpc 13 | grpc-all 14 | 0.7.1 15 | 16 | 17 | junit 18 | junit 19 | 3.8.1 20 | test 21 | 22 | 23 | 24 | 25 | 26 | never 27 | 28 | 29 | false 30 | 31 | central 32 | Central Repository 33 | https://repo.maven.apache.org/maven2 34 | 35 | 36 | protoc-plugin 37 | https://dl.bintray.com/sergei-ivanov/maven/ 38 | 39 | 40 | 41 | 42 | 43 | kr.motd.maven 44 | os-maven-plugin 45 | 1.2.3.Final 46 | 47 | 48 | 49 | 50 | com.google.protobuf.tools 51 | maven-protoc-plugin 52 | 0.4.2 53 | 54 | com.google.protobuf:protoc:3.0.0-alpha-3.1:exe:${os.detected.classifier} 55 | grpc-java 56 | io.grpc:protoc-gen-grpc-java:0.7.1:exe:${os.detected.classifier} 57 | 58 | 59 | 60 | 61 | compile 62 | compile-custom 63 | 64 | 65 | 66 | 67 | 68 | org.apache.maven.plugins 69 | maven-shade-plugin 70 | 2.4.1 71 | 72 | 73 | package 74 | 75 | shade 76 | 77 | 78 | 79 | 80 | com.colobu.rpctest.AppServer 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /gRPC/java/src/main/java/com/colobu/rpctest/AppClient.java: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | import java.util.concurrent.TimeUnit; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | import io.grpc.ChannelImpl; 10 | import io.grpc.transport.netty.NegotiationType; 11 | import io.grpc.transport.netty.NettyChannelBuilder; 12 | 13 | public class AppClient { 14 | private static final Logger logger = Logger.getLogger(AppClient.class.getName()); 15 | 16 | private final ChannelImpl channel; 17 | private final GreeterGrpc.GreeterBlockingStub blockingStub; 18 | 19 | public AppClient(String host, int port) { 20 | channel = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build(); 21 | blockingStub = GreeterGrpc.newBlockingStub(channel); 22 | } 23 | 24 | public void shutdown() throws InterruptedException { 25 | channel.shutdown().awaitTerminated(5, TimeUnit.SECONDS); 26 | } 27 | 28 | public void greet(String name) { 29 | try { 30 | //logger.info("Will try to greet " + name + " ..."); 31 | GreeterOuterClass.HelloRequest request = GreeterOuterClass.HelloRequest.newBuilder().setName(name).build(); 32 | GreeterOuterClass.HelloReply response = blockingStub.sayHello(request); 33 | //logger.info("Greeting: " + response.getMessage()); 34 | } 35 | catch (RuntimeException e) { 36 | logger.log(Level.WARNING, "RPC failed", e); 37 | return; 38 | } 39 | } 40 | 41 | public static void syncTest(AppClient client, String user) { 42 | long t = System.nanoTime(); 43 | for (int i = 0; i < 10000; i++) { client.greet(user); } 44 | System.out.println("took: " + (System.nanoTime() - t) / 1000000 + " ms"); 45 | } 46 | 47 | public static void asyncTest(final AppClient[] client, final String user) { 48 | ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); 49 | final CountDownLatch latch = new CountDownLatch(10000); 50 | long t = System.nanoTime(); 51 | for (int i = 0; i < 10000; i++) { 52 | final int j = i; 53 | pool.submit(new Runnable() { 54 | @Override 55 | public void run() { 56 | client[j % 20].greet(user); 57 | latch.countDown(); 58 | } 59 | }); 60 | } 61 | try { 62 | latch.await(); 63 | } 64 | catch (InterruptedException e) { 65 | e.printStackTrace(); 66 | } 67 | System.out.println("took: " + (System.nanoTime() - t) / 1000000 + " ms"); 68 | pool.shutdownNow(); 69 | } 70 | 71 | public static void main(String[] args) throws Exception { 72 | AppClient[] client = new AppClient[20]; 73 | try { 74 | String user = "world"; 75 | 76 | int i = 0; 77 | for (i = 0; i < 20; i++) { 78 | client[i] = new AppClient("localhost", 50051); 79 | client[i].greet(user); 80 | } 81 | 82 | boolean sync = true; 83 | if (args.length > 0) { 84 | sync = Boolean.parseBoolean(args[0]); 85 | } 86 | 87 | if (sync) { syncTest(client[0], user); } 88 | else { asyncTest(client, user); } 89 | } 90 | finally { 91 | 92 | for (int i = 0; i < 20; i++) { 93 | client[i].shutdown(); 94 | } 95 | 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /gRPC/java/src/main/java/com/colobu/rpctest/AppServer.java: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest; 2 | 3 | import java.util.logging.Logger; 4 | import io.grpc.ServerImpl; 5 | import io.grpc.stub.StreamObserver; 6 | import io.grpc.transport.netty.NettyServerBuilder; 7 | 8 | public class AppServer 9 | { 10 | private static final Logger logger = Logger.getLogger(AppServer.class.getName()); 11 | 12 | /* The port on which the server should run */ 13 | private int port = 50051; 14 | private ServerImpl server; 15 | 16 | private void start() throws Exception { 17 | server = NettyServerBuilder.forPort(port) 18 | .addService(GreeterGrpc.bindService(new GreeterImpl())) 19 | .build().start(); 20 | logger.info("Server started, listening on " + port); 21 | Runtime.getRuntime().addShutdownHook(new Thread() { 22 | @Override 23 | public void run() { 24 | System.err.println("*** shutting down gRPC server since JVM is shutting down"); 25 | AppServer.this.stop(); 26 | System.err.println("*** server shut down"); 27 | } 28 | }); 29 | } 30 | 31 | private void stop() { 32 | if (server != null) { 33 | server.shutdown(); 34 | } 35 | } 36 | 37 | public static void main(String[] args) throws Exception { 38 | final AppServer server = new AppServer(); 39 | server.start(); 40 | } 41 | 42 | private class GreeterImpl implements GreeterGrpc.Greeter { 43 | 44 | @Override 45 | public void sayHello(GreeterOuterClass.HelloRequest req, StreamObserver responseObserver) { 46 | GreeterOuterClass.HelloReply reply = GreeterOuterClass.HelloReply.newBuilder().setMessage("Hello " + req.getName()).build(); 47 | responseObserver.onValue(reply); 48 | responseObserver.onCompleted(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /gRPC/java/src/main/proto/greeter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_package = "com.colobu.rpctest"; 4 | 5 | package greeter; 6 | 7 | // The greeting service definition. 8 | service Greeter { 9 | // Sends a greeting 10 | rpc SayHello (HelloRequest) returns (HelloReply) {} 11 | } 12 | 13 | // The request message containing the user's name. 14 | message HelloRequest { 15 | string name = 1; 16 | } 17 | 18 | // The response message containing the greetings 19 | message HelloReply { 20 | string message = 1; 21 | } -------------------------------------------------------------------------------- /gRPC/scala/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .settings/ 3 | target/ 4 | *.iml 5 | *.log* 6 | 7 | *.class 8 | *.log 9 | -------------------------------------------------------------------------------- /gRPC/scala/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## SBT support 3 | https://github.com/sbt/sbt-protobuf/issues/31 4 | -------------------------------------------------------------------------------- /gRPC/scala/project/Build.scala: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat 2 | import java.util.Date 3 | 4 | import com.typesafe.sbt.packager.archetypes.JavaAppPackaging 5 | import com.typesafe.sbt.packager.universal.UniversalDeployPlugin 6 | import sbt.Defaults._ 7 | import sbt.Keys._ 8 | import sbt._ 9 | import sbtbuildinfo.Plugin.{BuildInfoKey, _} 10 | import sbtrelease.ReleasePlugin._ 11 | 12 | object ApplicationBuild extends Build { 13 | 14 | lazy val root = Project("gRPC", file(".")) 15 | .settings(coreDefaultSettings: _*) 16 | .settings(libraryDependencies ++= Seq("io.grpc" % "grpc-all" % "0.7.1")) 17 | .settings(mainClass in Compile := Some("com.colobu.rpctest.AppServer")) 18 | .enablePlugins(JavaAppPackaging) 19 | } -------------------------------------------------------------------------------- /gRPC/scala/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.5 -------------------------------------------------------------------------------- /gRPC/scala/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" 2 | 3 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4") 4 | 5 | addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1") 6 | 7 | addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8") 8 | 9 | addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.2") 10 | 11 | addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4") 12 | 13 | addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0") 14 | 15 | addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8.5") -------------------------------------------------------------------------------- /gRPC/scala/src/main/proto/greeter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option java_package = "com.colobu.rpctest"; 4 | 5 | package greeter; 6 | 7 | // The greeting service definition. 8 | service Greeter { 9 | // Sends a greeting 10 | rpc SayHello (HelloRequest) returns (HelloReply) {} 11 | } 12 | 13 | // The request message containing the user's name. 14 | message HelloRequest { 15 | string name = 1; 16 | } 17 | 18 | // The response message containing the greetings 19 | message HelloReply { 20 | string message = 1; 21 | } -------------------------------------------------------------------------------- /gRPC/scala/src/main/scala/com/colobu/rpctest/AppClient.scala: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest 2 | 3 | import java.util.concurrent.{Executors, CountDownLatch, TimeUnit} 4 | import io.grpc.ChannelImpl 5 | import io.grpc.transport.netty.{NegotiationType, NettyChannelBuilder} 6 | 7 | object AppClient extends App{ 8 | val host = "127.0.0.1" 9 | val port = 50051 10 | //var channel:ChannelImpl = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build() 11 | //val blockingStub:GreeterGrpc.GreeterBlockingStub = GreeterGrpc.newBlockingStub(channel) 12 | 13 | var channel = new Array[ChannelImpl](20) 14 | var blockingStub = new Array[GreeterGrpc.GreeterBlockingStub](20) 15 | 16 | 17 | def shutdown():Unit = { 18 | for (i <- 0 to 19) { 19 | channel(i).shutdown().awaitTerminated(5, TimeUnit.SECONDS) 20 | } 21 | 22 | } 23 | 24 | def greet(stub:GreeterGrpc.GreeterBlockingStub, name:String):Unit = { 25 | try { 26 | //println("Will try to greet " + name + " ..."); 27 | val request = GreeterOuterClass.HelloRequest.newBuilder().setName(name).build() 28 | val response = stub.sayHello(request) 29 | //println("Greeting: " + response.getMessage()); 30 | } 31 | catch { 32 | case e:Throwable => println("failed", e) 33 | } 34 | } 35 | 36 | def syncTest():Unit = { 37 | val t = System.nanoTime() 38 | for (i <- 1 to 10000) 39 | greet(blockingStub(0),user) 40 | println("took: " + (System.nanoTime() - t) /1000000 + " ms") 41 | } 42 | 43 | def asyncTest():Unit = { 44 | val latch = new CountDownLatch(10000) 45 | val pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2) 46 | val t = System.nanoTime() 47 | for (i <- 1 to 10000) 48 | pool.submit(new Runnable { 49 | override def run(): Unit = {greet(blockingStub(i%20), user); latch.countDown()} 50 | }) 51 | latch.await() 52 | println("took: " + (System.nanoTime() - t) /1000000 + " ms") 53 | pool.shutdownNow() 54 | } 55 | 56 | var user = "world" 57 | var sync = true 58 | if (args.length > 0) { 59 | sync = args(0).toBoolean 60 | } 61 | 62 | //warmup 63 | for (i <- 0 to 19) { 64 | channel(i) = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build() 65 | blockingStub(i) = GreeterGrpc.newBlockingStub(channel(i)) 66 | greet(blockingStub(i), user) 67 | } 68 | 69 | if (sync) 70 | syncTest() 71 | else 72 | asyncTest 73 | 74 | shutdown() 75 | } 76 | -------------------------------------------------------------------------------- /gRPC/scala/src/main/scala/com/colobu/rpctest/AppServer.scala: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest 2 | 3 | import io.grpc.ServerImpl 4 | import io.grpc.stub.StreamObserver 5 | import io.grpc.transport.netty.NettyServerBuilder 6 | 7 | object AppServer extends App { 8 | val port = 50051 9 | var server: ServerImpl = _ 10 | 11 | def start(): Unit = { 12 | server = NettyServerBuilder.forPort(port) 13 | .addService(GreeterGrpc.bindService(new GreeterImpl())) 14 | .build().start() 15 | 16 | println("Server started, listening on " + port) 17 | sys.addShutdownHook({ 18 | println("*** shutting down gRPC server since JVM is shutting down") 19 | stop() 20 | println("*** server shut down") 21 | }) 22 | } 23 | 24 | 25 | def stop(): Unit = { 26 | if (server != null) { 27 | server.shutdown() 28 | } 29 | } 30 | 31 | start() 32 | 33 | private class GreeterImpl extends GreeterGrpc.Greeter { 34 | @Override 35 | def sayHello(req: GreeterOuterClass.HelloRequest, responseObserver: StreamObserver[GreeterOuterClass.HelloReply]) { 36 | val reply = GreeterOuterClass.HelloReply.newBuilder().setMessage("Hello " + req.getName()).build() 37 | responseObserver.onValue(reply) 38 | responseObserver.onCompleted() 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /gRPC/scala/src/main/scala/com/colobu/rpctest/GreeterGrpc.java: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest; 2 | 3 | import static io.grpc.stub.Calls.createMethodDescriptor; 4 | import static io.grpc.stub.Calls.asyncUnaryCall; 5 | import static io.grpc.stub.Calls.asyncServerStreamingCall; 6 | import static io.grpc.stub.Calls.asyncClientStreamingCall; 7 | import static io.grpc.stub.Calls.duplexStreamingCall; 8 | import static io.grpc.stub.Calls.blockingUnaryCall; 9 | import static io.grpc.stub.Calls.blockingServerStreamingCall; 10 | import static io.grpc.stub.Calls.unaryFutureCall; 11 | import static io.grpc.stub.ServerCalls.createMethodDefinition; 12 | import static io.grpc.stub.ServerCalls.asyncUnaryRequestCall; 13 | import static io.grpc.stub.ServerCalls.asyncStreamingRequestCall; 14 | 15 | @javax.annotation.Generated("by gRPC proto compiler") 16 | public class GreeterGrpc { 17 | 18 | private static final io.grpc.stub.Method METHOD_SAY_HELLO = 20 | io.grpc.stub.Method.create( 21 | io.grpc.MethodType.UNARY, "SayHello", 22 | io.grpc.protobuf.ProtoUtils.marshaller(com.colobu.rpctest.GreeterOuterClass.HelloRequest.PARSER), 23 | io.grpc.protobuf.ProtoUtils.marshaller(com.colobu.rpctest.GreeterOuterClass.HelloReply.PARSER)); 24 | 25 | public static GreeterStub newStub(io.grpc.Channel channel) { 26 | return new GreeterStub(channel, CONFIG); 27 | } 28 | 29 | public static GreeterBlockingStub newBlockingStub( 30 | io.grpc.Channel channel) { 31 | return new GreeterBlockingStub(channel, CONFIG); 32 | } 33 | 34 | public static GreeterFutureStub newFutureStub( 35 | io.grpc.Channel channel) { 36 | return new GreeterFutureStub(channel, CONFIG); 37 | } 38 | 39 | public static final GreeterServiceDescriptor CONFIG = 40 | new GreeterServiceDescriptor(); 41 | 42 | @javax.annotation.concurrent.Immutable 43 | public static class GreeterServiceDescriptor extends 44 | io.grpc.stub.AbstractServiceDescriptor { 45 | public final io.grpc.MethodDescriptor sayHello; 47 | 48 | private GreeterServiceDescriptor() { 49 | sayHello = createMethodDescriptor( 50 | "greeter.Greeter", METHOD_SAY_HELLO); 51 | } 52 | 53 | @SuppressWarnings("unchecked") 54 | private GreeterServiceDescriptor( 55 | java.util.Map> methodMap) { 56 | sayHello = (io.grpc.MethodDescriptor) methodMap.get( 58 | CONFIG.sayHello.getName()); 59 | } 60 | 61 | @java.lang.Override 62 | protected GreeterServiceDescriptor build( 63 | java.util.Map> methodMap) { 64 | return new GreeterServiceDescriptor(methodMap); 65 | } 66 | 67 | @java.lang.Override 68 | public com.google.common.collect.ImmutableList> methods() { 69 | return com.google.common.collect.ImmutableList.>of( 70 | sayHello); 71 | } 72 | } 73 | 74 | public static interface Greeter { 75 | 76 | public void sayHello(com.colobu.rpctest.GreeterOuterClass.HelloRequest request, 77 | io.grpc.stub.StreamObserver responseObserver); 78 | } 79 | 80 | public static interface GreeterBlockingClient { 81 | 82 | public com.colobu.rpctest.GreeterOuterClass.HelloReply sayHello(com.colobu.rpctest.GreeterOuterClass.HelloRequest request); 83 | } 84 | 85 | public static interface GreeterFutureClient { 86 | 87 | public com.google.common.util.concurrent.ListenableFuture sayHello( 88 | com.colobu.rpctest.GreeterOuterClass.HelloRequest request); 89 | } 90 | 91 | public static class GreeterStub extends 92 | io.grpc.stub.AbstractStub 93 | implements Greeter { 94 | private GreeterStub(io.grpc.Channel channel, 95 | GreeterServiceDescriptor config) { 96 | super(channel, config); 97 | } 98 | 99 | @java.lang.Override 100 | protected GreeterStub build(io.grpc.Channel channel, 101 | GreeterServiceDescriptor config) { 102 | return new GreeterStub(channel, config); 103 | } 104 | 105 | @java.lang.Override 106 | public void sayHello(com.colobu.rpctest.GreeterOuterClass.HelloRequest request, 107 | io.grpc.stub.StreamObserver responseObserver) { 108 | asyncUnaryCall( 109 | channel.newCall(config.sayHello), request, responseObserver); 110 | } 111 | } 112 | 113 | public static class GreeterBlockingStub extends 114 | io.grpc.stub.AbstractStub 115 | implements GreeterBlockingClient { 116 | private GreeterBlockingStub(io.grpc.Channel channel, 117 | GreeterServiceDescriptor config) { 118 | super(channel, config); 119 | } 120 | 121 | @java.lang.Override 122 | protected GreeterBlockingStub build(io.grpc.Channel channel, 123 | GreeterServiceDescriptor config) { 124 | return new GreeterBlockingStub(channel, config); 125 | } 126 | 127 | @java.lang.Override 128 | public com.colobu.rpctest.GreeterOuterClass.HelloReply sayHello(com.colobu.rpctest.GreeterOuterClass.HelloRequest request) { 129 | return blockingUnaryCall( 130 | channel.newCall(config.sayHello), request); 131 | } 132 | } 133 | 134 | public static class GreeterFutureStub extends 135 | io.grpc.stub.AbstractStub 136 | implements GreeterFutureClient { 137 | private GreeterFutureStub(io.grpc.Channel channel, 138 | GreeterServiceDescriptor config) { 139 | super(channel, config); 140 | } 141 | 142 | @java.lang.Override 143 | protected GreeterFutureStub build(io.grpc.Channel channel, 144 | GreeterServiceDescriptor config) { 145 | return new GreeterFutureStub(channel, config); 146 | } 147 | 148 | @java.lang.Override 149 | public com.google.common.util.concurrent.ListenableFuture sayHello( 150 | com.colobu.rpctest.GreeterOuterClass.HelloRequest request) { 151 | return unaryFutureCall( 152 | channel.newCall(config.sayHello), request); 153 | } 154 | } 155 | 156 | public static io.grpc.ServerServiceDefinition bindService( 157 | final Greeter serviceImpl) { 158 | return io.grpc.ServerServiceDefinition.builder("greeter.Greeter") 159 | .addMethod(createMethodDefinition( 160 | METHOD_SAY_HELLO, 161 | asyncUnaryRequestCall( 162 | new io.grpc.stub.ServerCalls.UnaryRequestMethod< 163 | com.colobu.rpctest.GreeterOuterClass.HelloRequest, 164 | com.colobu.rpctest.GreeterOuterClass.HelloReply>() { 165 | @java.lang.Override 166 | public void invoke( 167 | com.colobu.rpctest.GreeterOuterClass.HelloRequest request, 168 | io.grpc.stub.StreamObserver responseObserver) { 169 | serviceImpl.sayHello(request, responseObserver); 170 | } 171 | }))).build(); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /gRPC/scala/src/main/scala/com/colobu/rpctest/GreeterOuterClass.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: greeter.proto 3 | 4 | package com.colobu.rpctest; 5 | 6 | public final class GreeterOuterClass { 7 | private GreeterOuterClass() {} 8 | public static void registerAllExtensions( 9 | com.google.protobuf.ExtensionRegistry registry) { 10 | } 11 | public interface HelloRequestOrBuilder extends 12 | // @@protoc_insertion_point(interface_extends:greeter.HelloRequest) 13 | com.google.protobuf.MessageOrBuilder { 14 | 15 | /** 16 | * optional string name = 1; 17 | */ 18 | java.lang.String getName(); 19 | /** 20 | * optional string name = 1; 21 | */ 22 | com.google.protobuf.ByteString 23 | getNameBytes(); 24 | } 25 | /** 26 | * Protobuf type {@code greeter.HelloRequest} 27 | * 28 | *
 29 |    * The request message containing the user's name.
 30 |    * 
31 | */ 32 | public static final class HelloRequest extends 33 | com.google.protobuf.GeneratedMessage implements 34 | // @@protoc_insertion_point(message_implements:greeter.HelloRequest) 35 | HelloRequestOrBuilder { 36 | // Use HelloRequest.newBuilder() to construct. 37 | private HelloRequest(com.google.protobuf.GeneratedMessage.Builder builder) { 38 | super(builder); 39 | } 40 | private HelloRequest() { 41 | name_ = ""; 42 | } 43 | 44 | @java.lang.Override 45 | public final com.google.protobuf.UnknownFieldSet 46 | getUnknownFields() { 47 | return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); 48 | } 49 | private HelloRequest( 50 | com.google.protobuf.CodedInputStream input, 51 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) { 52 | this(); 53 | int mutable_bitField0_ = 0; 54 | try { 55 | boolean done = false; 56 | while (!done) { 57 | int tag = input.readTag(); 58 | switch (tag) { 59 | case 0: 60 | done = true; 61 | break; 62 | default: { 63 | if (!input.skipField(tag)) { 64 | done = true; 65 | } 66 | break; 67 | } 68 | case 10: { 69 | com.google.protobuf.ByteString bs = input.readBytes(); 70 | 71 | name_ = bs; 72 | break; 73 | } 74 | } 75 | } 76 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 77 | throw new RuntimeException(e.setUnfinishedMessage(this)); 78 | } catch (java.io.IOException e) { 79 | throw new RuntimeException( 80 | new com.google.protobuf.InvalidProtocolBufferException( 81 | e.getMessage()).setUnfinishedMessage(this)); 82 | } finally { 83 | makeExtensionsImmutable(); 84 | } 85 | } 86 | public static final com.google.protobuf.Descriptors.Descriptor 87 | getDescriptor() { 88 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloRequest_descriptor; 89 | } 90 | 91 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 92 | internalGetFieldAccessorTable() { 93 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloRequest_fieldAccessorTable 94 | .ensureFieldAccessorsInitialized( 95 | com.colobu.rpctest.GreeterOuterClass.HelloRequest.class, com.colobu.rpctest.GreeterOuterClass.HelloRequest.Builder.class); 96 | } 97 | 98 | public static final int NAME_FIELD_NUMBER = 1; 99 | private volatile java.lang.Object name_; 100 | /** 101 | * optional string name = 1; 102 | */ 103 | public java.lang.String getName() { 104 | java.lang.Object ref = name_; 105 | if (ref instanceof java.lang.String) { 106 | return (java.lang.String) ref; 107 | } else { 108 | com.google.protobuf.ByteString bs = 109 | (com.google.protobuf.ByteString) ref; 110 | java.lang.String s = bs.toStringUtf8(); 111 | if (bs.isValidUtf8()) { 112 | name_ = s; 113 | } 114 | return s; 115 | } 116 | } 117 | /** 118 | * optional string name = 1; 119 | */ 120 | public com.google.protobuf.ByteString 121 | getNameBytes() { 122 | java.lang.Object ref = name_; 123 | if (ref instanceof java.lang.String) { 124 | com.google.protobuf.ByteString b = 125 | com.google.protobuf.ByteString.copyFromUtf8( 126 | (java.lang.String) ref); 127 | name_ = b; 128 | return b; 129 | } else { 130 | return (com.google.protobuf.ByteString) ref; 131 | } 132 | } 133 | 134 | private byte memoizedIsInitialized = -1; 135 | public final boolean isInitialized() { 136 | byte isInitialized = memoizedIsInitialized; 137 | if (isInitialized == 1) return true; 138 | if (isInitialized == 0) return false; 139 | 140 | memoizedIsInitialized = 1; 141 | return true; 142 | } 143 | 144 | public void writeTo(com.google.protobuf.CodedOutputStream output) 145 | throws java.io.IOException { 146 | if (!getNameBytes().isEmpty()) { 147 | output.writeBytes(1, getNameBytes()); 148 | } 149 | } 150 | 151 | private int memoizedSerializedSize = -1; 152 | public int getSerializedSize() { 153 | int size = memoizedSerializedSize; 154 | if (size != -1) return size; 155 | 156 | size = 0; 157 | if (!getNameBytes().isEmpty()) { 158 | size += com.google.protobuf.CodedOutputStream 159 | .computeBytesSize(1, getNameBytes()); 160 | } 161 | memoizedSerializedSize = size; 162 | return size; 163 | } 164 | 165 | private static final long serialVersionUID = 0L; 166 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom( 167 | com.google.protobuf.ByteString data) 168 | throws com.google.protobuf.InvalidProtocolBufferException { 169 | return PARSER.parseFrom(data); 170 | } 171 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom( 172 | com.google.protobuf.ByteString data, 173 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 174 | throws com.google.protobuf.InvalidProtocolBufferException { 175 | return PARSER.parseFrom(data, extensionRegistry); 176 | } 177 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom(byte[] data) 178 | throws com.google.protobuf.InvalidProtocolBufferException { 179 | return PARSER.parseFrom(data); 180 | } 181 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom( 182 | byte[] data, 183 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 184 | throws com.google.protobuf.InvalidProtocolBufferException { 185 | return PARSER.parseFrom(data, extensionRegistry); 186 | } 187 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom(java.io.InputStream input) 188 | throws java.io.IOException { 189 | return PARSER.parseFrom(input); 190 | } 191 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom( 192 | java.io.InputStream input, 193 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 194 | throws java.io.IOException { 195 | return PARSER.parseFrom(input, extensionRegistry); 196 | } 197 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseDelimitedFrom(java.io.InputStream input) 198 | throws java.io.IOException { 199 | return PARSER.parseDelimitedFrom(input); 200 | } 201 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseDelimitedFrom( 202 | java.io.InputStream input, 203 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 204 | throws java.io.IOException { 205 | return PARSER.parseDelimitedFrom(input, extensionRegistry); 206 | } 207 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom( 208 | com.google.protobuf.CodedInputStream input) 209 | throws java.io.IOException { 210 | return PARSER.parseFrom(input); 211 | } 212 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest parseFrom( 213 | com.google.protobuf.CodedInputStream input, 214 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 215 | throws java.io.IOException { 216 | return PARSER.parseFrom(input, extensionRegistry); 217 | } 218 | 219 | public Builder newBuilderForType() { return newBuilder(); } 220 | public static Builder newBuilder() { 221 | return DEFAULT_INSTANCE.toBuilder(); 222 | } 223 | public static Builder newBuilder(com.colobu.rpctest.GreeterOuterClass.HelloRequest prototype) { 224 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 225 | } 226 | public Builder toBuilder() { 227 | return this == DEFAULT_INSTANCE 228 | ? new Builder() : new Builder().mergeFrom(this); 229 | } 230 | 231 | @java.lang.Override 232 | protected Builder newBuilderForType( 233 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 234 | Builder builder = new Builder(parent); 235 | return builder; 236 | } 237 | /** 238 | * Protobuf type {@code greeter.HelloRequest} 239 | * 240 | *
241 |      * The request message containing the user's name.
242 |      * 
243 | */ 244 | public static final class Builder extends 245 | com.google.protobuf.GeneratedMessage.Builder implements 246 | // @@protoc_insertion_point(builder_implements:greeter.HelloRequest) 247 | com.colobu.rpctest.GreeterOuterClass.HelloRequestOrBuilder { 248 | public static final com.google.protobuf.Descriptors.Descriptor 249 | getDescriptor() { 250 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloRequest_descriptor; 251 | } 252 | 253 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 254 | internalGetFieldAccessorTable() { 255 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloRequest_fieldAccessorTable 256 | .ensureFieldAccessorsInitialized( 257 | com.colobu.rpctest.GreeterOuterClass.HelloRequest.class, com.colobu.rpctest.GreeterOuterClass.HelloRequest.Builder.class); 258 | } 259 | 260 | // Construct using com.colobu.rpctest.GreeterOuterClass.HelloRequest.newBuilder() 261 | private Builder() { 262 | maybeForceBuilderInitialization(); 263 | } 264 | 265 | private Builder( 266 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 267 | super(parent); 268 | maybeForceBuilderInitialization(); 269 | } 270 | private void maybeForceBuilderInitialization() { 271 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 272 | } 273 | } 274 | public Builder clear() { 275 | super.clear(); 276 | name_ = ""; 277 | 278 | return this; 279 | } 280 | 281 | public com.google.protobuf.Descriptors.Descriptor 282 | getDescriptorForType() { 283 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloRequest_descriptor; 284 | } 285 | 286 | public com.colobu.rpctest.GreeterOuterClass.HelloRequest getDefaultInstanceForType() { 287 | return com.colobu.rpctest.GreeterOuterClass.HelloRequest.getDefaultInstance(); 288 | } 289 | 290 | public com.colobu.rpctest.GreeterOuterClass.HelloRequest build() { 291 | com.colobu.rpctest.GreeterOuterClass.HelloRequest result = buildPartial(); 292 | if (!result.isInitialized()) { 293 | throw newUninitializedMessageException(result); 294 | } 295 | return result; 296 | } 297 | 298 | public com.colobu.rpctest.GreeterOuterClass.HelloRequest buildPartial() { 299 | com.colobu.rpctest.GreeterOuterClass.HelloRequest result = new com.colobu.rpctest.GreeterOuterClass.HelloRequest(this); 300 | result.name_ = name_; 301 | onBuilt(); 302 | return result; 303 | } 304 | 305 | public Builder mergeFrom(com.google.protobuf.Message other) { 306 | if (other instanceof com.colobu.rpctest.GreeterOuterClass.HelloRequest) { 307 | return mergeFrom((com.colobu.rpctest.GreeterOuterClass.HelloRequest)other); 308 | } else { 309 | super.mergeFrom(other); 310 | return this; 311 | } 312 | } 313 | 314 | public Builder mergeFrom(com.colobu.rpctest.GreeterOuterClass.HelloRequest other) { 315 | if (other == com.colobu.rpctest.GreeterOuterClass.HelloRequest.getDefaultInstance()) return this; 316 | if (!other.getName().isEmpty()) { 317 | name_ = other.name_; 318 | onChanged(); 319 | } 320 | onChanged(); 321 | return this; 322 | } 323 | 324 | public final boolean isInitialized() { 325 | return true; 326 | } 327 | 328 | public Builder mergeFrom( 329 | com.google.protobuf.CodedInputStream input, 330 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 331 | throws java.io.IOException { 332 | com.colobu.rpctest.GreeterOuterClass.HelloRequest parsedMessage = null; 333 | try { 334 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 335 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 336 | parsedMessage = (com.colobu.rpctest.GreeterOuterClass.HelloRequest) e.getUnfinishedMessage(); 337 | throw e; 338 | } finally { 339 | if (parsedMessage != null) { 340 | mergeFrom(parsedMessage); 341 | } 342 | } 343 | return this; 344 | } 345 | 346 | private java.lang.Object name_ = ""; 347 | /** 348 | * optional string name = 1; 349 | */ 350 | public java.lang.String getName() { 351 | java.lang.Object ref = name_; 352 | if (!(ref instanceof java.lang.String)) { 353 | com.google.protobuf.ByteString bs = 354 | (com.google.protobuf.ByteString) ref; 355 | java.lang.String s = bs.toStringUtf8(); 356 | if (bs.isValidUtf8()) { 357 | name_ = s; 358 | } 359 | return s; 360 | } else { 361 | return (java.lang.String) ref; 362 | } 363 | } 364 | /** 365 | * optional string name = 1; 366 | */ 367 | public com.google.protobuf.ByteString 368 | getNameBytes() { 369 | java.lang.Object ref = name_; 370 | if (ref instanceof String) { 371 | com.google.protobuf.ByteString b = 372 | com.google.protobuf.ByteString.copyFromUtf8( 373 | (java.lang.String) ref); 374 | name_ = b; 375 | return b; 376 | } else { 377 | return (com.google.protobuf.ByteString) ref; 378 | } 379 | } 380 | /** 381 | * optional string name = 1; 382 | */ 383 | public Builder setName( 384 | java.lang.String value) { 385 | if (value == null) { 386 | throw new NullPointerException(); 387 | } 388 | 389 | name_ = value; 390 | onChanged(); 391 | return this; 392 | } 393 | /** 394 | * optional string name = 1; 395 | */ 396 | public Builder clearName() { 397 | 398 | name_ = getDefaultInstance().getName(); 399 | onChanged(); 400 | return this; 401 | } 402 | /** 403 | * optional string name = 1; 404 | */ 405 | public Builder setNameBytes( 406 | com.google.protobuf.ByteString value) { 407 | if (value == null) { 408 | throw new NullPointerException(); 409 | } 410 | 411 | name_ = value; 412 | onChanged(); 413 | return this; 414 | } 415 | public final Builder setUnknownFields( 416 | final com.google.protobuf.UnknownFieldSet unknownFields) { 417 | return this; 418 | } 419 | 420 | public final Builder mergeUnknownFields( 421 | final com.google.protobuf.UnknownFieldSet unknownFields) { 422 | return this; 423 | } 424 | 425 | 426 | // @@protoc_insertion_point(builder_scope:greeter.HelloRequest) 427 | } 428 | 429 | // @@protoc_insertion_point(class_scope:greeter.HelloRequest) 430 | private static final com.colobu.rpctest.GreeterOuterClass.HelloRequest DEFAULT_INSTANCE; 431 | static { 432 | DEFAULT_INSTANCE = new com.colobu.rpctest.GreeterOuterClass.HelloRequest(); 433 | } 434 | 435 | public static com.colobu.rpctest.GreeterOuterClass.HelloRequest getDefaultInstance() { 436 | return DEFAULT_INSTANCE; 437 | } 438 | 439 | public static final com.google.protobuf.Parser PARSER = 440 | new com.google.protobuf.AbstractParser() { 441 | public HelloRequest parsePartialFrom( 442 | com.google.protobuf.CodedInputStream input, 443 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 444 | throws com.google.protobuf.InvalidProtocolBufferException { 445 | try { 446 | return new HelloRequest(input, extensionRegistry); 447 | } catch (RuntimeException e) { 448 | if (e.getCause() instanceof 449 | com.google.protobuf.InvalidProtocolBufferException) { 450 | throw (com.google.protobuf.InvalidProtocolBufferException) 451 | e.getCause(); 452 | } 453 | throw e; 454 | } 455 | } 456 | }; 457 | 458 | public static com.google.protobuf.Parser parser() { 459 | return PARSER; 460 | } 461 | 462 | @java.lang.Override 463 | public com.google.protobuf.Parser getParserForType() { 464 | return PARSER; 465 | } 466 | 467 | public com.colobu.rpctest.GreeterOuterClass.HelloRequest getDefaultInstanceForType() { 468 | return DEFAULT_INSTANCE; 469 | } 470 | 471 | } 472 | 473 | public interface HelloReplyOrBuilder extends 474 | // @@protoc_insertion_point(interface_extends:greeter.HelloReply) 475 | com.google.protobuf.MessageOrBuilder { 476 | 477 | /** 478 | * optional string message = 1; 479 | */ 480 | java.lang.String getMessage(); 481 | /** 482 | * optional string message = 1; 483 | */ 484 | com.google.protobuf.ByteString 485 | getMessageBytes(); 486 | } 487 | /** 488 | * Protobuf type {@code greeter.HelloReply} 489 | * 490 | *
491 |    * The response message containing the greetings
492 |    * 
493 | */ 494 | public static final class HelloReply extends 495 | com.google.protobuf.GeneratedMessage implements 496 | // @@protoc_insertion_point(message_implements:greeter.HelloReply) 497 | HelloReplyOrBuilder { 498 | // Use HelloReply.newBuilder() to construct. 499 | private HelloReply(com.google.protobuf.GeneratedMessage.Builder builder) { 500 | super(builder); 501 | } 502 | private HelloReply() { 503 | message_ = ""; 504 | } 505 | 506 | @java.lang.Override 507 | public final com.google.protobuf.UnknownFieldSet 508 | getUnknownFields() { 509 | return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); 510 | } 511 | private HelloReply( 512 | com.google.protobuf.CodedInputStream input, 513 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) { 514 | this(); 515 | int mutable_bitField0_ = 0; 516 | try { 517 | boolean done = false; 518 | while (!done) { 519 | int tag = input.readTag(); 520 | switch (tag) { 521 | case 0: 522 | done = true; 523 | break; 524 | default: { 525 | if (!input.skipField(tag)) { 526 | done = true; 527 | } 528 | break; 529 | } 530 | case 10: { 531 | com.google.protobuf.ByteString bs = input.readBytes(); 532 | 533 | message_ = bs; 534 | break; 535 | } 536 | } 537 | } 538 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 539 | throw new RuntimeException(e.setUnfinishedMessage(this)); 540 | } catch (java.io.IOException e) { 541 | throw new RuntimeException( 542 | new com.google.protobuf.InvalidProtocolBufferException( 543 | e.getMessage()).setUnfinishedMessage(this)); 544 | } finally { 545 | makeExtensionsImmutable(); 546 | } 547 | } 548 | public static final com.google.protobuf.Descriptors.Descriptor 549 | getDescriptor() { 550 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloReply_descriptor; 551 | } 552 | 553 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 554 | internalGetFieldAccessorTable() { 555 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloReply_fieldAccessorTable 556 | .ensureFieldAccessorsInitialized( 557 | com.colobu.rpctest.GreeterOuterClass.HelloReply.class, com.colobu.rpctest.GreeterOuterClass.HelloReply.Builder.class); 558 | } 559 | 560 | public static final int MESSAGE_FIELD_NUMBER = 1; 561 | private volatile java.lang.Object message_; 562 | /** 563 | * optional string message = 1; 564 | */ 565 | public java.lang.String getMessage() { 566 | java.lang.Object ref = message_; 567 | if (ref instanceof java.lang.String) { 568 | return (java.lang.String) ref; 569 | } else { 570 | com.google.protobuf.ByteString bs = 571 | (com.google.protobuf.ByteString) ref; 572 | java.lang.String s = bs.toStringUtf8(); 573 | if (bs.isValidUtf8()) { 574 | message_ = s; 575 | } 576 | return s; 577 | } 578 | } 579 | /** 580 | * optional string message = 1; 581 | */ 582 | public com.google.protobuf.ByteString 583 | getMessageBytes() { 584 | java.lang.Object ref = message_; 585 | if (ref instanceof java.lang.String) { 586 | com.google.protobuf.ByteString b = 587 | com.google.protobuf.ByteString.copyFromUtf8( 588 | (java.lang.String) ref); 589 | message_ = b; 590 | return b; 591 | } else { 592 | return (com.google.protobuf.ByteString) ref; 593 | } 594 | } 595 | 596 | private byte memoizedIsInitialized = -1; 597 | public final boolean isInitialized() { 598 | byte isInitialized = memoizedIsInitialized; 599 | if (isInitialized == 1) return true; 600 | if (isInitialized == 0) return false; 601 | 602 | memoizedIsInitialized = 1; 603 | return true; 604 | } 605 | 606 | public void writeTo(com.google.protobuf.CodedOutputStream output) 607 | throws java.io.IOException { 608 | if (!getMessageBytes().isEmpty()) { 609 | output.writeBytes(1, getMessageBytes()); 610 | } 611 | } 612 | 613 | private int memoizedSerializedSize = -1; 614 | public int getSerializedSize() { 615 | int size = memoizedSerializedSize; 616 | if (size != -1) return size; 617 | 618 | size = 0; 619 | if (!getMessageBytes().isEmpty()) { 620 | size += com.google.protobuf.CodedOutputStream 621 | .computeBytesSize(1, getMessageBytes()); 622 | } 623 | memoizedSerializedSize = size; 624 | return size; 625 | } 626 | 627 | private static final long serialVersionUID = 0L; 628 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom( 629 | com.google.protobuf.ByteString data) 630 | throws com.google.protobuf.InvalidProtocolBufferException { 631 | return PARSER.parseFrom(data); 632 | } 633 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom( 634 | com.google.protobuf.ByteString data, 635 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 636 | throws com.google.protobuf.InvalidProtocolBufferException { 637 | return PARSER.parseFrom(data, extensionRegistry); 638 | } 639 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom(byte[] data) 640 | throws com.google.protobuf.InvalidProtocolBufferException { 641 | return PARSER.parseFrom(data); 642 | } 643 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom( 644 | byte[] data, 645 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 646 | throws com.google.protobuf.InvalidProtocolBufferException { 647 | return PARSER.parseFrom(data, extensionRegistry); 648 | } 649 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom(java.io.InputStream input) 650 | throws java.io.IOException { 651 | return PARSER.parseFrom(input); 652 | } 653 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom( 654 | java.io.InputStream input, 655 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 656 | throws java.io.IOException { 657 | return PARSER.parseFrom(input, extensionRegistry); 658 | } 659 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseDelimitedFrom(java.io.InputStream input) 660 | throws java.io.IOException { 661 | return PARSER.parseDelimitedFrom(input); 662 | } 663 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseDelimitedFrom( 664 | java.io.InputStream input, 665 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 666 | throws java.io.IOException { 667 | return PARSER.parseDelimitedFrom(input, extensionRegistry); 668 | } 669 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom( 670 | com.google.protobuf.CodedInputStream input) 671 | throws java.io.IOException { 672 | return PARSER.parseFrom(input); 673 | } 674 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply parseFrom( 675 | com.google.protobuf.CodedInputStream input, 676 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 677 | throws java.io.IOException { 678 | return PARSER.parseFrom(input, extensionRegistry); 679 | } 680 | 681 | public Builder newBuilderForType() { return newBuilder(); } 682 | public static Builder newBuilder() { 683 | return DEFAULT_INSTANCE.toBuilder(); 684 | } 685 | public static Builder newBuilder(com.colobu.rpctest.GreeterOuterClass.HelloReply prototype) { 686 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 687 | } 688 | public Builder toBuilder() { 689 | return this == DEFAULT_INSTANCE 690 | ? new Builder() : new Builder().mergeFrom(this); 691 | } 692 | 693 | @java.lang.Override 694 | protected Builder newBuilderForType( 695 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 696 | Builder builder = new Builder(parent); 697 | return builder; 698 | } 699 | /** 700 | * Protobuf type {@code greeter.HelloReply} 701 | * 702 | *
703 |      * The response message containing the greetings
704 |      * 
705 | */ 706 | public static final class Builder extends 707 | com.google.protobuf.GeneratedMessage.Builder implements 708 | // @@protoc_insertion_point(builder_implements:greeter.HelloReply) 709 | com.colobu.rpctest.GreeterOuterClass.HelloReplyOrBuilder { 710 | public static final com.google.protobuf.Descriptors.Descriptor 711 | getDescriptor() { 712 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloReply_descriptor; 713 | } 714 | 715 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 716 | internalGetFieldAccessorTable() { 717 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloReply_fieldAccessorTable 718 | .ensureFieldAccessorsInitialized( 719 | com.colobu.rpctest.GreeterOuterClass.HelloReply.class, com.colobu.rpctest.GreeterOuterClass.HelloReply.Builder.class); 720 | } 721 | 722 | // Construct using com.colobu.rpctest.GreeterOuterClass.HelloReply.newBuilder() 723 | private Builder() { 724 | maybeForceBuilderInitialization(); 725 | } 726 | 727 | private Builder( 728 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 729 | super(parent); 730 | maybeForceBuilderInitialization(); 731 | } 732 | private void maybeForceBuilderInitialization() { 733 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 734 | } 735 | } 736 | public Builder clear() { 737 | super.clear(); 738 | message_ = ""; 739 | 740 | return this; 741 | } 742 | 743 | public com.google.protobuf.Descriptors.Descriptor 744 | getDescriptorForType() { 745 | return com.colobu.rpctest.GreeterOuterClass.internal_static_greeter_HelloReply_descriptor; 746 | } 747 | 748 | public com.colobu.rpctest.GreeterOuterClass.HelloReply getDefaultInstanceForType() { 749 | return com.colobu.rpctest.GreeterOuterClass.HelloReply.getDefaultInstance(); 750 | } 751 | 752 | public com.colobu.rpctest.GreeterOuterClass.HelloReply build() { 753 | com.colobu.rpctest.GreeterOuterClass.HelloReply result = buildPartial(); 754 | if (!result.isInitialized()) { 755 | throw newUninitializedMessageException(result); 756 | } 757 | return result; 758 | } 759 | 760 | public com.colobu.rpctest.GreeterOuterClass.HelloReply buildPartial() { 761 | com.colobu.rpctest.GreeterOuterClass.HelloReply result = new com.colobu.rpctest.GreeterOuterClass.HelloReply(this); 762 | result.message_ = message_; 763 | onBuilt(); 764 | return result; 765 | } 766 | 767 | public Builder mergeFrom(com.google.protobuf.Message other) { 768 | if (other instanceof com.colobu.rpctest.GreeterOuterClass.HelloReply) { 769 | return mergeFrom((com.colobu.rpctest.GreeterOuterClass.HelloReply)other); 770 | } else { 771 | super.mergeFrom(other); 772 | return this; 773 | } 774 | } 775 | 776 | public Builder mergeFrom(com.colobu.rpctest.GreeterOuterClass.HelloReply other) { 777 | if (other == com.colobu.rpctest.GreeterOuterClass.HelloReply.getDefaultInstance()) return this; 778 | if (!other.getMessage().isEmpty()) { 779 | message_ = other.message_; 780 | onChanged(); 781 | } 782 | onChanged(); 783 | return this; 784 | } 785 | 786 | public final boolean isInitialized() { 787 | return true; 788 | } 789 | 790 | public Builder mergeFrom( 791 | com.google.protobuf.CodedInputStream input, 792 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 793 | throws java.io.IOException { 794 | com.colobu.rpctest.GreeterOuterClass.HelloReply parsedMessage = null; 795 | try { 796 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 797 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 798 | parsedMessage = (com.colobu.rpctest.GreeterOuterClass.HelloReply) e.getUnfinishedMessage(); 799 | throw e; 800 | } finally { 801 | if (parsedMessage != null) { 802 | mergeFrom(parsedMessage); 803 | } 804 | } 805 | return this; 806 | } 807 | 808 | private java.lang.Object message_ = ""; 809 | /** 810 | * optional string message = 1; 811 | */ 812 | public java.lang.String getMessage() { 813 | java.lang.Object ref = message_; 814 | if (!(ref instanceof java.lang.String)) { 815 | com.google.protobuf.ByteString bs = 816 | (com.google.protobuf.ByteString) ref; 817 | java.lang.String s = bs.toStringUtf8(); 818 | if (bs.isValidUtf8()) { 819 | message_ = s; 820 | } 821 | return s; 822 | } else { 823 | return (java.lang.String) ref; 824 | } 825 | } 826 | /** 827 | * optional string message = 1; 828 | */ 829 | public com.google.protobuf.ByteString 830 | getMessageBytes() { 831 | java.lang.Object ref = message_; 832 | if (ref instanceof String) { 833 | com.google.protobuf.ByteString b = 834 | com.google.protobuf.ByteString.copyFromUtf8( 835 | (java.lang.String) ref); 836 | message_ = b; 837 | return b; 838 | } else { 839 | return (com.google.protobuf.ByteString) ref; 840 | } 841 | } 842 | /** 843 | * optional string message = 1; 844 | */ 845 | public Builder setMessage( 846 | java.lang.String value) { 847 | if (value == null) { 848 | throw new NullPointerException(); 849 | } 850 | 851 | message_ = value; 852 | onChanged(); 853 | return this; 854 | } 855 | /** 856 | * optional string message = 1; 857 | */ 858 | public Builder clearMessage() { 859 | 860 | message_ = getDefaultInstance().getMessage(); 861 | onChanged(); 862 | return this; 863 | } 864 | /** 865 | * optional string message = 1; 866 | */ 867 | public Builder setMessageBytes( 868 | com.google.protobuf.ByteString value) { 869 | if (value == null) { 870 | throw new NullPointerException(); 871 | } 872 | 873 | message_ = value; 874 | onChanged(); 875 | return this; 876 | } 877 | public final Builder setUnknownFields( 878 | final com.google.protobuf.UnknownFieldSet unknownFields) { 879 | return this; 880 | } 881 | 882 | public final Builder mergeUnknownFields( 883 | final com.google.protobuf.UnknownFieldSet unknownFields) { 884 | return this; 885 | } 886 | 887 | 888 | // @@protoc_insertion_point(builder_scope:greeter.HelloReply) 889 | } 890 | 891 | // @@protoc_insertion_point(class_scope:greeter.HelloReply) 892 | private static final com.colobu.rpctest.GreeterOuterClass.HelloReply DEFAULT_INSTANCE; 893 | static { 894 | DEFAULT_INSTANCE = new com.colobu.rpctest.GreeterOuterClass.HelloReply(); 895 | } 896 | 897 | public static com.colobu.rpctest.GreeterOuterClass.HelloReply getDefaultInstance() { 898 | return DEFAULT_INSTANCE; 899 | } 900 | 901 | public static final com.google.protobuf.Parser PARSER = 902 | new com.google.protobuf.AbstractParser() { 903 | public HelloReply parsePartialFrom( 904 | com.google.protobuf.CodedInputStream input, 905 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 906 | throws com.google.protobuf.InvalidProtocolBufferException { 907 | try { 908 | return new HelloReply(input, extensionRegistry); 909 | } catch (RuntimeException e) { 910 | if (e.getCause() instanceof 911 | com.google.protobuf.InvalidProtocolBufferException) { 912 | throw (com.google.protobuf.InvalidProtocolBufferException) 913 | e.getCause(); 914 | } 915 | throw e; 916 | } 917 | } 918 | }; 919 | 920 | public static com.google.protobuf.Parser parser() { 921 | return PARSER; 922 | } 923 | 924 | @java.lang.Override 925 | public com.google.protobuf.Parser getParserForType() { 926 | return PARSER; 927 | } 928 | 929 | public com.colobu.rpctest.GreeterOuterClass.HelloReply getDefaultInstanceForType() { 930 | return DEFAULT_INSTANCE; 931 | } 932 | 933 | } 934 | 935 | private static com.google.protobuf.Descriptors.Descriptor 936 | internal_static_greeter_HelloRequest_descriptor; 937 | private static 938 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 939 | internal_static_greeter_HelloRequest_fieldAccessorTable; 940 | private static com.google.protobuf.Descriptors.Descriptor 941 | internal_static_greeter_HelloReply_descriptor; 942 | private static 943 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 944 | internal_static_greeter_HelloReply_fieldAccessorTable; 945 | 946 | public static com.google.protobuf.Descriptors.FileDescriptor 947 | getDescriptor() { 948 | return descriptor; 949 | } 950 | private static com.google.protobuf.Descriptors.FileDescriptor 951 | descriptor; 952 | static { 953 | java.lang.String[] descriptorData = { 954 | "\n\rgreeter.proto\022\007greeter\"\034\n\014HelloRequest" + 955 | "\022\014\n\004name\030\001 \001(\t\"\035\n\nHelloReply\022\017\n\007message\030" + 956 | "\001 \001(\t2C\n\007Greeter\0228\n\010SayHello\022\025.greeter.H" + 957 | "elloRequest\032\023.greeter.HelloReply\"\000B\024\n\022co" + 958 | "m.colobu.rpctestb\006proto3" 959 | }; 960 | com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 961 | new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { 962 | public com.google.protobuf.ExtensionRegistry assignDescriptors( 963 | com.google.protobuf.Descriptors.FileDescriptor root) { 964 | descriptor = root; 965 | return null; 966 | } 967 | }; 968 | com.google.protobuf.Descriptors.FileDescriptor 969 | .internalBuildGeneratedFileFrom(descriptorData, 970 | new com.google.protobuf.Descriptors.FileDescriptor[] { 971 | }, assigner); 972 | internal_static_greeter_HelloRequest_descriptor = 973 | getDescriptor().getMessageTypes().get(0); 974 | internal_static_greeter_HelloRequest_fieldAccessorTable = new 975 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 976 | internal_static_greeter_HelloRequest_descriptor, 977 | new java.lang.String[] { "Name", }); 978 | internal_static_greeter_HelloReply_descriptor = 979 | getDescriptor().getMessageTypes().get(1); 980 | internal_static_greeter_HelloReply_fieldAccessorTable = new 981 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 982 | internal_static_greeter_HelloReply_descriptor, 983 | new java.lang.String[] { "Message", }); 984 | } 985 | 986 | // @@protoc_insertion_point(outer_class_scope) 987 | } 988 | -------------------------------------------------------------------------------- /gRPC/scala/src/templates/bash-template: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ### ------------------------------- ### 4 | ### Helper methods for BASH scripts ### 5 | ### ------------------------------- ### 6 | 7 | die() { 8 | echo "$@" 1>&2 9 | exit 1 10 | } 11 | 12 | realpath () { 13 | ( 14 | TARGET_FILE="$1" 15 | CHECK_CYGWIN="$2" 16 | 17 | cd "$(dirname "$TARGET_FILE")" 18 | TARGET_FILE=$(basename "$TARGET_FILE") 19 | 20 | COUNT=0 21 | while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ] 22 | do 23 | TARGET_FILE=$(readlink "$TARGET_FILE") 24 | cd "$(dirname "$TARGET_FILE")" 25 | TARGET_FILE=$(basename "$TARGET_FILE") 26 | COUNT=$(($COUNT + 1)) 27 | done 28 | 29 | if [ "$TARGET_FILE" == "." -o "$TARGET_FILE" == ".." ]; then 30 | cd "$TARGET_FILE" 31 | TARGET_FILEPATH= 32 | else 33 | TARGET_FILEPATH=/$TARGET_FILE 34 | fi 35 | 36 | # make sure we grab the actual windows path, instead of cygwin's path. 37 | if [[ "x$CHECK_CYGWIN" == "x" ]]; then 38 | echo "$(pwd -P)/$TARGET_FILE" 39 | else 40 | echo $(cygwinpath "$(pwd -P)/$TARGET_FILE") 41 | fi 42 | ) 43 | } 44 | 45 | # TODO - Do we need to detect msys? 46 | 47 | # Uses uname to detect if we're in the odd cygwin environment. 48 | is_cygwin() { 49 | local os=$(uname -s) 50 | case "$os" in 51 | CYGWIN*) return 0 ;; 52 | *) return 1 ;; 53 | esac 54 | } 55 | 56 | # This can fix cygwin style /cygdrive paths so we get the 57 | # windows style paths. 58 | cygwinpath() { 59 | local file="$1" 60 | if is_cygwin; then 61 | echo $(cygpath -w $file) 62 | else 63 | echo $file 64 | fi 65 | } 66 | 67 | # Make something URI friendly 68 | make_url() { 69 | url="$1" 70 | local nospaces=${url// /%20} 71 | if is_cygwin; then 72 | echo "/${nospaces//\\//}" 73 | else 74 | echo "$nospaces" 75 | fi 76 | } 77 | 78 | # This crazy function reads in a vanilla "linux" classpath string (only : are separators, and all /), 79 | # and returns a classpath with windows style paths, and ; separators. 80 | fixCygwinClasspath() { 81 | OLDIFS=$IFS 82 | IFS=":" 83 | read -a classpath_members <<< "$1" 84 | declare -a fixed_members 85 | IFS=$OLDIFS 86 | for i in "${!classpath_members[@]}" 87 | do 88 | fixed_members[i]=$(realpath "${classpath_members[i]}" "fix") 89 | done 90 | IFS=";" 91 | echo "${fixed_members[*]}" 92 | IFS=$OLDIFS 93 | } 94 | 95 | # Fix the classpath we use for cygwin. 96 | fix_classpath() { 97 | cp="$1" 98 | if is_cygwin; then 99 | echo "$(fixCygwinClasspath "$cp;$app_conf")" 100 | else 101 | echo "$cp:$app_conf" 102 | fi 103 | } 104 | # Detect if we should use JAVA_HOME or just try PATH. 105 | get_java_cmd() { 106 | if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then 107 | echo "$JAVA_HOME/bin/java" 108 | else 109 | echo "java" 110 | fi 111 | } 112 | 113 | echoerr () { 114 | echo 1>&2 "$@" 115 | } 116 | vlog () { 117 | [[ $verbose || $debug ]] && echoerr "$@" 118 | } 119 | dlog () { 120 | [[ $debug ]] && echoerr "$@" 121 | } 122 | execRunner () { 123 | # print the arguments one to a line, quoting any containing spaces 124 | [[ $verbose || $debug ]] && echo "# Executing command line:" && { 125 | for arg; do 126 | if printf "%s\n" "$arg" | grep -q ' '; then 127 | printf "\"%s\"\n" "$arg" 128 | else 129 | printf "%s\n" "$arg" 130 | fi 131 | done 132 | echo "" 133 | } 134 | 135 | # we use "exec" here for our pids to be accurate. 136 | exec "$@" 137 | } 138 | addJava () { 139 | dlog "[addJava] arg = '$1'" 140 | java_args+=( "$1" ) 141 | } 142 | addApp () { 143 | dlog "[addApp] arg = '$1'" 144 | app_commands+=( "$1" ) 145 | } 146 | addResidual () { 147 | dlog "[residual] arg = '$1'" 148 | residual_args+=( "$1" ) 149 | } 150 | addDebugger () { 151 | addJava "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$1" 152 | } 153 | 154 | require_arg () { 155 | local type="$1" 156 | local opt="$2" 157 | local arg="$3" 158 | if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then 159 | die "$opt requires <$type> argument" 160 | fi 161 | } 162 | is_function_defined() { 163 | declare -f "$1" > /dev/null 164 | } 165 | 166 | # Attempt to detect if the script is running via a GUI or not 167 | # TODO - Determine where/how we use this generically 168 | detect_terminal_for_ui() { 169 | [[ ! -t 0 ]] && [[ "${#residual_args}" == "0" ]] && { 170 | echo "true" 171 | } 172 | # SPECIAL TEST FOR MAC 173 | [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]] && [[ "${#residual_args}" == "0" ]] && { 174 | echo "true" 175 | } 176 | } 177 | 178 | # Processes incoming arguments and places them in appropriate global variables. called by the run method. 179 | process_args () { 180 | local no_more_snp_opts=0 181 | while [[ $# -gt 0 ]]; do 182 | case "$1" in 183 | --) shift && no_more_snp_opts=1 && break ;; 184 | -h|-help) usage; exit 1 ;; 185 | -v|-verbose) verbose=1 && shift ;; 186 | -d|-debug) debug=1 && shift ;; 187 | 188 | -no-version-check) no_version_check=1 && shift ;; 189 | 190 | -mem) echo "!! WARNING !! -mem option is ignored. Please use -J-Xmx and -J-Xms" && shift 2 ;; 191 | -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; 192 | 193 | -main) custom_mainclass="$2" && shift 2 ;; 194 | 195 | -java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;; 196 | 197 | -D*|-agentlib*) addJava "$1" && shift ;; 198 | -J*) addJava "${1:2}" && shift ;; 199 | *) addResidual "$1" && shift ;; 200 | esac 201 | done 202 | 203 | if [[ no_more_snp_opts ]]; then 204 | while [[ $# -gt 0 ]]; do 205 | addResidual "$1" && shift 206 | done 207 | fi 208 | 209 | is_function_defined process_my_args && { 210 | myargs=("${residual_args[@]}") 211 | residual_args=() 212 | process_my_args "${myargs[@]}" 213 | } 214 | } 215 | 216 | # Actually runs the script. 217 | run() { 218 | # TODO - check for sane environment 219 | 220 | # process the combined args, then reset "$@" to the residuals 221 | process_args "$@" 222 | set -- "${residual_args[@]}" 223 | argumentCount=$# 224 | 225 | #check for jline terminal fixes on cygwin 226 | if is_cygwin; then 227 | stty -icanon min 1 -echo > /dev/null 2>&1 228 | addJava "-Djline.terminal=jline.UnixTerminal" 229 | addJava "-Dsbt.cygwin=true" 230 | fi 231 | 232 | # check java version 233 | if [[ ! $no_version_check ]]; then 234 | java_version_check 235 | fi 236 | 237 | if [ -n "$custom_mainclass" ]; then 238 | mainclass="$custom_mainclass" 239 | else 240 | mainclass="$app_mainclass" 241 | fi 242 | 243 | # Now we check to see if there are any java opts on the environment. These get listed first, with the script able to override them. 244 | if [[ "$JAVA_OPTS" != "" ]]; then 245 | java_opts="${JAVA_OPTS}" 246 | fi 247 | 248 | # run sbt 249 | execRunner "$java_cmd" \ 250 | ${java_opts[@]} \ 251 | "${java_args[@]}" \ 252 | -cp "$(fix_classpath "$app_classpath")" \ 253 | $mainclass \ 254 | "${app_commands[@]}" \ 255 | "${residual_args[@]}" 256 | 257 | local exit_code=$? 258 | if is_cygwin; then 259 | stty icanon echo > /dev/null 2>&1 260 | fi 261 | exit $exit_code 262 | } 263 | 264 | # Loads a configuration file full of default command line options for this script. 265 | loadConfigFile() { 266 | cat "$1" | sed '/^\#/d' 267 | } 268 | 269 | # Now check to see if it's a good enough version 270 | # TODO - Check to see if we have a configured default java version, otherwise use 1.6 271 | java_version_check() { 272 | readonly java_version=$("$java_cmd" -version 2>&1 | awk -F '"' '/version/ {print $2}') 273 | if [[ "$java_version" == "" ]]; then 274 | echo 275 | echo No java installations was detected. 276 | echo Please go to http://www.java.com/getjava/ and download 277 | echo 278 | exit 1 279 | elif [[ ! "$java_version" > "1.6" ]]; then 280 | echo 281 | echo The java installation you have is not up to date 282 | echo $app_name requires at least version 1.6+, you have 283 | echo version $java_version 284 | echo 285 | echo Please go to http://www.java.com/getjava/ and download 286 | echo a valid Java Runtime and install before running $app_name. 287 | echo 288 | exit 1 289 | fi 290 | } 291 | 292 | ### ------------------------------- ### 293 | ### Start of customized settings ### 294 | ### ------------------------------- ### 295 | usage() { 296 | cat < Define a custom main class 304 | -jvm-debug Turn on JVM debugging, open at the given port. 305 | 306 | # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) 307 | -java-home alternate JAVA_HOME 308 | 309 | # jvm options and output control 310 | JAVA_OPTS environment variable, if unset uses "$java_opts" 311 | -Dkey=val pass -Dkey=val directly to the java runtime 312 | -J-X pass option -X directly to the java runtime 313 | (-J is stripped) 314 | 315 | # special option 316 | -- To stop parsing built-in commands from the rest of the command-line. 317 | e.g.) enabling debug and sending -d as app argument 318 | \$ ./start-script -d -- -d 319 | 320 | In the case of duplicated or conflicting options, basically the order above 321 | shows precedence: JAVA_OPTS lowest, command line options highest except "--". 322 | EOM 323 | } 324 | 325 | ### ------------------------------- ### 326 | ### Main script ### 327 | ### ------------------------------- ### 328 | 329 | declare -a residual_args 330 | declare -a java_args 331 | declare -a app_commands 332 | declare -r real_script_path="$(realpath "$0")" 333 | declare -r app_home="$(realpath "$(dirname "$real_script_path")")" 334 | declare -r app_conf="$(realpath "${app_home}/../conf")" 335 | # TODO - Check whether this is ok in cygwin... 336 | declare -r lib_dir="$(realpath "${app_home}/../lib")" 337 | ${{template_declares}} 338 | # java_cmd is overrode in process_args when -java-home is used 339 | declare java_cmd=$(get_java_cmd) 340 | 341 | [ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xms12G -Xmx12G -Xss1M -XX:+UseParallelGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps " 342 | 343 | if [ -n "$APP_CONFIG" ]; then 344 | JAVA_OPTS="$JAVA_OPTS -Dconfig.file=$APP_CONFIG" 345 | fi 346 | if [ -n "$LOGBACK_CONFIG" ]; then 347 | JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=$LOGBACK_CONFIG" 348 | fi 349 | 350 | # if configuration files exist, prepend their contents to $@ so it can be processed by this runner 351 | [[ -f "$script_conf_file" ]] && set -- $(loadConfigFile "$script_conf_file") "$@" 352 | 353 | run "$@" 354 | -------------------------------------------------------------------------------- /gRPC/scala/src/universal/conf/application.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallnest/RPC-TEST/eace9e69b2d12d1c244402ad0740611feebd11ff/gRPC/scala/src/universal/conf/application.conf -------------------------------------------------------------------------------- /thrift/golang/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | pkg/ 3 | -------------------------------------------------------------------------------- /thrift/golang/gen.sh: -------------------------------------------------------------------------------- 1 | #go get github.com/golang/protobuf/protoc-gen-go 2 | #go get github.com/golang/protobuf/proto 3 | #go get golang.org/x/net/context 4 | #go get google.golang.org/grpc 5 | 6 | thrift-0.9.2.exe -r --gen go -out src thrift/helloworld.thrift -------------------------------------------------------------------------------- /thrift/golang/src/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "fmt" 6 | "time" 7 | "strconv" 8 | "sync" 9 | 10 | "greeter" 11 | 12 | "git.apache.org/thrift.git/lib/go/thrift" 13 | 14 | ) 15 | 16 | const ( 17 | address = "localhost:9090" 18 | defaultName = "world" 19 | ) 20 | 21 | func syncTest(client *greeter.GreeterClient, name string) { 22 | i := 10000 23 | t := time.Now().UnixNano() 24 | for ; i>0; i-- { 25 | client.SayHello(name) 26 | } 27 | fmt.Println("took", (time.Now().UnixNano() - t) / 1000000, "ms") 28 | } 29 | 30 | func asyncTest(client [20]*greeter.GreeterClient, name string) { 31 | var locks [20]sync.Mutex 32 | var wg sync.WaitGroup 33 | wg.Add(10000) 34 | 35 | i := 10000 36 | t := time.Now().UnixNano() 37 | for ; i>0; i-- { 38 | go func(index int) { 39 | locks[index % 20].Lock() 40 | client[ index % 20].SayHello(name) 41 | wg.Done() 42 | locks[index % 20].Unlock() 43 | }(i) 44 | } 45 | wg.Wait() 46 | fmt.Println("took", (time.Now().UnixNano() - t) / 1000000, "ms") 47 | } 48 | 49 | 50 | func main() { 51 | transportFactory := thrift.NewTBufferedTransportFactory(8192) 52 | protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() 53 | 54 | var client [20]*greeter.GreeterClient 55 | 56 | //warm up 57 | for i := 0; i < 20; i++ { 58 | transport, err := thrift.NewTSocket(address) 59 | if err != nil { 60 | fmt.Fprintln(os.Stderr, "error resolving address:", err) 61 | os.Exit(1) 62 | } 63 | useTransport := transportFactory.GetTransport(transport) 64 | defer transport.Close() 65 | 66 | if err := transport.Open(); err != nil { 67 | fmt.Fprintln(os.Stderr, "Error opening socket to localhost:9090", " ", err) 68 | os.Exit(1) 69 | } 70 | 71 | client[i] = greeter.NewGreeterClientFactory(useTransport, protocolFactory) 72 | client[i].SayHello(defaultName) 73 | } 74 | 75 | sync := true 76 | if len(os.Args) > 1 { 77 | sync, _ = strconv.ParseBool(os.Args[1]) 78 | } 79 | 80 | if sync { 81 | syncTest(client[0], defaultName) 82 | } else { 83 | asyncTest(client, defaultName) 84 | } 85 | } -------------------------------------------------------------------------------- /thrift/golang/src/greeter/constants.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (0.9.2) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package greeter 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | ) 11 | 12 | // (needed to ensure safety because of naive import list construction.) 13 | var _ = thrift.ZERO 14 | var _ = fmt.Printf 15 | var _ = bytes.Equal 16 | 17 | func init() { 18 | } 19 | -------------------------------------------------------------------------------- /thrift/golang/src/greeter/greeter-remote/greeter-remote.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (0.9.2) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package main 5 | 6 | import ( 7 | "flag" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | "greeter" 11 | "math" 12 | "net" 13 | "net/url" 14 | "os" 15 | "strconv" 16 | "strings" 17 | ) 18 | 19 | func Usage() { 20 | fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") 21 | flag.PrintDefaults() 22 | fmt.Fprintln(os.Stderr, "\nFunctions:") 23 | fmt.Fprintln(os.Stderr, " string sayHello(string name)") 24 | fmt.Fprintln(os.Stderr) 25 | os.Exit(0) 26 | } 27 | 28 | func main() { 29 | flag.Usage = Usage 30 | var host string 31 | var port int 32 | var protocol string 33 | var urlString string 34 | var framed bool 35 | var useHttp bool 36 | var parsedUrl url.URL 37 | var trans thrift.TTransport 38 | _ = strconv.Atoi 39 | _ = math.Abs 40 | flag.Usage = Usage 41 | flag.StringVar(&host, "h", "localhost", "Specify host and port") 42 | flag.IntVar(&port, "p", 9090, "Specify port") 43 | flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") 44 | flag.StringVar(&urlString, "u", "", "Specify the url") 45 | flag.BoolVar(&framed, "framed", false, "Use framed transport") 46 | flag.BoolVar(&useHttp, "http", false, "Use http") 47 | flag.Parse() 48 | 49 | if len(urlString) > 0 { 50 | parsedUrl, err := url.Parse(urlString) 51 | if err != nil { 52 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 53 | flag.Usage() 54 | } 55 | host = parsedUrl.Host 56 | useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" 57 | } else if useHttp { 58 | _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) 59 | if err != nil { 60 | fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 61 | flag.Usage() 62 | } 63 | } 64 | 65 | cmd := flag.Arg(0) 66 | var err error 67 | if useHttp { 68 | trans, err = thrift.NewTHttpClient(parsedUrl.String()) 69 | } else { 70 | portStr := fmt.Sprint(port) 71 | if strings.Contains(host, ":") { 72 | host, portStr, err = net.SplitHostPort(host) 73 | if err != nil { 74 | fmt.Fprintln(os.Stderr, "error with host:", err) 75 | os.Exit(1) 76 | } 77 | } 78 | trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) 79 | if err != nil { 80 | fmt.Fprintln(os.Stderr, "error resolving address:", err) 81 | os.Exit(1) 82 | } 83 | if framed { 84 | trans = thrift.NewTFramedTransport(trans) 85 | } 86 | } 87 | if err != nil { 88 | fmt.Fprintln(os.Stderr, "Error creating transport", err) 89 | os.Exit(1) 90 | } 91 | defer trans.Close() 92 | var protocolFactory thrift.TProtocolFactory 93 | switch protocol { 94 | case "compact": 95 | protocolFactory = thrift.NewTCompactProtocolFactory() 96 | break 97 | case "simplejson": 98 | protocolFactory = thrift.NewTSimpleJSONProtocolFactory() 99 | break 100 | case "json": 101 | protocolFactory = thrift.NewTJSONProtocolFactory() 102 | break 103 | case "binary", "": 104 | protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() 105 | break 106 | default: 107 | fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) 108 | Usage() 109 | os.Exit(1) 110 | } 111 | client := greeter.NewGreeterClientFactory(trans, protocolFactory) 112 | if err := trans.Open(); err != nil { 113 | fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) 114 | os.Exit(1) 115 | } 116 | 117 | switch cmd { 118 | case "sayHello": 119 | if flag.NArg()-1 != 1 { 120 | fmt.Fprintln(os.Stderr, "SayHello requires 1 args") 121 | flag.Usage() 122 | } 123 | argvalue0 := flag.Arg(1) 124 | value0 := argvalue0 125 | fmt.Print(client.SayHello(value0)) 126 | fmt.Print("\n") 127 | break 128 | case "": 129 | Usage() 130 | break 131 | default: 132 | fmt.Fprintln(os.Stderr, "Invalid function ", cmd) 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /thrift/golang/src/greeter/greeter.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (0.9.2) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package greeter 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | ) 11 | 12 | // (needed to ensure safety because of naive import list construction.) 13 | var _ = thrift.ZERO 14 | var _ = fmt.Printf 15 | var _ = bytes.Equal 16 | 17 | type Greeter interface { 18 | // Parameters: 19 | // - Name 20 | SayHello(name string) (r string, err error) 21 | } 22 | 23 | type GreeterClient struct { 24 | Transport thrift.TTransport 25 | ProtocolFactory thrift.TProtocolFactory 26 | InputProtocol thrift.TProtocol 27 | OutputProtocol thrift.TProtocol 28 | SeqId int32 29 | } 30 | 31 | func NewGreeterClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *GreeterClient { 32 | return &GreeterClient{Transport: t, 33 | ProtocolFactory: f, 34 | InputProtocol: f.GetProtocol(t), 35 | OutputProtocol: f.GetProtocol(t), 36 | SeqId: 0, 37 | } 38 | } 39 | 40 | func NewGreeterClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *GreeterClient { 41 | return &GreeterClient{Transport: t, 42 | ProtocolFactory: nil, 43 | InputProtocol: iprot, 44 | OutputProtocol: oprot, 45 | SeqId: 0, 46 | } 47 | } 48 | 49 | // Parameters: 50 | // - Name 51 | func (p *GreeterClient) SayHello(name string) (r string, err error) { 52 | if err = p.sendSayHello(name); err != nil { 53 | return 54 | } 55 | return p.recvSayHello() 56 | } 57 | 58 | func (p *GreeterClient) sendSayHello(name string) (err error) { 59 | oprot := p.OutputProtocol 60 | if oprot == nil { 61 | oprot = p.ProtocolFactory.GetProtocol(p.Transport) 62 | p.OutputProtocol = oprot 63 | } 64 | p.SeqId++ 65 | if err = oprot.WriteMessageBegin("sayHello", thrift.CALL, p.SeqId); err != nil { 66 | return 67 | } 68 | args := SayHelloArgs{ 69 | Name: name, 70 | } 71 | if err = args.Write(oprot); err != nil { 72 | return 73 | } 74 | if err = oprot.WriteMessageEnd(); err != nil { 75 | return 76 | } 77 | return oprot.Flush() 78 | } 79 | 80 | func (p *GreeterClient) recvSayHello() (value string, err error) { 81 | iprot := p.InputProtocol 82 | if iprot == nil { 83 | iprot = p.ProtocolFactory.GetProtocol(p.Transport) 84 | p.InputProtocol = iprot 85 | } 86 | _, mTypeId, seqId, err := iprot.ReadMessageBegin() 87 | if err != nil { 88 | return 89 | } 90 | if mTypeId == thrift.EXCEPTION { 91 | error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") 92 | var error1 error 93 | error1, err = error0.Read(iprot) 94 | if err != nil { 95 | return 96 | } 97 | if err = iprot.ReadMessageEnd(); err != nil { 98 | return 99 | } 100 | err = error1 101 | return 102 | } 103 | if p.SeqId != seqId { 104 | err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "sayHello failed: out of sequence response") 105 | return 106 | } 107 | result := SayHelloResult{} 108 | if err = result.Read(iprot); err != nil { 109 | return 110 | } 111 | if err = iprot.ReadMessageEnd(); err != nil { 112 | return 113 | } 114 | value = result.GetSuccess() 115 | return 116 | } 117 | 118 | type GreeterProcessor struct { 119 | processorMap map[string]thrift.TProcessorFunction 120 | handler Greeter 121 | } 122 | 123 | func (p *GreeterProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { 124 | p.processorMap[key] = processor 125 | } 126 | 127 | func (p *GreeterProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { 128 | processor, ok = p.processorMap[key] 129 | return processor, ok 130 | } 131 | 132 | func (p *GreeterProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { 133 | return p.processorMap 134 | } 135 | 136 | func NewGreeterProcessor(handler Greeter) *GreeterProcessor { 137 | 138 | self2 := &GreeterProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} 139 | self2.processorMap["sayHello"] = &greeterProcessorSayHello{handler: handler} 140 | return self2 141 | } 142 | 143 | func (p *GreeterProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { 144 | name, _, seqId, err := iprot.ReadMessageBegin() 145 | if err != nil { 146 | return false, err 147 | } 148 | if processor, ok := p.GetProcessorFunction(name); ok { 149 | return processor.Process(seqId, iprot, oprot) 150 | } 151 | iprot.Skip(thrift.STRUCT) 152 | iprot.ReadMessageEnd() 153 | x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) 154 | oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) 155 | x3.Write(oprot) 156 | oprot.WriteMessageEnd() 157 | oprot.Flush() 158 | return false, x3 159 | 160 | } 161 | 162 | type greeterProcessorSayHello struct { 163 | handler Greeter 164 | } 165 | 166 | func (p *greeterProcessorSayHello) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { 167 | args := SayHelloArgs{} 168 | if err = args.Read(iprot); err != nil { 169 | iprot.ReadMessageEnd() 170 | x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) 171 | oprot.WriteMessageBegin("sayHello", thrift.EXCEPTION, seqId) 172 | x.Write(oprot) 173 | oprot.WriteMessageEnd() 174 | oprot.Flush() 175 | return false, err 176 | } 177 | 178 | iprot.ReadMessageEnd() 179 | result := SayHelloResult{} 180 | var retval string 181 | var err2 error 182 | if retval, err2 = p.handler.SayHello(args.Name); err2 != nil { 183 | x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing sayHello: "+err2.Error()) 184 | oprot.WriteMessageBegin("sayHello", thrift.EXCEPTION, seqId) 185 | x.Write(oprot) 186 | oprot.WriteMessageEnd() 187 | oprot.Flush() 188 | return true, err2 189 | } else { 190 | result.Success = &retval 191 | } 192 | if err2 = oprot.WriteMessageBegin("sayHello", thrift.REPLY, seqId); err2 != nil { 193 | err = err2 194 | } 195 | if err2 = result.Write(oprot); err == nil && err2 != nil { 196 | err = err2 197 | } 198 | if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { 199 | err = err2 200 | } 201 | if err2 = oprot.Flush(); err == nil && err2 != nil { 202 | err = err2 203 | } 204 | if err != nil { 205 | return 206 | } 207 | return true, err 208 | } 209 | 210 | // HELPER FUNCTIONS AND STRUCTURES 211 | 212 | type SayHelloArgs struct { 213 | Name string `thrift:"name,1" json:"name"` 214 | } 215 | 216 | func NewSayHelloArgs() *SayHelloArgs { 217 | return &SayHelloArgs{} 218 | } 219 | 220 | func (p *SayHelloArgs) GetName() string { 221 | return p.Name 222 | } 223 | func (p *SayHelloArgs) Read(iprot thrift.TProtocol) error { 224 | if _, err := iprot.ReadStructBegin(); err != nil { 225 | return fmt.Errorf("%T read error: %s", p, err) 226 | } 227 | for { 228 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() 229 | if err != nil { 230 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) 231 | } 232 | if fieldTypeId == thrift.STOP { 233 | break 234 | } 235 | switch fieldId { 236 | case 1: 237 | if err := p.ReadField1(iprot); err != nil { 238 | return err 239 | } 240 | default: 241 | if err := iprot.Skip(fieldTypeId); err != nil { 242 | return err 243 | } 244 | } 245 | if err := iprot.ReadFieldEnd(); err != nil { 246 | return err 247 | } 248 | } 249 | if err := iprot.ReadStructEnd(); err != nil { 250 | return fmt.Errorf("%T read struct end error: %s", p, err) 251 | } 252 | return nil 253 | } 254 | 255 | func (p *SayHelloArgs) ReadField1(iprot thrift.TProtocol) error { 256 | if v, err := iprot.ReadString(); err != nil { 257 | return fmt.Errorf("error reading field 1: %s", err) 258 | } else { 259 | p.Name = v 260 | } 261 | return nil 262 | } 263 | 264 | func (p *SayHelloArgs) Write(oprot thrift.TProtocol) error { 265 | if err := oprot.WriteStructBegin("sayHello_args"); err != nil { 266 | return fmt.Errorf("%T write struct begin error: %s", p, err) 267 | } 268 | if err := p.writeField1(oprot); err != nil { 269 | return err 270 | } 271 | if err := oprot.WriteFieldStop(); err != nil { 272 | return fmt.Errorf("write field stop error: %s", err) 273 | } 274 | if err := oprot.WriteStructEnd(); err != nil { 275 | return fmt.Errorf("write struct stop error: %s", err) 276 | } 277 | return nil 278 | } 279 | 280 | func (p *SayHelloArgs) writeField1(oprot thrift.TProtocol) (err error) { 281 | if err := oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil { 282 | return fmt.Errorf("%T write field begin error 1:name: %s", p, err) 283 | } 284 | if err := oprot.WriteString(string(p.Name)); err != nil { 285 | return fmt.Errorf("%T.name (1) field write error: %s", p, err) 286 | } 287 | if err := oprot.WriteFieldEnd(); err != nil { 288 | return fmt.Errorf("%T write field end error 1:name: %s", p, err) 289 | } 290 | return err 291 | } 292 | 293 | func (p *SayHelloArgs) String() string { 294 | if p == nil { 295 | return "" 296 | } 297 | return fmt.Sprintf("SayHelloArgs(%+v)", *p) 298 | } 299 | 300 | type SayHelloResult struct { 301 | Success *string `thrift:"success,0" json:"success"` 302 | } 303 | 304 | func NewSayHelloResult() *SayHelloResult { 305 | return &SayHelloResult{} 306 | } 307 | 308 | var SayHelloResult_Success_DEFAULT string 309 | 310 | func (p *SayHelloResult) GetSuccess() string { 311 | if !p.IsSetSuccess() { 312 | return SayHelloResult_Success_DEFAULT 313 | } 314 | return *p.Success 315 | } 316 | func (p *SayHelloResult) IsSetSuccess() bool { 317 | return p.Success != nil 318 | } 319 | 320 | func (p *SayHelloResult) Read(iprot thrift.TProtocol) error { 321 | if _, err := iprot.ReadStructBegin(); err != nil { 322 | return fmt.Errorf("%T read error: %s", p, err) 323 | } 324 | for { 325 | _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() 326 | if err != nil { 327 | return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) 328 | } 329 | if fieldTypeId == thrift.STOP { 330 | break 331 | } 332 | switch fieldId { 333 | case 0: 334 | if err := p.ReadField0(iprot); err != nil { 335 | return err 336 | } 337 | default: 338 | if err := iprot.Skip(fieldTypeId); err != nil { 339 | return err 340 | } 341 | } 342 | if err := iprot.ReadFieldEnd(); err != nil { 343 | return err 344 | } 345 | } 346 | if err := iprot.ReadStructEnd(); err != nil { 347 | return fmt.Errorf("%T read struct end error: %s", p, err) 348 | } 349 | return nil 350 | } 351 | 352 | func (p *SayHelloResult) ReadField0(iprot thrift.TProtocol) error { 353 | if v, err := iprot.ReadString(); err != nil { 354 | return fmt.Errorf("error reading field 0: %s", err) 355 | } else { 356 | p.Success = &v 357 | } 358 | return nil 359 | } 360 | 361 | func (p *SayHelloResult) Write(oprot thrift.TProtocol) error { 362 | if err := oprot.WriteStructBegin("sayHello_result"); err != nil { 363 | return fmt.Errorf("%T write struct begin error: %s", p, err) 364 | } 365 | if err := p.writeField0(oprot); err != nil { 366 | return err 367 | } 368 | if err := oprot.WriteFieldStop(); err != nil { 369 | return fmt.Errorf("write field stop error: %s", err) 370 | } 371 | if err := oprot.WriteStructEnd(); err != nil { 372 | return fmt.Errorf("write struct stop error: %s", err) 373 | } 374 | return nil 375 | } 376 | 377 | func (p *SayHelloResult) writeField0(oprot thrift.TProtocol) (err error) { 378 | if p.IsSetSuccess() { 379 | if err := oprot.WriteFieldBegin("success", thrift.STRING, 0); err != nil { 380 | return fmt.Errorf("%T write field begin error 0:success: %s", p, err) 381 | } 382 | if err := oprot.WriteString(string(*p.Success)); err != nil { 383 | return fmt.Errorf("%T.success (0) field write error: %s", p, err) 384 | } 385 | if err := oprot.WriteFieldEnd(); err != nil { 386 | return fmt.Errorf("%T write field end error 0:success: %s", p, err) 387 | } 388 | } 389 | return err 390 | } 391 | 392 | func (p *SayHelloResult) String() string { 393 | if p == nil { 394 | return "" 395 | } 396 | return fmt.Sprintf("SayHelloResult(%+v)", *p) 397 | } 398 | -------------------------------------------------------------------------------- /thrift/golang/src/greeter/ttypes.go: -------------------------------------------------------------------------------- 1 | // Autogenerated by Thrift Compiler (0.9.2) 2 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 3 | 4 | package greeter 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "git.apache.org/thrift.git/lib/go/thrift" 10 | ) 11 | 12 | // (needed to ensure safety because of naive import list construction.) 13 | var _ = thrift.ZERO 14 | var _ = fmt.Printf 15 | var _ = bytes.Equal 16 | 17 | var GoUnusedProtection__ int 18 | -------------------------------------------------------------------------------- /thrift/golang/src/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "git.apache.org/thrift.git/lib/go/thrift" 8 | 9 | "greeter" 10 | ) 11 | 12 | const ( 13 | NetworkAddr = "localhost:9090" 14 | ) 15 | 16 | 17 | type GreeterHandler struct { 18 | 19 | } 20 | 21 | func NewGreeterHandler() *GreeterHandler { 22 | return &GreeterHandler{} 23 | } 24 | 25 | func (p *GreeterHandler) SayHello(name string)(r string, err error) { 26 | return "Hello " + name, nil 27 | } 28 | 29 | func main() { 30 | var protocolFactory thrift.TProtocolFactory = thrift.NewTBinaryProtocolFactoryDefault() 31 | var transportFactory thrift.TTransportFactory = thrift.NewTBufferedTransportFactory(8192) 32 | transport, err := thrift.NewTServerSocket(NetworkAddr) 33 | if err != nil { 34 | fmt.Println("Error!", err) 35 | os.Exit(1) 36 | } 37 | 38 | handler := NewGreeterHandler() 39 | processor := greeter.NewGreeterProcessor(handler) 40 | server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) 41 | fmt.Println("Starting the simple server... on ", NetworkAddr) 42 | server.Serve() 43 | } -------------------------------------------------------------------------------- /thrift/golang/thrift/helloworld.thrift: -------------------------------------------------------------------------------- 1 | namespace go greeter 2 | 3 | service Greeter { 4 | 5 | string sayHello(1:string name); 6 | 7 | } -------------------------------------------------------------------------------- /thrift/java/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .settings/ 3 | target/ 4 | *.iml 5 | *.log* 6 | .cache 7 | .classpath 8 | .project 9 | .DS_Store 10 | -------------------------------------------------------------------------------- /thrift/java/dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.colobu.rpctest 5 | thrift 6 | thrift 7 | 1.0-SNAPSHOT 8 | http://maven.apache.org 9 | 10 | 11 | 12 | org.apache.thrift.tools 13 | maven-thrift-plugin 14 | 0.1.11 15 | 16 | 17 | thrift-sources 18 | generate-sources 19 | 20 | compile 21 | 22 | 23 | 24 | thrift-test-sources 25 | generate-test-sources 26 | 27 | testCompile 28 | 29 | 30 | 31 | 32 | C:/java/thrift-0.9.2.exe 33 | 34 | 35 | 36 | maven-shade-plugin 37 | 2.4.1 38 | 39 | 40 | package 41 | 42 | shade 43 | 44 | 45 | 46 | 47 | com.colobu.rpctest.AppServer 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | junit 59 | junit 60 | 3.8.1 61 | test 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /thrift/java/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.colobu.rpctest 5 | thrift 6 | jar 7 | 1.0-SNAPSHOT 8 | thrift 9 | http://maven.apache.org 10 | 11 | 12 | junit 13 | junit 14 | 3.8.1 15 | test 16 | 17 | 18 | org.apache.thrift 19 | libthrift 20 | 0.9.2 21 | 22 | 23 | org.slf4j 24 | slf4j-api 25 | 1.7.12 26 | 27 | 28 | ch.qos.logback 29 | logback-classic 30 | 1.1.3 31 | 32 | 33 | 34 | 35 | 36 | org.apache.thrift.tools 37 | maven-thrift-plugin 38 | 0.1.11 39 | 40 | C:/java/thrift-0.9.2.exe 41 | 42 | 43 | 44 | thrift-sources 45 | generate-sources 46 | 47 | compile 48 | 49 | 50 | 51 | thrift-test-sources 52 | generate-test-sources 53 | 54 | testCompile 55 | 56 | 57 | 58 | 59 | 60 | org.apache.maven.plugins 61 | maven-shade-plugin 62 | 2.4.1 63 | 64 | 65 | package 66 | 67 | shade 68 | 69 | 70 | 71 | 72 | com.colobu.rpctest.AppServer 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /thrift/java/src/main/java/com/colobu/rpctest/AppClient.java: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | import org.apache.thrift.TException; 7 | import org.apache.thrift.protocol.TBinaryProtocol; 8 | import org.apache.thrift.protocol.TProtocol; 9 | import org.apache.thrift.transport.TSocket; 10 | import org.apache.thrift.transport.TTransport; 11 | 12 | public class AppClient { 13 | public static void main(String[] args) { 14 | try { 15 | TTransport[] transport = new TTransport[20]; 16 | Greeter.Client[] client = new Greeter.Client[20]; 17 | 18 | //warmup 19 | String name = "world"; 20 | for (int i = 0; i < 20; i++) { 21 | transport[i] = new TSocket("localhost", 9090); 22 | transport[i].open(); 23 | 24 | TProtocol protocol = new TBinaryProtocol(transport[i]); 25 | client[i] = new Greeter.Client(protocol); 26 | client[i].sayHello(name); 27 | } 28 | 29 | boolean sync = true; 30 | if (args.length > 0) { 31 | sync = Boolean.parseBoolean(args[0]); 32 | } 33 | if (sync) { syncTest(client[0], name); } 34 | else { asyncTest(client, name); } 35 | 36 | for (int i = 0; i < 20; i++) { 37 | transport[i].close(); 38 | } 39 | } 40 | catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | private static void syncTest(Greeter.Client client, String name) throws TException { 46 | long t = System.nanoTime(); 47 | for (int i = 0; i < 10000; i++) { 48 | client.sayHello(name); 49 | } 50 | System.out.println("took: " + (System.nanoTime() - t) / 1000000 + " ms"); 51 | } 52 | 53 | private static void asyncTest(final Greeter.Client[] client, final String name) throws InterruptedException { 54 | ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); 55 | final CountDownLatch latch = new CountDownLatch(10000); 56 | long t = System.nanoTime(); 57 | for (int i = 0; i < 10000; i++) { 58 | final int j = i; 59 | pool.submit(new Runnable() { 60 | @Override 61 | public void run() { 62 | synchronized (client[j % 20]) { 63 | try { 64 | client[j % 20].sayHello(name); 65 | } 66 | catch (TException e) { 67 | e.printStackTrace(); 68 | } 69 | finally { 70 | latch.countDown(); 71 | } 72 | } 73 | 74 | } 75 | }); 76 | 77 | } 78 | 79 | latch.await(); 80 | System.out.println("took: " + (System.nanoTime() - t) / 1000000 + " ms"); 81 | pool.shutdownNow(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /thrift/java/src/main/java/com/colobu/rpctest/AppServer.java: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest; 2 | 3 | import org.apache.thrift.server.TServer; 4 | import org.apache.thrift.server.TThreadPoolServer; 5 | import org.apache.thrift.transport.TServerSocket; 6 | import org.apache.thrift.transport.TServerTransport; 7 | 8 | public class AppServer 9 | { 10 | public static GreeterHandler handler; 11 | 12 | public static Greeter.Processor processor; 13 | 14 | public static void main( String[] args ) 15 | { 16 | try { 17 | handler = new GreeterHandler(); 18 | processor = new Greeter.Processor(handler); 19 | 20 | Runnable simple = new Runnable() { 21 | public void run() { 22 | simple(processor); 23 | } 24 | }; 25 | new Thread(simple).start(); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | } 31 | 32 | public static void simple(Greeter.Processor processor) { 33 | try { 34 | TServerTransport serverTransport = new TServerSocket(9090); 35 | //TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); 36 | 37 | // Use this for a multithreaded server 38 | TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor)); 39 | 40 | System.out.println("Starting the simple server..."); 41 | server.serve(); 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /thrift/java/src/main/java/com/colobu/rpctest/GreeterHandler.java: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest; 2 | 3 | import org.apache.thrift.TException; 4 | 5 | public class GreeterHandler implements Greeter.Iface { 6 | @Override 7 | public String sayHello(String name) throws TException { 8 | return "Hello " + name; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /thrift/java/src/main/thrift/helloworld.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.colobu.rpctest 2 | 3 | service Greeter { 4 | 5 | string sayHello(1:string name); 6 | 7 | } -------------------------------------------------------------------------------- /thrift/scala/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .settings/ 3 | target/ 4 | *.iml 5 | *.log* 6 | 7 | *.class 8 | *.log 9 | -------------------------------------------------------------------------------- /thrift/scala/README.md: -------------------------------------------------------------------------------- 1 | There are few sbt thrift plugins: 2 | * 3 | * 4 | * 5 | 6 | But they are too old and required thrift is very old. 7 | 8 | I copy the generated java file from the same helloworld.thrift into this project and it can be used in Scala. 9 | 10 | -------------------------------------------------------------------------------- /thrift/scala/project/Build.scala: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat 2 | import java.util.Date 3 | 4 | import com.typesafe.sbt.packager.archetypes.JavaAppPackaging 5 | import com.typesafe.sbt.packager.universal.UniversalDeployPlugin 6 | import sbt.Defaults._ 7 | import sbt.Keys._ 8 | import sbt._ 9 | import sbtbuildinfo.Plugin.{BuildInfoKey, _} 10 | import sbtrelease.ReleasePlugin._ 11 | 12 | object ApplicationBuild extends Build { 13 | 14 | lazy val root = Project("thrift", file(".")) 15 | .settings(coreDefaultSettings: _*) 16 | .settings(libraryDependencies ++= Seq("org.apache.thrift" % "libthrift" % "0.9.2", 17 | "org.slf4j" % "slf4j-api" % "1.7.12", 18 | "ch.qos.logback" % "logback-classic" % "1.1.3")) 19 | .settings(mainClass in Compile := Some("com.colobu.rpctest.AppServer")) 20 | .enablePlugins(JavaAppPackaging) 21 | } -------------------------------------------------------------------------------- /thrift/scala/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 0.13.8 -------------------------------------------------------------------------------- /thrift/scala/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | logLevel := Level.Warn 2 | 3 | resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" 4 | 5 | addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4") 6 | 7 | addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1") 8 | 9 | addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8") 10 | 11 | addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.2") 12 | 13 | addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4") 14 | 15 | addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0") 16 | 17 | addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8.5") 18 | 19 | -------------------------------------------------------------------------------- /thrift/scala/src/main/java/com/colobu/rpctest/Greeter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.2) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | package com.colobu.rpctest; 8 | 9 | import org.apache.thrift.scheme.IScheme; 10 | import org.apache.thrift.scheme.SchemeFactory; 11 | import org.apache.thrift.scheme.StandardScheme; 12 | 13 | import org.apache.thrift.scheme.TupleScheme; 14 | import org.apache.thrift.protocol.TTupleProtocol; 15 | import org.apache.thrift.protocol.TProtocolException; 16 | import org.apache.thrift.EncodingUtils; 17 | import org.apache.thrift.TException; 18 | import org.apache.thrift.async.AsyncMethodCallback; 19 | import org.apache.thrift.server.AbstractNonblockingServer.*; 20 | import java.util.List; 21 | import java.util.ArrayList; 22 | import java.util.Map; 23 | import java.util.HashMap; 24 | import java.util.EnumMap; 25 | import java.util.Set; 26 | import java.util.HashSet; 27 | import java.util.EnumSet; 28 | import java.util.Collections; 29 | import java.util.BitSet; 30 | import java.nio.ByteBuffer; 31 | import java.util.Arrays; 32 | import javax.annotation.Generated; 33 | import org.slf4j.Logger; 34 | import org.slf4j.LoggerFactory; 35 | 36 | @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) 37 | @Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-7-17") 38 | public class Greeter { 39 | 40 | public interface Iface { 41 | 42 | public String sayHello(String name) throws org.apache.thrift.TException; 43 | 44 | } 45 | 46 | public interface AsyncIface { 47 | 48 | public void sayHello(String name, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; 49 | 50 | } 51 | 52 | public static class Client extends org.apache.thrift.TServiceClient implements Iface { 53 | public static class Factory implements org.apache.thrift.TServiceClientFactory { 54 | public Factory() {} 55 | public Client getClient(org.apache.thrift.protocol.TProtocol prot) { 56 | return new Client(prot); 57 | } 58 | public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { 59 | return new Client(iprot, oprot); 60 | } 61 | } 62 | 63 | public Client(org.apache.thrift.protocol.TProtocol prot) 64 | { 65 | super(prot, prot); 66 | } 67 | 68 | public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { 69 | super(iprot, oprot); 70 | } 71 | 72 | public String sayHello(String name) throws org.apache.thrift.TException 73 | { 74 | send_sayHello(name); 75 | return recv_sayHello(); 76 | } 77 | 78 | public void send_sayHello(String name) throws org.apache.thrift.TException 79 | { 80 | sayHello_args args = new sayHello_args(); 81 | args.setName(name); 82 | sendBase("sayHello", args); 83 | } 84 | 85 | public String recv_sayHello() throws org.apache.thrift.TException 86 | { 87 | sayHello_result result = new sayHello_result(); 88 | receiveBase(result, "sayHello"); 89 | if (result.isSetSuccess()) { 90 | return result.success; 91 | } 92 | throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "sayHello failed: unknown result"); 93 | } 94 | 95 | } 96 | public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { 97 | public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { 98 | private org.apache.thrift.async.TAsyncClientManager clientManager; 99 | private org.apache.thrift.protocol.TProtocolFactory protocolFactory; 100 | public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { 101 | this.clientManager = clientManager; 102 | this.protocolFactory = protocolFactory; 103 | } 104 | public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { 105 | return new AsyncClient(protocolFactory, clientManager, transport); 106 | } 107 | } 108 | 109 | public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { 110 | super(protocolFactory, clientManager, transport); 111 | } 112 | 113 | public void sayHello(String name, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { 114 | checkReady(); 115 | sayHello_call method_call = new sayHello_call(name, resultHandler, this, ___protocolFactory, ___transport); 116 | this.___currentMethod = method_call; 117 | ___manager.call(method_call); 118 | } 119 | 120 | public static class sayHello_call extends org.apache.thrift.async.TAsyncMethodCall { 121 | private String name; 122 | public sayHello_call(String name, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { 123 | super(client, protocolFactory, transport, resultHandler, false); 124 | this.name = name; 125 | } 126 | 127 | public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { 128 | prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("sayHello", org.apache.thrift.protocol.TMessageType.CALL, 0)); 129 | sayHello_args args = new sayHello_args(); 130 | args.setName(name); 131 | args.write(prot); 132 | prot.writeMessageEnd(); 133 | } 134 | 135 | public String getResult() throws org.apache.thrift.TException { 136 | if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { 137 | throw new IllegalStateException("Method call not finished!"); 138 | } 139 | org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); 140 | org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); 141 | return (new Client(prot)).recv_sayHello(); 142 | } 143 | } 144 | 145 | } 146 | 147 | public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { 148 | private static final Logger LOGGER = LoggerFactory.getLogger(Processor.class.getName()); 149 | public Processor(I iface) { 150 | super(iface, getProcessMap(new HashMap>())); 151 | } 152 | 153 | protected Processor(I iface, Map> processMap) { 154 | super(iface, getProcessMap(processMap)); 155 | } 156 | 157 | private static Map> getProcessMap(Map> processMap) { 158 | processMap.put("sayHello", new sayHello()); 159 | return processMap; 160 | } 161 | 162 | public static class sayHello extends org.apache.thrift.ProcessFunction { 163 | public sayHello() { 164 | super("sayHello"); 165 | } 166 | 167 | public sayHello_args getEmptyArgsInstance() { 168 | return new sayHello_args(); 169 | } 170 | 171 | protected boolean isOneway() { 172 | return false; 173 | } 174 | 175 | public sayHello_result getResult(I iface, sayHello_args args) throws org.apache.thrift.TException { 176 | sayHello_result result = new sayHello_result(); 177 | result.success = iface.sayHello(args.name); 178 | return result; 179 | } 180 | } 181 | 182 | } 183 | 184 | public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { 185 | private static final Logger LOGGER = LoggerFactory.getLogger(AsyncProcessor.class.getName()); 186 | public AsyncProcessor(I iface) { 187 | super(iface, getProcessMap(new HashMap>())); 188 | } 189 | 190 | protected AsyncProcessor(I iface, Map> processMap) { 191 | super(iface, getProcessMap(processMap)); 192 | } 193 | 194 | private static Map> getProcessMap(Map> processMap) { 195 | processMap.put("sayHello", new sayHello()); 196 | return processMap; 197 | } 198 | 199 | public static class sayHello extends org.apache.thrift.AsyncProcessFunction { 200 | public sayHello() { 201 | super("sayHello"); 202 | } 203 | 204 | public sayHello_args getEmptyArgsInstance() { 205 | return new sayHello_args(); 206 | } 207 | 208 | public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { 209 | final org.apache.thrift.AsyncProcessFunction fcall = this; 210 | return new AsyncMethodCallback() { 211 | public void onComplete(String o) { 212 | sayHello_result result = new sayHello_result(); 213 | result.success = o; 214 | try { 215 | fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); 216 | return; 217 | } catch (Exception e) { 218 | LOGGER.error("Exception writing to internal frame buffer", e); 219 | } 220 | fb.close(); 221 | } 222 | public void onError(Exception e) { 223 | byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; 224 | org.apache.thrift.TBase msg; 225 | sayHello_result result = new sayHello_result(); 226 | { 227 | msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; 228 | msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); 229 | } 230 | try { 231 | fcall.sendResponse(fb,msg,msgType,seqid); 232 | return; 233 | } catch (Exception ex) { 234 | LOGGER.error("Exception writing to internal frame buffer", ex); 235 | } 236 | fb.close(); 237 | } 238 | }; 239 | } 240 | 241 | protected boolean isOneway() { 242 | return false; 243 | } 244 | 245 | public void start(I iface, sayHello_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { 246 | iface.sayHello(args.name,resultHandler); 247 | } 248 | } 249 | 250 | } 251 | 252 | public static class sayHello_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 253 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayHello_args"); 254 | 255 | private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1); 256 | 257 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 258 | static { 259 | schemes.put(StandardScheme.class, new sayHello_argsStandardSchemeFactory()); 260 | schemes.put(TupleScheme.class, new sayHello_argsTupleSchemeFactory()); 261 | } 262 | 263 | public String name; // required 264 | 265 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 266 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 267 | NAME((short)1, "name"); 268 | 269 | private static final Map byName = new HashMap(); 270 | 271 | static { 272 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 273 | byName.put(field.getFieldName(), field); 274 | } 275 | } 276 | 277 | /** 278 | * Find the _Fields constant that matches fieldId, or null if its not found. 279 | */ 280 | public static _Fields findByThriftId(int fieldId) { 281 | switch(fieldId) { 282 | case 1: // NAME 283 | return NAME; 284 | default: 285 | return null; 286 | } 287 | } 288 | 289 | /** 290 | * Find the _Fields constant that matches fieldId, throwing an exception 291 | * if it is not found. 292 | */ 293 | public static _Fields findByThriftIdOrThrow(int fieldId) { 294 | _Fields fields = findByThriftId(fieldId); 295 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 296 | return fields; 297 | } 298 | 299 | /** 300 | * Find the _Fields constant that matches name, or null if its not found. 301 | */ 302 | public static _Fields findByName(String name) { 303 | return byName.get(name); 304 | } 305 | 306 | private final short _thriftId; 307 | private final String _fieldName; 308 | 309 | _Fields(short thriftId, String fieldName) { 310 | _thriftId = thriftId; 311 | _fieldName = fieldName; 312 | } 313 | 314 | public short getThriftFieldId() { 315 | return _thriftId; 316 | } 317 | 318 | public String getFieldName() { 319 | return _fieldName; 320 | } 321 | } 322 | 323 | // isset id assignments 324 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 325 | static { 326 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 327 | tmpMap.put(_Fields.NAME, new org.apache.thrift.meta_data.FieldMetaData("name", org.apache.thrift.TFieldRequirementType.DEFAULT, 328 | new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); 329 | metaDataMap = Collections.unmodifiableMap(tmpMap); 330 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayHello_args.class, metaDataMap); 331 | } 332 | 333 | public sayHello_args() { 334 | } 335 | 336 | public sayHello_args( 337 | String name) 338 | { 339 | this(); 340 | this.name = name; 341 | } 342 | 343 | /** 344 | * Performs a deep copy on other. 345 | */ 346 | public sayHello_args(sayHello_args other) { 347 | if (other.isSetName()) { 348 | this.name = other.name; 349 | } 350 | } 351 | 352 | public sayHello_args deepCopy() { 353 | return new sayHello_args(this); 354 | } 355 | 356 | @Override 357 | public void clear() { 358 | this.name = null; 359 | } 360 | 361 | public String getName() { 362 | return this.name; 363 | } 364 | 365 | public sayHello_args setName(String name) { 366 | this.name = name; 367 | return this; 368 | } 369 | 370 | public void unsetName() { 371 | this.name = null; 372 | } 373 | 374 | /** Returns true if field name is set (has been assigned a value) and false otherwise */ 375 | public boolean isSetName() { 376 | return this.name != null; 377 | } 378 | 379 | public void setNameIsSet(boolean value) { 380 | if (!value) { 381 | this.name = null; 382 | } 383 | } 384 | 385 | public void setFieldValue(_Fields field, Object value) { 386 | switch (field) { 387 | case NAME: 388 | if (value == null) { 389 | unsetName(); 390 | } else { 391 | setName((String)value); 392 | } 393 | break; 394 | 395 | } 396 | } 397 | 398 | public Object getFieldValue(_Fields field) { 399 | switch (field) { 400 | case NAME: 401 | return getName(); 402 | 403 | } 404 | throw new IllegalStateException(); 405 | } 406 | 407 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 408 | public boolean isSet(_Fields field) { 409 | if (field == null) { 410 | throw new IllegalArgumentException(); 411 | } 412 | 413 | switch (field) { 414 | case NAME: 415 | return isSetName(); 416 | } 417 | throw new IllegalStateException(); 418 | } 419 | 420 | @Override 421 | public boolean equals(Object that) { 422 | if (that == null) 423 | return false; 424 | if (that instanceof sayHello_args) 425 | return this.equals((sayHello_args)that); 426 | return false; 427 | } 428 | 429 | public boolean equals(sayHello_args that) { 430 | if (that == null) 431 | return false; 432 | 433 | boolean this_present_name = true && this.isSetName(); 434 | boolean that_present_name = true && that.isSetName(); 435 | if (this_present_name || that_present_name) { 436 | if (!(this_present_name && that_present_name)) 437 | return false; 438 | if (!this.name.equals(that.name)) 439 | return false; 440 | } 441 | 442 | return true; 443 | } 444 | 445 | @Override 446 | public int hashCode() { 447 | List list = new ArrayList(); 448 | 449 | boolean present_name = true && (isSetName()); 450 | list.add(present_name); 451 | if (present_name) 452 | list.add(name); 453 | 454 | return list.hashCode(); 455 | } 456 | 457 | @Override 458 | public int compareTo(sayHello_args other) { 459 | if (!getClass().equals(other.getClass())) { 460 | return getClass().getName().compareTo(other.getClass().getName()); 461 | } 462 | 463 | int lastComparison = 0; 464 | 465 | lastComparison = Boolean.valueOf(isSetName()).compareTo(other.isSetName()); 466 | if (lastComparison != 0) { 467 | return lastComparison; 468 | } 469 | if (isSetName()) { 470 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.name, other.name); 471 | if (lastComparison != 0) { 472 | return lastComparison; 473 | } 474 | } 475 | return 0; 476 | } 477 | 478 | public _Fields fieldForId(int fieldId) { 479 | return _Fields.findByThriftId(fieldId); 480 | } 481 | 482 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 483 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 484 | } 485 | 486 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 487 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 488 | } 489 | 490 | @Override 491 | public String toString() { 492 | StringBuilder sb = new StringBuilder("sayHello_args("); 493 | boolean first = true; 494 | 495 | sb.append("name:"); 496 | if (this.name == null) { 497 | sb.append("null"); 498 | } else { 499 | sb.append(this.name); 500 | } 501 | first = false; 502 | sb.append(")"); 503 | return sb.toString(); 504 | } 505 | 506 | public void validate() throws org.apache.thrift.TException { 507 | // check for required fields 508 | // check for sub-struct validity 509 | } 510 | 511 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 512 | try { 513 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 514 | } catch (org.apache.thrift.TException te) { 515 | throw new java.io.IOException(te); 516 | } 517 | } 518 | 519 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 520 | try { 521 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 522 | } catch (org.apache.thrift.TException te) { 523 | throw new java.io.IOException(te); 524 | } 525 | } 526 | 527 | private static class sayHello_argsStandardSchemeFactory implements SchemeFactory { 528 | public sayHello_argsStandardScheme getScheme() { 529 | return new sayHello_argsStandardScheme(); 530 | } 531 | } 532 | 533 | private static class sayHello_argsStandardScheme extends StandardScheme { 534 | 535 | public void read(org.apache.thrift.protocol.TProtocol iprot, sayHello_args struct) throws org.apache.thrift.TException { 536 | org.apache.thrift.protocol.TField schemeField; 537 | iprot.readStructBegin(); 538 | while (true) 539 | { 540 | schemeField = iprot.readFieldBegin(); 541 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 542 | break; 543 | } 544 | switch (schemeField.id) { 545 | case 1: // NAME 546 | if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { 547 | struct.name = iprot.readString(); 548 | struct.setNameIsSet(true); 549 | } else { 550 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 551 | } 552 | break; 553 | default: 554 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 555 | } 556 | iprot.readFieldEnd(); 557 | } 558 | iprot.readStructEnd(); 559 | 560 | // check for required fields of primitive type, which can't be checked in the validate method 561 | struct.validate(); 562 | } 563 | 564 | public void write(org.apache.thrift.protocol.TProtocol oprot, sayHello_args struct) throws org.apache.thrift.TException { 565 | struct.validate(); 566 | 567 | oprot.writeStructBegin(STRUCT_DESC); 568 | if (struct.name != null) { 569 | oprot.writeFieldBegin(NAME_FIELD_DESC); 570 | oprot.writeString(struct.name); 571 | oprot.writeFieldEnd(); 572 | } 573 | oprot.writeFieldStop(); 574 | oprot.writeStructEnd(); 575 | } 576 | 577 | } 578 | 579 | private static class sayHello_argsTupleSchemeFactory implements SchemeFactory { 580 | public sayHello_argsTupleScheme getScheme() { 581 | return new sayHello_argsTupleScheme(); 582 | } 583 | } 584 | 585 | private static class sayHello_argsTupleScheme extends TupleScheme { 586 | 587 | @Override 588 | public void write(org.apache.thrift.protocol.TProtocol prot, sayHello_args struct) throws org.apache.thrift.TException { 589 | TTupleProtocol oprot = (TTupleProtocol) prot; 590 | BitSet optionals = new BitSet(); 591 | if (struct.isSetName()) { 592 | optionals.set(0); 593 | } 594 | oprot.writeBitSet(optionals, 1); 595 | if (struct.isSetName()) { 596 | oprot.writeString(struct.name); 597 | } 598 | } 599 | 600 | @Override 601 | public void read(org.apache.thrift.protocol.TProtocol prot, sayHello_args struct) throws org.apache.thrift.TException { 602 | TTupleProtocol iprot = (TTupleProtocol) prot; 603 | BitSet incoming = iprot.readBitSet(1); 604 | if (incoming.get(0)) { 605 | struct.name = iprot.readString(); 606 | struct.setNameIsSet(true); 607 | } 608 | } 609 | } 610 | 611 | } 612 | 613 | public static class sayHello_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { 614 | private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("sayHello_result"); 615 | 616 | private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRING, (short)0); 617 | 618 | private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); 619 | static { 620 | schemes.put(StandardScheme.class, new sayHello_resultStandardSchemeFactory()); 621 | schemes.put(TupleScheme.class, new sayHello_resultTupleSchemeFactory()); 622 | } 623 | 624 | public String success; // required 625 | 626 | /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ 627 | public enum _Fields implements org.apache.thrift.TFieldIdEnum { 628 | SUCCESS((short)0, "success"); 629 | 630 | private static final Map byName = new HashMap(); 631 | 632 | static { 633 | for (_Fields field : EnumSet.allOf(_Fields.class)) { 634 | byName.put(field.getFieldName(), field); 635 | } 636 | } 637 | 638 | /** 639 | * Find the _Fields constant that matches fieldId, or null if its not found. 640 | */ 641 | public static _Fields findByThriftId(int fieldId) { 642 | switch(fieldId) { 643 | case 0: // SUCCESS 644 | return SUCCESS; 645 | default: 646 | return null; 647 | } 648 | } 649 | 650 | /** 651 | * Find the _Fields constant that matches fieldId, throwing an exception 652 | * if it is not found. 653 | */ 654 | public static _Fields findByThriftIdOrThrow(int fieldId) { 655 | _Fields fields = findByThriftId(fieldId); 656 | if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); 657 | return fields; 658 | } 659 | 660 | /** 661 | * Find the _Fields constant that matches name, or null if its not found. 662 | */ 663 | public static _Fields findByName(String name) { 664 | return byName.get(name); 665 | } 666 | 667 | private final short _thriftId; 668 | private final String _fieldName; 669 | 670 | _Fields(short thriftId, String fieldName) { 671 | _thriftId = thriftId; 672 | _fieldName = fieldName; 673 | } 674 | 675 | public short getThriftFieldId() { 676 | return _thriftId; 677 | } 678 | 679 | public String getFieldName() { 680 | return _fieldName; 681 | } 682 | } 683 | 684 | // isset id assignments 685 | public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; 686 | static { 687 | Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); 688 | tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, 689 | new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); 690 | metaDataMap = Collections.unmodifiableMap(tmpMap); 691 | org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(sayHello_result.class, metaDataMap); 692 | } 693 | 694 | public sayHello_result() { 695 | } 696 | 697 | public sayHello_result( 698 | String success) 699 | { 700 | this(); 701 | this.success = success; 702 | } 703 | 704 | /** 705 | * Performs a deep copy on other. 706 | */ 707 | public sayHello_result(sayHello_result other) { 708 | if (other.isSetSuccess()) { 709 | this.success = other.success; 710 | } 711 | } 712 | 713 | public sayHello_result deepCopy() { 714 | return new sayHello_result(this); 715 | } 716 | 717 | @Override 718 | public void clear() { 719 | this.success = null; 720 | } 721 | 722 | public String getSuccess() { 723 | return this.success; 724 | } 725 | 726 | public sayHello_result setSuccess(String success) { 727 | this.success = success; 728 | return this; 729 | } 730 | 731 | public void unsetSuccess() { 732 | this.success = null; 733 | } 734 | 735 | /** Returns true if field success is set (has been assigned a value) and false otherwise */ 736 | public boolean isSetSuccess() { 737 | return this.success != null; 738 | } 739 | 740 | public void setSuccessIsSet(boolean value) { 741 | if (!value) { 742 | this.success = null; 743 | } 744 | } 745 | 746 | public void setFieldValue(_Fields field, Object value) { 747 | switch (field) { 748 | case SUCCESS: 749 | if (value == null) { 750 | unsetSuccess(); 751 | } else { 752 | setSuccess((String)value); 753 | } 754 | break; 755 | 756 | } 757 | } 758 | 759 | public Object getFieldValue(_Fields field) { 760 | switch (field) { 761 | case SUCCESS: 762 | return getSuccess(); 763 | 764 | } 765 | throw new IllegalStateException(); 766 | } 767 | 768 | /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ 769 | public boolean isSet(_Fields field) { 770 | if (field == null) { 771 | throw new IllegalArgumentException(); 772 | } 773 | 774 | switch (field) { 775 | case SUCCESS: 776 | return isSetSuccess(); 777 | } 778 | throw new IllegalStateException(); 779 | } 780 | 781 | @Override 782 | public boolean equals(Object that) { 783 | if (that == null) 784 | return false; 785 | if (that instanceof sayHello_result) 786 | return this.equals((sayHello_result)that); 787 | return false; 788 | } 789 | 790 | public boolean equals(sayHello_result that) { 791 | if (that == null) 792 | return false; 793 | 794 | boolean this_present_success = true && this.isSetSuccess(); 795 | boolean that_present_success = true && that.isSetSuccess(); 796 | if (this_present_success || that_present_success) { 797 | if (!(this_present_success && that_present_success)) 798 | return false; 799 | if (!this.success.equals(that.success)) 800 | return false; 801 | } 802 | 803 | return true; 804 | } 805 | 806 | @Override 807 | public int hashCode() { 808 | List list = new ArrayList(); 809 | 810 | boolean present_success = true && (isSetSuccess()); 811 | list.add(present_success); 812 | if (present_success) 813 | list.add(success); 814 | 815 | return list.hashCode(); 816 | } 817 | 818 | @Override 819 | public int compareTo(sayHello_result other) { 820 | if (!getClass().equals(other.getClass())) { 821 | return getClass().getName().compareTo(other.getClass().getName()); 822 | } 823 | 824 | int lastComparison = 0; 825 | 826 | lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); 827 | if (lastComparison != 0) { 828 | return lastComparison; 829 | } 830 | if (isSetSuccess()) { 831 | lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); 832 | if (lastComparison != 0) { 833 | return lastComparison; 834 | } 835 | } 836 | return 0; 837 | } 838 | 839 | public _Fields fieldForId(int fieldId) { 840 | return _Fields.findByThriftId(fieldId); 841 | } 842 | 843 | public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { 844 | schemes.get(iprot.getScheme()).getScheme().read(iprot, this); 845 | } 846 | 847 | public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { 848 | schemes.get(oprot.getScheme()).getScheme().write(oprot, this); 849 | } 850 | 851 | @Override 852 | public String toString() { 853 | StringBuilder sb = new StringBuilder("sayHello_result("); 854 | boolean first = true; 855 | 856 | sb.append("success:"); 857 | if (this.success == null) { 858 | sb.append("null"); 859 | } else { 860 | sb.append(this.success); 861 | } 862 | first = false; 863 | sb.append(")"); 864 | return sb.toString(); 865 | } 866 | 867 | public void validate() throws org.apache.thrift.TException { 868 | // check for required fields 869 | // check for sub-struct validity 870 | } 871 | 872 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 873 | try { 874 | write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); 875 | } catch (org.apache.thrift.TException te) { 876 | throw new java.io.IOException(te); 877 | } 878 | } 879 | 880 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 881 | try { 882 | read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); 883 | } catch (org.apache.thrift.TException te) { 884 | throw new java.io.IOException(te); 885 | } 886 | } 887 | 888 | private static class sayHello_resultStandardSchemeFactory implements SchemeFactory { 889 | public sayHello_resultStandardScheme getScheme() { 890 | return new sayHello_resultStandardScheme(); 891 | } 892 | } 893 | 894 | private static class sayHello_resultStandardScheme extends StandardScheme { 895 | 896 | public void read(org.apache.thrift.protocol.TProtocol iprot, sayHello_result struct) throws org.apache.thrift.TException { 897 | org.apache.thrift.protocol.TField schemeField; 898 | iprot.readStructBegin(); 899 | while (true) 900 | { 901 | schemeField = iprot.readFieldBegin(); 902 | if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 903 | break; 904 | } 905 | switch (schemeField.id) { 906 | case 0: // SUCCESS 907 | if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { 908 | struct.success = iprot.readString(); 909 | struct.setSuccessIsSet(true); 910 | } else { 911 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 912 | } 913 | break; 914 | default: 915 | org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); 916 | } 917 | iprot.readFieldEnd(); 918 | } 919 | iprot.readStructEnd(); 920 | 921 | // check for required fields of primitive type, which can't be checked in the validate method 922 | struct.validate(); 923 | } 924 | 925 | public void write(org.apache.thrift.protocol.TProtocol oprot, sayHello_result struct) throws org.apache.thrift.TException { 926 | struct.validate(); 927 | 928 | oprot.writeStructBegin(STRUCT_DESC); 929 | if (struct.success != null) { 930 | oprot.writeFieldBegin(SUCCESS_FIELD_DESC); 931 | oprot.writeString(struct.success); 932 | oprot.writeFieldEnd(); 933 | } 934 | oprot.writeFieldStop(); 935 | oprot.writeStructEnd(); 936 | } 937 | 938 | } 939 | 940 | private static class sayHello_resultTupleSchemeFactory implements SchemeFactory { 941 | public sayHello_resultTupleScheme getScheme() { 942 | return new sayHello_resultTupleScheme(); 943 | } 944 | } 945 | 946 | private static class sayHello_resultTupleScheme extends TupleScheme { 947 | 948 | @Override 949 | public void write(org.apache.thrift.protocol.TProtocol prot, sayHello_result struct) throws org.apache.thrift.TException { 950 | TTupleProtocol oprot = (TTupleProtocol) prot; 951 | BitSet optionals = new BitSet(); 952 | if (struct.isSetSuccess()) { 953 | optionals.set(0); 954 | } 955 | oprot.writeBitSet(optionals, 1); 956 | if (struct.isSetSuccess()) { 957 | oprot.writeString(struct.success); 958 | } 959 | } 960 | 961 | @Override 962 | public void read(org.apache.thrift.protocol.TProtocol prot, sayHello_result struct) throws org.apache.thrift.TException { 963 | TTupleProtocol iprot = (TTupleProtocol) prot; 964 | BitSet incoming = iprot.readBitSet(1); 965 | if (incoming.get(0)) { 966 | struct.success = iprot.readString(); 967 | struct.setSuccessIsSet(true); 968 | } 969 | } 970 | } 971 | 972 | } 973 | 974 | } 975 | -------------------------------------------------------------------------------- /thrift/scala/src/main/scala/com/colobu/rpctest/AppClient.scala: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest 2 | 3 | import java.util.concurrent.{CountDownLatch, Executors} 4 | 5 | import org.apache.thrift.protocol.TBinaryProtocol 6 | import org.apache.thrift.transport.TSocket 7 | 8 | object AppClient extends App{ 9 | try { 10 | val transport = new Array[TSocket](20) 11 | val client = new Array[Greeter.Client](20) 12 | //new Greeter.Client(protocol) 13 | 14 | //warm up 15 | val name = "world" 16 | 17 | for (i <- 0 to 19) { 18 | transport(i) = new TSocket("localhost", 9090) 19 | transport(i).open() 20 | 21 | val protocol = new TBinaryProtocol(transport(i)) 22 | client(i) = new Greeter.Client(protocol) 23 | client(i).sayHello(name) 24 | } 25 | 26 | var sync = true 27 | if (args.length > 0) { 28 | sync = args(0).toBoolean 29 | } 30 | 31 | if (sync) { 32 | syncTest(client(0), name) 33 | } 34 | else { 35 | asyncTest(client, name) 36 | } 37 | 38 | for (i <- 0 to 19) { 39 | transport(i).close() 40 | } 41 | } 42 | catch { 43 | case e: Throwable => e.printStackTrace() 44 | } 45 | 46 | 47 | def syncTest(client:Greeter.Client , name:String):Unit = { 48 | val t = System.nanoTime() 49 | for (i <- 1 to 10000) { 50 | client.sayHello(name) 51 | } 52 | println("took: " + (System.nanoTime() - t) / 1000000 + " ms") 53 | } 54 | 55 | def asyncTest(client:Array[Greeter.Client] , name:String):Unit = { 56 | val latch = new CountDownLatch(10000) 57 | val pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2) 58 | val t = System.nanoTime() 59 | for (i <- 1 to 10000) { 60 | pool.submit(new Runnable { 61 | override def run(): Unit = { 62 | client(i% 20) synchronized { 63 | client(i % 20).sayHello(name) 64 | latch.countDown() 65 | } 66 | } 67 | }) 68 | } 69 | latch.await() 70 | println("took: " + (System.nanoTime() - t) / 1000000 + " ms") 71 | pool.shutdownNow() 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /thrift/scala/src/main/scala/com/colobu/rpctest/AppServer.scala: -------------------------------------------------------------------------------- 1 | package com.colobu.rpctest 2 | 3 | import org.apache.thrift.server.TServer 4 | import org.apache.thrift.server.TThreadPoolServer 5 | import org.apache.thrift.transport.TServerSocket 6 | import org.apache.thrift.transport.TServerTransport 7 | 8 | object AppServer extends App { 9 | def simple(processor: Greeter.Processor[GreeterHandler]): Unit = { 10 | try { 11 | val serverTransport = new TServerSocket(9090) 12 | //TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); 13 | 14 | // Use this for a multithreaded server 15 | val server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor)) 16 | 17 | println("Starting the simple server...") 18 | server.serve(); 19 | } catch { 20 | case e: Throwable => e.printStackTrace() 21 | } 22 | } 23 | 24 | try { 25 | val handler = new GreeterHandler() 26 | val processor = new Greeter.Processor(handler) 27 | 28 | new Thread(new Runnable { 29 | override def run(): Unit = simple(processor) 30 | }).start(); 31 | 32 | } catch { 33 | case e: Throwable => 34 | e.printStackTrace() 35 | } 36 | } 37 | 38 | class GreeterHandler extends Greeter.Iface{ 39 | override def sayHello(name: String): String = "Hello" + name 40 | } -------------------------------------------------------------------------------- /thrift/scala/src/main/thrift/helloworld.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.colobu.rpctest 2 | 3 | service Greeter { 4 | 5 | string sayHello(1:string name); 6 | 7 | } -------------------------------------------------------------------------------- /thrift/scala/src/templates/bash-template: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ### ------------------------------- ### 4 | ### Helper methods for BASH scripts ### 5 | ### ------------------------------- ### 6 | 7 | die() { 8 | echo "$@" 1>&2 9 | exit 1 10 | } 11 | 12 | realpath () { 13 | ( 14 | TARGET_FILE="$1" 15 | CHECK_CYGWIN="$2" 16 | 17 | cd "$(dirname "$TARGET_FILE")" 18 | TARGET_FILE=$(basename "$TARGET_FILE") 19 | 20 | COUNT=0 21 | while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ] 22 | do 23 | TARGET_FILE=$(readlink "$TARGET_FILE") 24 | cd "$(dirname "$TARGET_FILE")" 25 | TARGET_FILE=$(basename "$TARGET_FILE") 26 | COUNT=$(($COUNT + 1)) 27 | done 28 | 29 | if [ "$TARGET_FILE" == "." -o "$TARGET_FILE" == ".." ]; then 30 | cd "$TARGET_FILE" 31 | TARGET_FILEPATH= 32 | else 33 | TARGET_FILEPATH=/$TARGET_FILE 34 | fi 35 | 36 | # make sure we grab the actual windows path, instead of cygwin's path. 37 | if [[ "x$CHECK_CYGWIN" == "x" ]]; then 38 | echo "$(pwd -P)/$TARGET_FILE" 39 | else 40 | echo $(cygwinpath "$(pwd -P)/$TARGET_FILE") 41 | fi 42 | ) 43 | } 44 | 45 | # TODO - Do we need to detect msys? 46 | 47 | # Uses uname to detect if we're in the odd cygwin environment. 48 | is_cygwin() { 49 | local os=$(uname -s) 50 | case "$os" in 51 | CYGWIN*) return 0 ;; 52 | *) return 1 ;; 53 | esac 54 | } 55 | 56 | # This can fix cygwin style /cygdrive paths so we get the 57 | # windows style paths. 58 | cygwinpath() { 59 | local file="$1" 60 | if is_cygwin; then 61 | echo $(cygpath -w $file) 62 | else 63 | echo $file 64 | fi 65 | } 66 | 67 | # Make something URI friendly 68 | make_url() { 69 | url="$1" 70 | local nospaces=${url// /%20} 71 | if is_cygwin; then 72 | echo "/${nospaces//\\//}" 73 | else 74 | echo "$nospaces" 75 | fi 76 | } 77 | 78 | # This crazy function reads in a vanilla "linux" classpath string (only : are separators, and all /), 79 | # and returns a classpath with windows style paths, and ; separators. 80 | fixCygwinClasspath() { 81 | OLDIFS=$IFS 82 | IFS=":" 83 | read -a classpath_members <<< "$1" 84 | declare -a fixed_members 85 | IFS=$OLDIFS 86 | for i in "${!classpath_members[@]}" 87 | do 88 | fixed_members[i]=$(realpath "${classpath_members[i]}" "fix") 89 | done 90 | IFS=";" 91 | echo "${fixed_members[*]}" 92 | IFS=$OLDIFS 93 | } 94 | 95 | # Fix the classpath we use for cygwin. 96 | fix_classpath() { 97 | cp="$1" 98 | if is_cygwin; then 99 | echo "$(fixCygwinClasspath "$cp;$app_conf")" 100 | else 101 | echo "$cp:$app_conf" 102 | fi 103 | } 104 | # Detect if we should use JAVA_HOME or just try PATH. 105 | get_java_cmd() { 106 | if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then 107 | echo "$JAVA_HOME/bin/java" 108 | else 109 | echo "java" 110 | fi 111 | } 112 | 113 | echoerr () { 114 | echo 1>&2 "$@" 115 | } 116 | vlog () { 117 | [[ $verbose || $debug ]] && echoerr "$@" 118 | } 119 | dlog () { 120 | [[ $debug ]] && echoerr "$@" 121 | } 122 | execRunner () { 123 | # print the arguments one to a line, quoting any containing spaces 124 | [[ $verbose || $debug ]] && echo "# Executing command line:" && { 125 | for arg; do 126 | if printf "%s\n" "$arg" | grep -q ' '; then 127 | printf "\"%s\"\n" "$arg" 128 | else 129 | printf "%s\n" "$arg" 130 | fi 131 | done 132 | echo "" 133 | } 134 | 135 | # we use "exec" here for our pids to be accurate. 136 | exec "$@" 137 | } 138 | addJava () { 139 | dlog "[addJava] arg = '$1'" 140 | java_args+=( "$1" ) 141 | } 142 | addApp () { 143 | dlog "[addApp] arg = '$1'" 144 | app_commands+=( "$1" ) 145 | } 146 | addResidual () { 147 | dlog "[residual] arg = '$1'" 148 | residual_args+=( "$1" ) 149 | } 150 | addDebugger () { 151 | addJava "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$1" 152 | } 153 | 154 | require_arg () { 155 | local type="$1" 156 | local opt="$2" 157 | local arg="$3" 158 | if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then 159 | die "$opt requires <$type> argument" 160 | fi 161 | } 162 | is_function_defined() { 163 | declare -f "$1" > /dev/null 164 | } 165 | 166 | # Attempt to detect if the script is running via a GUI or not 167 | # TODO - Determine where/how we use this generically 168 | detect_terminal_for_ui() { 169 | [[ ! -t 0 ]] && [[ "${#residual_args}" == "0" ]] && { 170 | echo "true" 171 | } 172 | # SPECIAL TEST FOR MAC 173 | [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]] && [[ "${#residual_args}" == "0" ]] && { 174 | echo "true" 175 | } 176 | } 177 | 178 | # Processes incoming arguments and places them in appropriate global variables. called by the run method. 179 | process_args () { 180 | local no_more_snp_opts=0 181 | while [[ $# -gt 0 ]]; do 182 | case "$1" in 183 | --) shift && no_more_snp_opts=1 && break ;; 184 | -h|-help) usage; exit 1 ;; 185 | -v|-verbose) verbose=1 && shift ;; 186 | -d|-debug) debug=1 && shift ;; 187 | 188 | -no-version-check) no_version_check=1 && shift ;; 189 | 190 | -mem) echo "!! WARNING !! -mem option is ignored. Please use -J-Xmx and -J-Xms" && shift 2 ;; 191 | -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; 192 | 193 | -main) custom_mainclass="$2" && shift 2 ;; 194 | 195 | -java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;; 196 | 197 | -D*|-agentlib*) addJava "$1" && shift ;; 198 | -J*) addJava "${1:2}" && shift ;; 199 | *) addResidual "$1" && shift ;; 200 | esac 201 | done 202 | 203 | if [[ no_more_snp_opts ]]; then 204 | while [[ $# -gt 0 ]]; do 205 | addResidual "$1" && shift 206 | done 207 | fi 208 | 209 | is_function_defined process_my_args && { 210 | myargs=("${residual_args[@]}") 211 | residual_args=() 212 | process_my_args "${myargs[@]}" 213 | } 214 | } 215 | 216 | # Actually runs the script. 217 | run() { 218 | # TODO - check for sane environment 219 | 220 | # process the combined args, then reset "$@" to the residuals 221 | process_args "$@" 222 | set -- "${residual_args[@]}" 223 | argumentCount=$# 224 | 225 | #check for jline terminal fixes on cygwin 226 | if is_cygwin; then 227 | stty -icanon min 1 -echo > /dev/null 2>&1 228 | addJava "-Djline.terminal=jline.UnixTerminal" 229 | addJava "-Dsbt.cygwin=true" 230 | fi 231 | 232 | # check java version 233 | if [[ ! $no_version_check ]]; then 234 | java_version_check 235 | fi 236 | 237 | if [ -n "$custom_mainclass" ]; then 238 | mainclass="$custom_mainclass" 239 | else 240 | mainclass="$app_mainclass" 241 | fi 242 | 243 | # Now we check to see if there are any java opts on the environment. These get listed first, with the script able to override them. 244 | if [[ "$JAVA_OPTS" != "" ]]; then 245 | java_opts="${JAVA_OPTS}" 246 | fi 247 | 248 | # run sbt 249 | execRunner "$java_cmd" \ 250 | ${java_opts[@]} \ 251 | "${java_args[@]}" \ 252 | -cp "$(fix_classpath "$app_classpath")" \ 253 | $mainclass \ 254 | "${app_commands[@]}" \ 255 | "${residual_args[@]}" 256 | 257 | local exit_code=$? 258 | if is_cygwin; then 259 | stty icanon echo > /dev/null 2>&1 260 | fi 261 | exit $exit_code 262 | } 263 | 264 | # Loads a configuration file full of default command line options for this script. 265 | loadConfigFile() { 266 | cat "$1" | sed '/^\#/d' 267 | } 268 | 269 | # Now check to see if it's a good enough version 270 | # TODO - Check to see if we have a configured default java version, otherwise use 1.6 271 | java_version_check() { 272 | readonly java_version=$("$java_cmd" -version 2>&1 | awk -F '"' '/version/ {print $2}') 273 | if [[ "$java_version" == "" ]]; then 274 | echo 275 | echo No java installations was detected. 276 | echo Please go to http://www.java.com/getjava/ and download 277 | echo 278 | exit 1 279 | elif [[ ! "$java_version" > "1.6" ]]; then 280 | echo 281 | echo The java installation you have is not up to date 282 | echo $app_name requires at least version 1.6+, you have 283 | echo version $java_version 284 | echo 285 | echo Please go to http://www.java.com/getjava/ and download 286 | echo a valid Java Runtime and install before running $app_name. 287 | echo 288 | exit 1 289 | fi 290 | } 291 | 292 | ### ------------------------------- ### 293 | ### Start of customized settings ### 294 | ### ------------------------------- ### 295 | usage() { 296 | cat < Define a custom main class 304 | -jvm-debug Turn on JVM debugging, open at the given port. 305 | 306 | # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) 307 | -java-home alternate JAVA_HOME 308 | 309 | # jvm options and output control 310 | JAVA_OPTS environment variable, if unset uses "$java_opts" 311 | -Dkey=val pass -Dkey=val directly to the java runtime 312 | -J-X pass option -X directly to the java runtime 313 | (-J is stripped) 314 | 315 | # special option 316 | -- To stop parsing built-in commands from the rest of the command-line. 317 | e.g.) enabling debug and sending -d as app argument 318 | \$ ./start-script -d -- -d 319 | 320 | In the case of duplicated or conflicting options, basically the order above 321 | shows precedence: JAVA_OPTS lowest, command line options highest except "--". 322 | EOM 323 | } 324 | 325 | ### ------------------------------- ### 326 | ### Main script ### 327 | ### ------------------------------- ### 328 | 329 | declare -a residual_args 330 | declare -a java_args 331 | declare -a app_commands 332 | declare -r real_script_path="$(realpath "$0")" 333 | declare -r app_home="$(realpath "$(dirname "$real_script_path")")" 334 | declare -r app_conf="$(realpath "${app_home}/../conf")" 335 | # TODO - Check whether this is ok in cygwin... 336 | declare -r lib_dir="$(realpath "${app_home}/../lib")" 337 | ${{template_declares}} 338 | # java_cmd is overrode in process_args when -java-home is used 339 | declare java_cmd=$(get_java_cmd) 340 | 341 | [ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xms12G -Xmx12G -Xss1M -XX:+UseParallelGC -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps " 342 | 343 | if [ -n "$APP_CONFIG" ]; then 344 | JAVA_OPTS="$JAVA_OPTS -Dconfig.file=$APP_CONFIG" 345 | fi 346 | if [ -n "$LOGBACK_CONFIG" ]; then 347 | JAVA_OPTS="$JAVA_OPTS -Dlogback.configurationFile=$LOGBACK_CONFIG" 348 | fi 349 | 350 | # if configuration files exist, prepend their contents to $@ so it can be processed by this runner 351 | [[ -f "$script_conf_file" ]] && set -- $(loadConfigFile "$script_conf_file") "$@" 352 | 353 | run "$@" 354 | -------------------------------------------------------------------------------- /thrift/scala/src/universal/conf/application.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smallnest/RPC-TEST/eace9e69b2d12d1c244402ad0740611feebd11ff/thrift/scala/src/universal/conf/application.conf --------------------------------------------------------------------------------