diff options
Diffstat (limited to 'src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java')
-rw-r--r-- | src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java b/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java index ffaedb0..b17c0bc 100644 --- a/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java +++ b/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java @@ -1,26 +1,35 @@ package com.orbekk.protobuf; -import java.net.Socket; -import java.net.UnknownHostException; -import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.logging.Logger; + +import com.google.protobuf.RpcCallback; public class SimpleProtobufClient { + static final Logger logger = + Logger.getLogger(SimpleProtobufClient.class.getName()); + public void run() { - try { - Socket socket = new Socket("localhost", 10000); - Rpc.Request r1 = Rpc.Request.newBuilder() - .setFullServiceName("com.orbekk.protobuf.TestService") - .setMethodName("Run") + RpcChannel channel = RpcChannel.create("localhost", 10000); + Test.TestService test = Test.TestService.newStub(channel); + Test.TestRequest request = Test.TestRequest.newBuilder() + .setId("Hello!") .build(); - Rpc.Request r2 = Rpc.Request.newBuilder() - .setFullServiceName("Service2") - .build(); - r1.writeDelimitedTo(socket.getOutputStream()); - r2.writeDelimitedTo(socket.getOutputStream()); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + int count = 10; + final CountDownLatch stop = new CountDownLatch(count); + for (int i = 0; i < count; i++) { + logger.info("Sending request."); + test.run(null, request, new RpcCallback<Test.TestResponse>() { + @Override public void run(Test.TestResponse response) { + System.out.println("Response from server: " + response); + stop.countDown(); + } + }); + } + try { + stop.await(); + } catch (InterruptedException e) { + // Stop waiting. } } |