blob: b17c0bc754c19596b401b082e568858031d6d83c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package com.orbekk.protobuf;
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() {
RpcChannel channel = RpcChannel.create("localhost", 10000);
Test.TestService test = Test.TestService.newStub(channel);
Test.TestRequest request = Test.TestRequest.newBuilder()
.setId("Hello!")
.build();
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.
}
}
public static void main(String[] args) {
new SimpleProtobufClient().run();
}
}
|