summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-09 12:06:22 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-09 12:06:22 +0200
commit45622f6c0d98c4b21375374cd748bae8e0ca1daf (patch)
tree6c17df1c573665fcaf65559be00df5c2f9957644 /same
parentc32ccdc6cffb47f4f3fe945404c4e8bd8fe3ff3e (diff)
Add (non-Android) protobuf benchmark code.
Diffstat (limited to 'same')
-rw-r--r--same/pom.xml5
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/ClientBenchmark.java83
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/Example.java643
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/Example.proto13
-rw-r--r--same/src/main/java/com/orbekk/same/benchmark/ExampleServer.java42
5 files changed, 786 insertions, 0 deletions
diff --git a/same/pom.xml b/same/pom.xml
index 2081a1e..5462491 100644
--- a/same/pom.xml
+++ b/same/pom.xml
@@ -87,6 +87,11 @@
<version>1.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.orbekk</groupId>
+ <artifactId>protobuf-simple-rpc</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/same/src/main/java/com/orbekk/same/benchmark/ClientBenchmark.java b/same/src/main/java/com/orbekk/same/benchmark/ClientBenchmark.java
new file mode 100644
index 0000000..ea23979
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/ClientBenchmark.java
@@ -0,0 +1,83 @@
+package com.orbekk.same.benchmark;
+
+import java.util.concurrent.CountDownLatch;
+
+import com.google.protobuf.RpcCallback;
+import com.orbekk.protobuf.Rpc;
+import com.orbekk.protobuf.RpcChannel;
+import com.orbekk.same.benchmark.Example.Data;
+
+public class ClientBenchmark {
+ private final Example.Service service;
+ private final int warmupIterations;
+ private final int iterations;
+
+ public static void benchmark(String host, int port, int warmupIterations,
+ int iterations) throws InterruptedException {
+ RpcChannel channel = null;
+ try {
+ channel = RpcChannel.create(host, port);
+ Example.Service service = Example.Service.newStub(channel);
+ ClientBenchmark benchmark = new ClientBenchmark(
+ service, warmupIterations, iterations);
+ benchmark.benchmark();
+ } finally {
+ if (channel != null) {
+ channel.close();
+ }
+ }
+ }
+
+ public ClientBenchmark(Example.Service service,
+ int warmupIterations, int iterations) {
+ this.service = service;
+ this.warmupIterations = warmupIterations;
+ this.iterations = iterations;
+ }
+
+ private void runBenchmark(int iterations) throws InterruptedException {
+ final CountDownLatch finished =
+ new CountDownLatch(iterations);
+
+ for (int i = 0; i < iterations; i++) {
+ Example.Data request = Example.Data.newBuilder()
+ .setArg1(i).build();
+ Rpc rpc = new Rpc();
+ service.methodA(rpc, request, new RpcCallback<Example.Data>() {
+ @Override
+ public void run(Data ignored) {
+ finished.countDown();
+ }
+ });
+ }
+
+ finished.await();
+ }
+
+ public void benchmark() throws InterruptedException {
+ long warmupStart = System.currentTimeMillis();
+ runBenchmark(warmupIterations);
+ long warmupFinished = System.currentTimeMillis();
+ System.out.println("Warmup: " + warmupIterations + " in " +
+ (warmupFinished - warmupStart) + "ms. ");
+ long start = System.currentTimeMillis();
+ runBenchmark(iterations);
+ long finished = System.currentTimeMillis();
+ System.out.println("Benchmark: " + iterations+ " in " +
+ (finished - start) + "ms. ");
+ }
+
+ public static void main(String[] args) {
+ if (args.length < 2) {
+ System.err.println("Usage: ClientBenchmark <host> <port>");
+ System.exit(1);
+ }
+ String host = args[0];
+ int port = Integer.valueOf(args[1]);
+ try {
+ benchmark(host, port, 1000, 10000);
+ } catch (InterruptedException e) {
+ System.out.println("Benchmark failed.");
+ }
+ }
+}
diff --git a/same/src/main/java/com/orbekk/same/benchmark/Example.java b/same/src/main/java/com/orbekk/same/benchmark/Example.java
new file mode 100644
index 0000000..c71ed0a
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/Example.java
@@ -0,0 +1,643 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: src/main/java/com/orbekk/same/benchmark/Example.proto
+
+package com.orbekk.same.benchmark;
+
+public final class Example {
+ private Example() {}
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistry registry) {
+ }
+ public static final class Data extends
+ com.google.protobuf.GeneratedMessage {
+ // Use Data.newBuilder() to construct.
+ private Data() {
+ initFields();
+ }
+ private Data(boolean noInit) {}
+
+ private static final Data defaultInstance;
+ public static Data getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public Data getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.orbekk.same.benchmark.Example.internal_static_com_orbekk_same_benchmark_Data_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.orbekk.same.benchmark.Example.internal_static_com_orbekk_same_benchmark_Data_fieldAccessorTable;
+ }
+
+ // optional string message = 1;
+ public static final int MESSAGE_FIELD_NUMBER = 1;
+ private boolean hasMessage;
+ private java.lang.String message_ = "";
+ public boolean hasMessage() { return hasMessage; }
+ public java.lang.String getMessage() { return message_; }
+
+ // optional int32 arg1 = 2;
+ public static final int ARG1_FIELD_NUMBER = 2;
+ private boolean hasArg1;
+ private int arg1_ = 0;
+ public boolean hasArg1() { return hasArg1; }
+ public int getArg1() { return arg1_; }
+
+ // optional int32 arg2 = 3;
+ public static final int ARG2_FIELD_NUMBER = 3;
+ private boolean hasArg2;
+ private int arg2_ = 0;
+ public boolean hasArg2() { return hasArg2; }
+ public int getArg2() { return arg2_; }
+
+ private void initFields() {
+ }
+ public final boolean isInitialized() {
+ return true;
+ }
+
+ public void writeTo(com.google.protobuf.CodedOutputStream output)
+ throws java.io.IOException {
+ getSerializedSize();
+ if (hasMessage()) {
+ output.writeString(1, getMessage());
+ }
+ if (hasArg1()) {
+ output.writeInt32(2, getArg1());
+ }
+ if (hasArg2()) {
+ output.writeInt32(3, getArg2());
+ }
+ getUnknownFields().writeTo(output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (hasMessage()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeStringSize(1, getMessage());
+ }
+ if (hasArg1()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(2, getArg1());
+ }
+ if (hasArg2()) {
+ size += com.google.protobuf.CodedOutputStream
+ .computeInt32Size(3, getArg2());
+ }
+ size += getUnknownFields().getSerializedSize();
+ memoizedSerializedSize = size;
+ return size;
+ }
+
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ Builder builder = newBuilder();
+ if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+ return builder.buildParsed();
+ } else {
+ return null;
+ }
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input).buildParsed();
+ }
+ public static com.orbekk.same.benchmark.Example.Data parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return newBuilder().mergeFrom(input, extensionRegistry)
+ .buildParsed();
+ }
+
+ public static Builder newBuilder() { return Builder.create(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.orbekk.same.benchmark.Example.Data prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder> {
+ private com.orbekk.same.benchmark.Example.Data result;
+
+ // Construct using com.orbekk.same.benchmark.Example.Data.newBuilder()
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new com.orbekk.same.benchmark.Example.Data();
+ return builder;
+ }
+
+ protected com.orbekk.same.benchmark.Example.Data internalGetResult() {
+ return result;
+ }
+
+ public Builder clear() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "Cannot call clear() after build().");
+ }
+ result = new com.orbekk.same.benchmark.Example.Data();
+ return this;
+ }
+
+ public Builder clone() {
+ return create().mergeFrom(result);
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.orbekk.same.benchmark.Example.Data.getDescriptor();
+ }
+
+ public com.orbekk.same.benchmark.Example.Data getDefaultInstanceForType() {
+ return com.orbekk.same.benchmark.Example.Data.getDefaultInstance();
+ }
+
+ public boolean isInitialized() {
+ return result.isInitialized();
+ }
+ public com.orbekk.same.benchmark.Example.Data build() {
+ if (result != null && !isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return buildPartial();
+ }
+
+ private com.orbekk.same.benchmark.Example.Data buildParsed()
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ result).asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ public com.orbekk.same.benchmark.Example.Data buildPartial() {
+ if (result == null) {
+ throw new IllegalStateException(
+ "build() has already been called on this Builder.");
+ }
+ com.orbekk.same.benchmark.Example.Data returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public Builder mergeFrom(com.google.protobuf.Message other) {
+ if (other instanceof com.orbekk.same.benchmark.Example.Data) {
+ return mergeFrom((com.orbekk.same.benchmark.Example.Data)other);
+ } else {
+ super.mergeFrom(other);
+ return this;
+ }
+ }
+
+ public Builder mergeFrom(com.orbekk.same.benchmark.Example.Data other) {
+ if (other == com.orbekk.same.benchmark.Example.Data.getDefaultInstance()) return this;
+ if (other.hasMessage()) {
+ setMessage(other.getMessage());
+ }
+ if (other.hasArg1()) {
+ setArg1(other.getArg1());
+ }
+ if (other.hasArg2()) {
+ setArg2(other.getArg2());
+ }
+ this.mergeUnknownFields(other.getUnknownFields());
+ return this;
+ }
+
+ public Builder mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+ com.google.protobuf.UnknownFieldSet.newBuilder(
+ this.getUnknownFields());
+ while (true) {
+ int tag = input.readTag();
+ switch (tag) {
+ case 0:
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ default: {
+ if (!parseUnknownField(input, unknownFields,
+ extensionRegistry, tag)) {
+ this.setUnknownFields(unknownFields.build());
+ return this;
+ }
+ break;
+ }
+ case 10: {
+ setMessage(input.readString());
+ break;
+ }
+ case 16: {
+ setArg1(input.readInt32());
+ break;
+ }
+ case 24: {
+ setArg2(input.readInt32());
+ break;
+ }
+ }
+ }
+ }
+
+
+ // optional string message = 1;
+ public boolean hasMessage() {
+ return result.hasMessage();
+ }
+ public java.lang.String getMessage() {
+ return result.getMessage();
+ }
+ public Builder setMessage(java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ result.hasMessage = true;
+ result.message_ = value;
+ return this;
+ }
+ public Builder clearMessage() {
+ result.hasMessage = false;
+ result.message_ = getDefaultInstance().getMessage();
+ return this;
+ }
+
+ // optional int32 arg1 = 2;
+ public boolean hasArg1() {
+ return result.hasArg1();
+ }
+ public int getArg1() {
+ return result.getArg1();
+ }
+ public Builder setArg1(int value) {
+ result.hasArg1 = true;
+ result.arg1_ = value;
+ return this;
+ }
+ public Builder clearArg1() {
+ result.hasArg1 = false;
+ result.arg1_ = 0;
+ return this;
+ }
+
+ // optional int32 arg2 = 3;
+ public boolean hasArg2() {
+ return result.hasArg2();
+ }
+ public int getArg2() {
+ return result.getArg2();
+ }
+ public Builder setArg2(int value) {
+ result.hasArg2 = true;
+ result.arg2_ = value;
+ return this;
+ }
+ public Builder clearArg2() {
+ result.hasArg2 = false;
+ result.arg2_ = 0;
+ return this;
+ }
+
+ // @@protoc_insertion_point(builder_scope:com.orbekk.same.benchmark.Data)
+ }
+
+ static {
+ defaultInstance = new Data(true);
+ com.orbekk.same.benchmark.Example.internalForceInit();
+ defaultInstance.initFields();
+ }
+
+ // @@protoc_insertion_point(class_scope:com.orbekk.same.benchmark.Data)
+ }
+
+ public static abstract class Service
+ implements com.google.protobuf.Service {
+ protected Service() {}
+
+ public interface Interface {
+ public abstract void methodA(
+ com.google.protobuf.RpcController controller,
+ com.orbekk.same.benchmark.Example.Data request,
+ com.google.protobuf.RpcCallback<com.orbekk.same.benchmark.Example.Data> done);
+
+ }
+
+ public static com.google.protobuf.Service newReflectiveService(
+ final Interface impl) {
+ return new Service() {
+ @Override
+ public void methodA(
+ com.google.protobuf.RpcController controller,
+ com.orbekk.same.benchmark.Example.Data request,
+ com.google.protobuf.RpcCallback<com.orbekk.same.benchmark.Example.Data> done) {
+ impl.methodA(controller, request, done);
+ }
+
+ };
+ }
+
+ public static com.google.protobuf.BlockingService
+ newReflectiveBlockingService(final BlockingInterface impl) {
+ return new com.google.protobuf.BlockingService() {
+ public final com.google.protobuf.Descriptors.ServiceDescriptor
+ getDescriptorForType() {
+ return getDescriptor();
+ }
+
+ public final com.google.protobuf.Message callBlockingMethod(
+ com.google.protobuf.Descriptors.MethodDescriptor method,
+ com.google.protobuf.RpcController controller,
+ com.google.protobuf.Message request)
+ throws com.google.protobuf.ServiceException {
+ if (method.getService() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "Service.callBlockingMethod() given method descriptor for " +
+ "wrong service type.");
+ }
+ switch(method.getIndex()) {
+ case 0:
+ return impl.methodA(controller, (com.orbekk.same.benchmark.Example.Data)request);
+ default:
+ throw new java.lang.AssertionError("Can't get here.");
+ }
+ }
+
+ public final com.google.protobuf.Message
+ getRequestPrototype(
+ com.google.protobuf.Descriptors.MethodDescriptor method) {
+ if (method.getService() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "Service.getRequestPrototype() given method " +
+ "descriptor for wrong service type.");
+ }
+ switch(method.getIndex()) {
+ case 0:
+ return com.orbekk.same.benchmark.Example.Data.getDefaultInstance();
+ default:
+ throw new java.lang.AssertionError("Can't get here.");
+ }
+ }
+
+ public final com.google.protobuf.Message
+ getResponsePrototype(
+ com.google.protobuf.Descriptors.MethodDescriptor method) {
+ if (method.getService() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "Service.getResponsePrototype() given method " +
+ "descriptor for wrong service type.");
+ }
+ switch(method.getIndex()) {
+ case 0:
+ return com.orbekk.same.benchmark.Example.Data.getDefaultInstance();
+ default:
+ throw new java.lang.AssertionError("Can't get here.");
+ }
+ }
+
+ };
+ }
+
+ public abstract void methodA(
+ com.google.protobuf.RpcController controller,
+ com.orbekk.same.benchmark.Example.Data request,
+ com.google.protobuf.RpcCallback<com.orbekk.same.benchmark.Example.Data> done);
+
+ public static final
+ com.google.protobuf.Descriptors.ServiceDescriptor
+ getDescriptor() {
+ return com.orbekk.same.benchmark.Example.getDescriptor().getServices().get(0);
+ }
+ public final com.google.protobuf.Descriptors.ServiceDescriptor
+ getDescriptorForType() {
+ return getDescriptor();
+ }
+
+ public final void callMethod(
+ com.google.protobuf.Descriptors.MethodDescriptor method,
+ com.google.protobuf.RpcController controller,
+ com.google.protobuf.Message request,
+ com.google.protobuf.RpcCallback<
+ com.google.protobuf.Message> done) {
+ if (method.getService() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "Service.callMethod() given method descriptor for wrong " +
+ "service type.");
+ }
+ switch(method.getIndex()) {
+ case 0:
+ this.methodA(controller, (com.orbekk.same.benchmark.Example.Data)request,
+ com.google.protobuf.RpcUtil.<com.orbekk.same.benchmark.Example.Data>specializeCallback(
+ done));
+ return;
+ default:
+ throw new java.lang.AssertionError("Can't get here.");
+ }
+ }
+
+ public final com.google.protobuf.Message
+ getRequestPrototype(
+ com.google.protobuf.Descriptors.MethodDescriptor method) {
+ if (method.getService() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "Service.getRequestPrototype() given method " +
+ "descriptor for wrong service type.");
+ }
+ switch(method.getIndex()) {
+ case 0:
+ return com.orbekk.same.benchmark.Example.Data.getDefaultInstance();
+ default:
+ throw new java.lang.AssertionError("Can't get here.");
+ }
+ }
+
+ public final com.google.protobuf.Message
+ getResponsePrototype(
+ com.google.protobuf.Descriptors.MethodDescriptor method) {
+ if (method.getService() != getDescriptor()) {
+ throw new java.lang.IllegalArgumentException(
+ "Service.getResponsePrototype() given method " +
+ "descriptor for wrong service type.");
+ }
+ switch(method.getIndex()) {
+ case 0:
+ return com.orbekk.same.benchmark.Example.Data.getDefaultInstance();
+ default:
+ throw new java.lang.AssertionError("Can't get here.");
+ }
+ }
+
+ public static Stub newStub(
+ com.google.protobuf.RpcChannel channel) {
+ return new Stub(channel);
+ }
+
+ public static final class Stub extends com.orbekk.same.benchmark.Example.Service implements Interface {
+ private Stub(com.google.protobuf.RpcChannel channel) {
+ this.channel = channel;
+ }
+
+ private final com.google.protobuf.RpcChannel channel;
+
+ public com.google.protobuf.RpcChannel getChannel() {
+ return channel;
+ }
+
+ public void methodA(
+ com.google.protobuf.RpcController controller,
+ com.orbekk.same.benchmark.Example.Data request,
+ com.google.protobuf.RpcCallback<com.orbekk.same.benchmark.Example.Data> done) {
+ channel.callMethod(
+ getDescriptor().getMethods().get(0),
+ controller,
+ request,
+ com.orbekk.same.benchmark.Example.Data.getDefaultInstance(),
+ com.google.protobuf.RpcUtil.generalizeCallback(
+ done,
+ com.orbekk.same.benchmark.Example.Data.class,
+ com.orbekk.same.benchmark.Example.Data.getDefaultInstance()));
+ }
+ }
+
+ public static BlockingInterface newBlockingStub(
+ com.google.protobuf.BlockingRpcChannel channel) {
+ return new BlockingStub(channel);
+ }
+
+ public interface BlockingInterface {
+ public com.orbekk.same.benchmark.Example.Data methodA(
+ com.google.protobuf.RpcController controller,
+ com.orbekk.same.benchmark.Example.Data request)
+ throws com.google.protobuf.ServiceException;
+ }
+
+ private static final class BlockingStub implements BlockingInterface {
+ private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {
+ this.channel = channel;
+ }
+
+ private final com.google.protobuf.BlockingRpcChannel channel;
+
+ public com.orbekk.same.benchmark.Example.Data methodA(
+ com.google.protobuf.RpcController controller,
+ com.orbekk.same.benchmark.Example.Data request)
+ throws com.google.protobuf.ServiceException {
+ return (com.orbekk.same.benchmark.Example.Data) channel.callBlockingMethod(
+ getDescriptor().getMethods().get(0),
+ controller,
+ request,
+ com.orbekk.same.benchmark.Example.Data.getDefaultInstance());
+ }
+
+ }
+ }
+
+ private static com.google.protobuf.Descriptors.Descriptor
+ internal_static_com_orbekk_same_benchmark_Data_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_com_orbekk_same_benchmark_Data_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor
+ getDescriptor() {
+ return descriptor;
+ }
+ private static com.google.protobuf.Descriptors.FileDescriptor
+ descriptor;
+ static {
+ java.lang.String[] descriptorData = {
+ "\n5src/main/java/com/orbekk/same/benchmar" +
+ "k/Example.proto\022\031com.orbekk.same.benchma" +
+ "rk\"3\n\004Data\022\017\n\007message\030\001 \001(\t\022\014\n\004arg1\030\002 \001(" +
+ "\005\022\014\n\004arg2\030\003 \001(\0052V\n\007Service\022K\n\007MethodA\022\037." +
+ "com.orbekk.same.benchmark.Data\032\037.com.orb" +
+ "ekk.same.benchmark.DataB\003\210\001\001"
+ };
+ com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+ new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
+ public com.google.protobuf.ExtensionRegistry assignDescriptors(
+ com.google.protobuf.Descriptors.FileDescriptor root) {
+ descriptor = root;
+ internal_static_com_orbekk_same_benchmark_Data_descriptor =
+ getDescriptor().getMessageTypes().get(0);
+ internal_static_com_orbekk_same_benchmark_Data_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_com_orbekk_same_benchmark_Data_descriptor,
+ new java.lang.String[] { "Message", "Arg1", "Arg2", },
+ com.orbekk.same.benchmark.Example.Data.class,
+ com.orbekk.same.benchmark.Example.Data.Builder.class);
+ return null;
+ }
+ };
+ com.google.protobuf.Descriptors.FileDescriptor
+ .internalBuildGeneratedFileFrom(descriptorData,
+ new com.google.protobuf.Descriptors.FileDescriptor[] {
+ }, assigner);
+ }
+
+ public static void internalForceInit() {}
+
+ // @@protoc_insertion_point(outer_class_scope)
+}
diff --git a/same/src/main/java/com/orbekk/same/benchmark/Example.proto b/same/src/main/java/com/orbekk/same/benchmark/Example.proto
new file mode 100644
index 0000000..1c74634
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/Example.proto
@@ -0,0 +1,13 @@
+package com.orbekk.same.benchmark;
+
+option java_generic_services = true;
+
+message Data {
+ optional string message = 1;
+ optional int32 arg1 = 2;
+ optional int32 arg2 = 3;
+}
+
+service Service {
+ rpc MethodA (Data) returns (Data);
+}
diff --git a/same/src/main/java/com/orbekk/same/benchmark/ExampleServer.java b/same/src/main/java/com/orbekk/same/benchmark/ExampleServer.java
new file mode 100644
index 0000000..9aa691d
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/benchmark/ExampleServer.java
@@ -0,0 +1,42 @@
+package com.orbekk.same.benchmark;
+
+import org.apache.log4j.Logger;
+
+import com.google.protobuf.RpcCallback;
+import com.google.protobuf.RpcController;
+import com.orbekk.protobuf.SimpleProtobufServer;
+import com.orbekk.same.benchmark.Example.Data;
+
+public class ExampleServer {
+ private final static Logger logger =
+ Logger.getLogger(ExampleServer.class);
+ private volatile SimpleProtobufServer server;
+
+ class ServiceImpl extends Example.Service {
+ @Override
+ public void methodA(RpcController controller, Data request, RpcCallback<Data> done) {
+ Data response = Data.newBuilder()
+ .setMessage(request.getMessage())
+ .setArg1(request.getArg1())
+ .setArg2(request.getArg2())
+ .build();
+ done.run(response);
+ }
+ }
+
+ public void runServer(int port) {
+ server = SimpleProtobufServer.create(port);
+ server.registerService(new ServiceImpl());
+ server.start();
+ logger.info("Running SimpleProtobufServer on port " + server.getPort());
+ }
+
+ public void stopServer() throws InterruptedException {
+ server.interrupt();
+ }
+
+ public static void main(String[] args) {
+ ExampleServer server = new ExampleServer();
+ server.runServer(12000);
+ }
+}