diff options
| author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-28 19:32:57 +0200 | 
|---|---|---|
| committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-03-28 19:32:57 +0200 | 
| commit | 46bf03f6f38284a85dc96a2e72688f1749750a6c (patch) | |
| tree | 9c6b52e9429b7e1717e782fef9caed9a384170d3 /src/main/java/com/orbekk | |
| parent | 8a1c8340be7151ba38eca59597b4eda04ebdcc9a (diff) | |
Handle failing RPCs.
– Handles RPCs that fail because the recipient calls setFailed().
– Handles RPCs that fail because the connection is closed.
Diffstat (limited to 'src/main/java/com/orbekk')
| -rw-r--r-- | src/main/java/com/orbekk/protobuf/Data.java | 1460 | ||||
| -rw-r--r-- | src/main/java/com/orbekk/protobuf/Data.proto (renamed from src/main/java/com/orbekk/protobuf/Rpc.proto) | 15 | ||||
| -rw-r--r-- | src/main/java/com/orbekk/protobuf/Rpc.java | 1393 | ||||
| -rw-r--r-- | src/main/java/com/orbekk/protobuf/RpcChannel.java | 57 | ||||
| -rw-r--r-- | src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java | 39 | ||||
| -rw-r--r-- | src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java | 91 | 
6 files changed, 1626 insertions, 1429 deletions
diff --git a/src/main/java/com/orbekk/protobuf/Data.java b/src/main/java/com/orbekk/protobuf/Data.java new file mode 100644 index 0000000..e0f364a --- /dev/null +++ b/src/main/java/com/orbekk/protobuf/Data.java @@ -0,0 +1,1460 @@ +// Generated by the protocol buffer compiler.  DO NOT EDIT! +// source: src/main/java/com/orbekk/protobuf/Data.proto + +package com.orbekk.protobuf; + +public final class Data { +  private Data() {} +  public static void registerAllExtensions( +      com.google.protobuf.ExtensionRegistry registry) { +  } +  public interface RequestOrBuilder +      extends com.google.protobuf.MessageOrBuilder { +     +    // optional string full_service_name = 1; +    boolean hasFullServiceName(); +    String getFullServiceName(); +     +    // optional string method_name = 2; +    boolean hasMethodName(); +    String getMethodName(); +     +    // optional bytes request_proto = 3; +    boolean hasRequestProto(); +    com.google.protobuf.ByteString getRequestProto(); +     +    // optional int64 request_id = 4; +    boolean hasRequestId(); +    long getRequestId(); +  } +  public static final class Request extends +      com.google.protobuf.GeneratedMessage +      implements RequestOrBuilder { +    // Use Request.newBuilder() to construct. +    private Request(Builder builder) { +      super(builder); +    } +    private Request(boolean noInit) {} +     +    private static final Request defaultInstance; +    public static Request getDefaultInstance() { +      return defaultInstance; +    } +     +    public Request getDefaultInstanceForType() { +      return defaultInstance; +    } +     +    public static final com.google.protobuf.Descriptors.Descriptor +        getDescriptor() { +      return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Request_descriptor; +    } +     +    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable +        internalGetFieldAccessorTable() { +      return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Request_fieldAccessorTable; +    } +     +    private int bitField0_; +    // optional string full_service_name = 1; +    public static final int FULL_SERVICE_NAME_FIELD_NUMBER = 1; +    private java.lang.Object fullServiceName_; +    public boolean hasFullServiceName() { +      return ((bitField0_ & 0x00000001) == 0x00000001); +    } +    public String getFullServiceName() { +      java.lang.Object ref = fullServiceName_; +      if (ref instanceof String) { +        return (String) ref; +      } else { +        com.google.protobuf.ByteString bs =  +            (com.google.protobuf.ByteString) ref; +        String s = bs.toStringUtf8(); +        if (com.google.protobuf.Internal.isValidUtf8(bs)) { +          fullServiceName_ = s; +        } +        return s; +      } +    } +    private com.google.protobuf.ByteString getFullServiceNameBytes() { +      java.lang.Object ref = fullServiceName_; +      if (ref instanceof String) { +        com.google.protobuf.ByteString b =  +            com.google.protobuf.ByteString.copyFromUtf8((String) ref); +        fullServiceName_ = b; +        return b; +      } else { +        return (com.google.protobuf.ByteString) ref; +      } +    } +     +    // optional string method_name = 2; +    public static final int METHOD_NAME_FIELD_NUMBER = 2; +    private java.lang.Object methodName_; +    public boolean hasMethodName() { +      return ((bitField0_ & 0x00000002) == 0x00000002); +    } +    public String getMethodName() { +      java.lang.Object ref = methodName_; +      if (ref instanceof String) { +        return (String) ref; +      } else { +        com.google.protobuf.ByteString bs =  +            (com.google.protobuf.ByteString) ref; +        String s = bs.toStringUtf8(); +        if (com.google.protobuf.Internal.isValidUtf8(bs)) { +          methodName_ = s; +        } +        return s; +      } +    } +    private com.google.protobuf.ByteString getMethodNameBytes() { +      java.lang.Object ref = methodName_; +      if (ref instanceof String) { +        com.google.protobuf.ByteString b =  +            com.google.protobuf.ByteString.copyFromUtf8((String) ref); +        methodName_ = b; +        return b; +      } else { +        return (com.google.protobuf.ByteString) ref; +      } +    } +     +    // optional bytes request_proto = 3; +    public static final int REQUEST_PROTO_FIELD_NUMBER = 3; +    private com.google.protobuf.ByteString requestProto_; +    public boolean hasRequestProto() { +      return ((bitField0_ & 0x00000004) == 0x00000004); +    } +    public com.google.protobuf.ByteString getRequestProto() { +      return requestProto_; +    } +     +    // optional int64 request_id = 4; +    public static final int REQUEST_ID_FIELD_NUMBER = 4; +    private long requestId_; +    public boolean hasRequestId() { +      return ((bitField0_ & 0x00000008) == 0x00000008); +    } +    public long getRequestId() { +      return requestId_; +    } +     +    private void initFields() { +      fullServiceName_ = ""; +      methodName_ = ""; +      requestProto_ = com.google.protobuf.ByteString.EMPTY; +      requestId_ = 0L; +    } +    private byte memoizedIsInitialized = -1; +    public final boolean isInitialized() { +      byte isInitialized = memoizedIsInitialized; +      if (isInitialized != -1) return isInitialized == 1; +       +      memoizedIsInitialized = 1; +      return true; +    } +     +    public void writeTo(com.google.protobuf.CodedOutputStream output) +                        throws java.io.IOException { +      getSerializedSize(); +      if (((bitField0_ & 0x00000001) == 0x00000001)) { +        output.writeBytes(1, getFullServiceNameBytes()); +      } +      if (((bitField0_ & 0x00000002) == 0x00000002)) { +        output.writeBytes(2, getMethodNameBytes()); +      } +      if (((bitField0_ & 0x00000004) == 0x00000004)) { +        output.writeBytes(3, requestProto_); +      } +      if (((bitField0_ & 0x00000008) == 0x00000008)) { +        output.writeInt64(4, requestId_); +      } +      getUnknownFields().writeTo(output); +    } +     +    private int memoizedSerializedSize = -1; +    public int getSerializedSize() { +      int size = memoizedSerializedSize; +      if (size != -1) return size; +     +      size = 0; +      if (((bitField0_ & 0x00000001) == 0x00000001)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBytesSize(1, getFullServiceNameBytes()); +      } +      if (((bitField0_ & 0x00000002) == 0x00000002)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBytesSize(2, getMethodNameBytes()); +      } +      if (((bitField0_ & 0x00000004) == 0x00000004)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBytesSize(3, requestProto_); +      } +      if (((bitField0_ & 0x00000008) == 0x00000008)) { +        size += com.google.protobuf.CodedOutputStream +          .computeInt64Size(4, requestId_); +      } +      size += getUnknownFields().getSerializedSize(); +      memoizedSerializedSize = size; +      return size; +    } +     +    private static final long serialVersionUID = 0L; +    @java.lang.Override +    protected java.lang.Object writeReplace() +        throws java.io.ObjectStreamException { +      return super.writeReplace(); +    } +     +    public static com.orbekk.protobuf.Data.Request parseFrom( +        com.google.protobuf.ByteString data) +        throws com.google.protobuf.InvalidProtocolBufferException { +      return newBuilder().mergeFrom(data).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Request 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.protobuf.Data.Request parseFrom(byte[] data) +        throws com.google.protobuf.InvalidProtocolBufferException { +      return newBuilder().mergeFrom(data).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Request parseFrom( +        byte[] data, +        com.google.protobuf.ExtensionRegistryLite extensionRegistry) +        throws com.google.protobuf.InvalidProtocolBufferException { +      return newBuilder().mergeFrom(data, extensionRegistry) +               .buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Request parseFrom(java.io.InputStream input) +        throws java.io.IOException { +      return newBuilder().mergeFrom(input).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Request parseFrom( +        java.io.InputStream input, +        com.google.protobuf.ExtensionRegistryLite extensionRegistry) +        throws java.io.IOException { +      return newBuilder().mergeFrom(input, extensionRegistry) +               .buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Request 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.protobuf.Data.Request 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.protobuf.Data.Request parseFrom( +        com.google.protobuf.CodedInputStream input) +        throws java.io.IOException { +      return newBuilder().mergeFrom(input).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Request 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.protobuf.Data.Request prototype) { +      return newBuilder().mergeFrom(prototype); +    } +    public Builder toBuilder() { return newBuilder(this); } +     +    @java.lang.Override +    protected Builder newBuilderForType( +        com.google.protobuf.GeneratedMessage.BuilderParent parent) { +      Builder builder = new Builder(parent); +      return builder; +    } +    public static final class Builder extends +        com.google.protobuf.GeneratedMessage.Builder<Builder> +       implements com.orbekk.protobuf.Data.RequestOrBuilder { +      public static final com.google.protobuf.Descriptors.Descriptor +          getDescriptor() { +        return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Request_descriptor; +      } +       +      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable +          internalGetFieldAccessorTable() { +        return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Request_fieldAccessorTable; +      } +       +      // Construct using com.orbekk.protobuf.Data.Request.newBuilder() +      private Builder() { +        maybeForceBuilderInitialization(); +      } +       +      private Builder(BuilderParent parent) { +        super(parent); +        maybeForceBuilderInitialization(); +      } +      private void maybeForceBuilderInitialization() { +        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { +        } +      } +      private static Builder create() { +        return new Builder(); +      } +       +      public Builder clear() { +        super.clear(); +        fullServiceName_ = ""; +        bitField0_ = (bitField0_ & ~0x00000001); +        methodName_ = ""; +        bitField0_ = (bitField0_ & ~0x00000002); +        requestProto_ = com.google.protobuf.ByteString.EMPTY; +        bitField0_ = (bitField0_ & ~0x00000004); +        requestId_ = 0L; +        bitField0_ = (bitField0_ & ~0x00000008); +        return this; +      } +       +      public Builder clone() { +        return create().mergeFrom(buildPartial()); +      } +       +      public com.google.protobuf.Descriptors.Descriptor +          getDescriptorForType() { +        return com.orbekk.protobuf.Data.Request.getDescriptor(); +      } +       +      public com.orbekk.protobuf.Data.Request getDefaultInstanceForType() { +        return com.orbekk.protobuf.Data.Request.getDefaultInstance(); +      } +       +      public com.orbekk.protobuf.Data.Request build() { +        com.orbekk.protobuf.Data.Request result = buildPartial(); +        if (!result.isInitialized()) { +          throw newUninitializedMessageException(result); +        } +        return result; +      } +       +      private com.orbekk.protobuf.Data.Request buildParsed() +          throws com.google.protobuf.InvalidProtocolBufferException { +        com.orbekk.protobuf.Data.Request result = buildPartial(); +        if (!result.isInitialized()) { +          throw newUninitializedMessageException( +            result).asInvalidProtocolBufferException(); +        } +        return result; +      } +       +      public com.orbekk.protobuf.Data.Request buildPartial() { +        com.orbekk.protobuf.Data.Request result = new com.orbekk.protobuf.Data.Request(this); +        int from_bitField0_ = bitField0_; +        int to_bitField0_ = 0; +        if (((from_bitField0_ & 0x00000001) == 0x00000001)) { +          to_bitField0_ |= 0x00000001; +        } +        result.fullServiceName_ = fullServiceName_; +        if (((from_bitField0_ & 0x00000002) == 0x00000002)) { +          to_bitField0_ |= 0x00000002; +        } +        result.methodName_ = methodName_; +        if (((from_bitField0_ & 0x00000004) == 0x00000004)) { +          to_bitField0_ |= 0x00000004; +        } +        result.requestProto_ = requestProto_; +        if (((from_bitField0_ & 0x00000008) == 0x00000008)) { +          to_bitField0_ |= 0x00000008; +        } +        result.requestId_ = requestId_; +        result.bitField0_ = to_bitField0_; +        onBuilt(); +        return result; +      } +       +      public Builder mergeFrom(com.google.protobuf.Message other) { +        if (other instanceof com.orbekk.protobuf.Data.Request) { +          return mergeFrom((com.orbekk.protobuf.Data.Request)other); +        } else { +          super.mergeFrom(other); +          return this; +        } +      } +       +      public Builder mergeFrom(com.orbekk.protobuf.Data.Request other) { +        if (other == com.orbekk.protobuf.Data.Request.getDefaultInstance()) return this; +        if (other.hasFullServiceName()) { +          setFullServiceName(other.getFullServiceName()); +        } +        if (other.hasMethodName()) { +          setMethodName(other.getMethodName()); +        } +        if (other.hasRequestProto()) { +          setRequestProto(other.getRequestProto()); +        } +        if (other.hasRequestId()) { +          setRequestId(other.getRequestId()); +        } +        this.mergeUnknownFields(other.getUnknownFields()); +        return this; +      } +       +      public final boolean isInitialized() { +        return true; +      } +       +      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()); +              onChanged(); +              return this; +            default: { +              if (!parseUnknownField(input, unknownFields, +                                     extensionRegistry, tag)) { +                this.setUnknownFields(unknownFields.build()); +                onChanged(); +                return this; +              } +              break; +            } +            case 10: { +              bitField0_ |= 0x00000001; +              fullServiceName_ = input.readBytes(); +              break; +            } +            case 18: { +              bitField0_ |= 0x00000002; +              methodName_ = input.readBytes(); +              break; +            } +            case 26: { +              bitField0_ |= 0x00000004; +              requestProto_ = input.readBytes(); +              break; +            } +            case 32: { +              bitField0_ |= 0x00000008; +              requestId_ = input.readInt64(); +              break; +            } +          } +        } +      } +       +      private int bitField0_; +       +      // optional string full_service_name = 1; +      private java.lang.Object fullServiceName_ = ""; +      public boolean hasFullServiceName() { +        return ((bitField0_ & 0x00000001) == 0x00000001); +      } +      public String getFullServiceName() { +        java.lang.Object ref = fullServiceName_; +        if (!(ref instanceof String)) { +          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); +          fullServiceName_ = s; +          return s; +        } else { +          return (String) ref; +        } +      } +      public Builder setFullServiceName(String value) { +        if (value == null) { +    throw new NullPointerException(); +  } +  bitField0_ |= 0x00000001; +        fullServiceName_ = value; +        onChanged(); +        return this; +      } +      public Builder clearFullServiceName() { +        bitField0_ = (bitField0_ & ~0x00000001); +        fullServiceName_ = getDefaultInstance().getFullServiceName(); +        onChanged(); +        return this; +      } +      void setFullServiceName(com.google.protobuf.ByteString value) { +        bitField0_ |= 0x00000001; +        fullServiceName_ = value; +        onChanged(); +      } +       +      // optional string method_name = 2; +      private java.lang.Object methodName_ = ""; +      public boolean hasMethodName() { +        return ((bitField0_ & 0x00000002) == 0x00000002); +      } +      public String getMethodName() { +        java.lang.Object ref = methodName_; +        if (!(ref instanceof String)) { +          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); +          methodName_ = s; +          return s; +        } else { +          return (String) ref; +        } +      } +      public Builder setMethodName(String value) { +        if (value == null) { +    throw new NullPointerException(); +  } +  bitField0_ |= 0x00000002; +        methodName_ = value; +        onChanged(); +        return this; +      } +      public Builder clearMethodName() { +        bitField0_ = (bitField0_ & ~0x00000002); +        methodName_ = getDefaultInstance().getMethodName(); +        onChanged(); +        return this; +      } +      void setMethodName(com.google.protobuf.ByteString value) { +        bitField0_ |= 0x00000002; +        methodName_ = value; +        onChanged(); +      } +       +      // optional bytes request_proto = 3; +      private com.google.protobuf.ByteString requestProto_ = com.google.protobuf.ByteString.EMPTY; +      public boolean hasRequestProto() { +        return ((bitField0_ & 0x00000004) == 0x00000004); +      } +      public com.google.protobuf.ByteString getRequestProto() { +        return requestProto_; +      } +      public Builder setRequestProto(com.google.protobuf.ByteString value) { +        if (value == null) { +    throw new NullPointerException(); +  } +  bitField0_ |= 0x00000004; +        requestProto_ = value; +        onChanged(); +        return this; +      } +      public Builder clearRequestProto() { +        bitField0_ = (bitField0_ & ~0x00000004); +        requestProto_ = getDefaultInstance().getRequestProto(); +        onChanged(); +        return this; +      } +       +      // optional int64 request_id = 4; +      private long requestId_ ; +      public boolean hasRequestId() { +        return ((bitField0_ & 0x00000008) == 0x00000008); +      } +      public long getRequestId() { +        return requestId_; +      } +      public Builder setRequestId(long value) { +        bitField0_ |= 0x00000008; +        requestId_ = value; +        onChanged(); +        return this; +      } +      public Builder clearRequestId() { +        bitField0_ = (bitField0_ & ~0x00000008); +        requestId_ = 0L; +        onChanged(); +        return this; +      } +       +      // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.Request) +    } +     +    static { +      defaultInstance = new Request(true); +      defaultInstance.initFields(); +    } +     +    // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.Request) +  } +   +  public interface ResponseOrBuilder +      extends com.google.protobuf.MessageOrBuilder { +     +    // optional bytes response_proto = 1; +    boolean hasResponseProto(); +    com.google.protobuf.ByteString getResponseProto(); +     +    // optional .com.orbekk.protobuf.Response.RpcError error = 2; +    boolean hasError(); +    com.orbekk.protobuf.Data.Response.RpcError getError(); +     +    // optional int64 request_id = 5; +    boolean hasRequestId(); +    long getRequestId(); +     +    // optional bool hasFailed = 4; +    boolean hasHasFailed(); +    boolean getHasFailed(); +     +    // optional bool canceled = 6; +    boolean hasCanceled(); +    boolean getCanceled(); +     +    // optional bool done = 7 [default = true]; +    boolean hasDone(); +    boolean getDone(); +     +    // optional string error_text = 3; +    boolean hasErrorText(); +    String getErrorText(); +  } +  public static final class Response extends +      com.google.protobuf.GeneratedMessage +      implements ResponseOrBuilder { +    // Use Response.newBuilder() to construct. +    private Response(Builder builder) { +      super(builder); +    } +    private Response(boolean noInit) {} +     +    private static final Response defaultInstance; +    public static Response getDefaultInstance() { +      return defaultInstance; +    } +     +    public Response getDefaultInstanceForType() { +      return defaultInstance; +    } +     +    public static final com.google.protobuf.Descriptors.Descriptor +        getDescriptor() { +      return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Response_descriptor; +    } +     +    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable +        internalGetFieldAccessorTable() { +      return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Response_fieldAccessorTable; +    } +     +    public enum RpcError +        implements com.google.protobuf.ProtocolMessageEnum { +      UNKNOWN_SERVICE(0, 0), +      UNKNOWN_METHOD(1, 1), +      CANCELED(2, 2), +      ; +       +      public static final int UNKNOWN_SERVICE_VALUE = 0; +      public static final int UNKNOWN_METHOD_VALUE = 1; +      public static final int CANCELED_VALUE = 2; +       +       +      public final int getNumber() { return value; } +       +      public static RpcError valueOf(int value) { +        switch (value) { +          case 0: return UNKNOWN_SERVICE; +          case 1: return UNKNOWN_METHOD; +          case 2: return CANCELED; +          default: return null; +        } +      } +       +      public static com.google.protobuf.Internal.EnumLiteMap<RpcError> +          internalGetValueMap() { +        return internalValueMap; +      } +      private static com.google.protobuf.Internal.EnumLiteMap<RpcError> +          internalValueMap = +            new com.google.protobuf.Internal.EnumLiteMap<RpcError>() { +              public RpcError findValueByNumber(int number) { +                return RpcError.valueOf(number); +              } +            }; +       +      public final com.google.protobuf.Descriptors.EnumValueDescriptor +          getValueDescriptor() { +        return getDescriptor().getValues().get(index); +      } +      public final com.google.protobuf.Descriptors.EnumDescriptor +          getDescriptorForType() { +        return getDescriptor(); +      } +      public static final com.google.protobuf.Descriptors.EnumDescriptor +          getDescriptor() { +        return com.orbekk.protobuf.Data.Response.getDescriptor().getEnumTypes().get(0); +      } +       +      private static final RpcError[] VALUES = { +        UNKNOWN_SERVICE, UNKNOWN_METHOD, CANCELED,  +      }; +       +      public static RpcError valueOf( +          com.google.protobuf.Descriptors.EnumValueDescriptor desc) { +        if (desc.getType() != getDescriptor()) { +          throw new java.lang.IllegalArgumentException( +            "EnumValueDescriptor is not for this type."); +        } +        return VALUES[desc.getIndex()]; +      } +       +      private final int index; +      private final int value; +       +      private RpcError(int index, int value) { +        this.index = index; +        this.value = value; +      } +       +      // @@protoc_insertion_point(enum_scope:com.orbekk.protobuf.Response.RpcError) +    } +     +    private int bitField0_; +    // optional bytes response_proto = 1; +    public static final int RESPONSE_PROTO_FIELD_NUMBER = 1; +    private com.google.protobuf.ByteString responseProto_; +    public boolean hasResponseProto() { +      return ((bitField0_ & 0x00000001) == 0x00000001); +    } +    public com.google.protobuf.ByteString getResponseProto() { +      return responseProto_; +    } +     +    // optional .com.orbekk.protobuf.Response.RpcError error = 2; +    public static final int ERROR_FIELD_NUMBER = 2; +    private com.orbekk.protobuf.Data.Response.RpcError error_; +    public boolean hasError() { +      return ((bitField0_ & 0x00000002) == 0x00000002); +    } +    public com.orbekk.protobuf.Data.Response.RpcError getError() { +      return error_; +    } +     +    // optional int64 request_id = 5; +    public static final int REQUEST_ID_FIELD_NUMBER = 5; +    private long requestId_; +    public boolean hasRequestId() { +      return ((bitField0_ & 0x00000004) == 0x00000004); +    } +    public long getRequestId() { +      return requestId_; +    } +     +    // optional bool hasFailed = 4; +    public static final int HASFAILED_FIELD_NUMBER = 4; +    private boolean hasFailed_; +    public boolean hasHasFailed() { +      return ((bitField0_ & 0x00000008) == 0x00000008); +    } +    public boolean getHasFailed() { +      return hasFailed_; +    } +     +    // optional bool canceled = 6; +    public static final int CANCELED_FIELD_NUMBER = 6; +    private boolean canceled_; +    public boolean hasCanceled() { +      return ((bitField0_ & 0x00000010) == 0x00000010); +    } +    public boolean getCanceled() { +      return canceled_; +    } +     +    // optional bool done = 7 [default = true]; +    public static final int DONE_FIELD_NUMBER = 7; +    private boolean done_; +    public boolean hasDone() { +      return ((bitField0_ & 0x00000020) == 0x00000020); +    } +    public boolean getDone() { +      return done_; +    } +     +    // optional string error_text = 3; +    public static final int ERROR_TEXT_FIELD_NUMBER = 3; +    private java.lang.Object errorText_; +    public boolean hasErrorText() { +      return ((bitField0_ & 0x00000040) == 0x00000040); +    } +    public String getErrorText() { +      java.lang.Object ref = errorText_; +      if (ref instanceof String) { +        return (String) ref; +      } else { +        com.google.protobuf.ByteString bs =  +            (com.google.protobuf.ByteString) ref; +        String s = bs.toStringUtf8(); +        if (com.google.protobuf.Internal.isValidUtf8(bs)) { +          errorText_ = s; +        } +        return s; +      } +    } +    private com.google.protobuf.ByteString getErrorTextBytes() { +      java.lang.Object ref = errorText_; +      if (ref instanceof String) { +        com.google.protobuf.ByteString b =  +            com.google.protobuf.ByteString.copyFromUtf8((String) ref); +        errorText_ = b; +        return b; +      } else { +        return (com.google.protobuf.ByteString) ref; +      } +    } +     +    private void initFields() { +      responseProto_ = com.google.protobuf.ByteString.EMPTY; +      error_ = com.orbekk.protobuf.Data.Response.RpcError.UNKNOWN_SERVICE; +      requestId_ = 0L; +      hasFailed_ = false; +      canceled_ = false; +      done_ = true; +      errorText_ = ""; +    } +    private byte memoizedIsInitialized = -1; +    public final boolean isInitialized() { +      byte isInitialized = memoizedIsInitialized; +      if (isInitialized != -1) return isInitialized == 1; +       +      memoizedIsInitialized = 1; +      return true; +    } +     +    public void writeTo(com.google.protobuf.CodedOutputStream output) +                        throws java.io.IOException { +      getSerializedSize(); +      if (((bitField0_ & 0x00000001) == 0x00000001)) { +        output.writeBytes(1, responseProto_); +      } +      if (((bitField0_ & 0x00000002) == 0x00000002)) { +        output.writeEnum(2, error_.getNumber()); +      } +      if (((bitField0_ & 0x00000040) == 0x00000040)) { +        output.writeBytes(3, getErrorTextBytes()); +      } +      if (((bitField0_ & 0x00000008) == 0x00000008)) { +        output.writeBool(4, hasFailed_); +      } +      if (((bitField0_ & 0x00000004) == 0x00000004)) { +        output.writeInt64(5, requestId_); +      } +      if (((bitField0_ & 0x00000010) == 0x00000010)) { +        output.writeBool(6, canceled_); +      } +      if (((bitField0_ & 0x00000020) == 0x00000020)) { +        output.writeBool(7, done_); +      } +      getUnknownFields().writeTo(output); +    } +     +    private int memoizedSerializedSize = -1; +    public int getSerializedSize() { +      int size = memoizedSerializedSize; +      if (size != -1) return size; +     +      size = 0; +      if (((bitField0_ & 0x00000001) == 0x00000001)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBytesSize(1, responseProto_); +      } +      if (((bitField0_ & 0x00000002) == 0x00000002)) { +        size += com.google.protobuf.CodedOutputStream +          .computeEnumSize(2, error_.getNumber()); +      } +      if (((bitField0_ & 0x00000040) == 0x00000040)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBytesSize(3, getErrorTextBytes()); +      } +      if (((bitField0_ & 0x00000008) == 0x00000008)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBoolSize(4, hasFailed_); +      } +      if (((bitField0_ & 0x00000004) == 0x00000004)) { +        size += com.google.protobuf.CodedOutputStream +          .computeInt64Size(5, requestId_); +      } +      if (((bitField0_ & 0x00000010) == 0x00000010)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBoolSize(6, canceled_); +      } +      if (((bitField0_ & 0x00000020) == 0x00000020)) { +        size += com.google.protobuf.CodedOutputStream +          .computeBoolSize(7, done_); +      } +      size += getUnknownFields().getSerializedSize(); +      memoizedSerializedSize = size; +      return size; +    } +     +    private static final long serialVersionUID = 0L; +    @java.lang.Override +    protected java.lang.Object writeReplace() +        throws java.io.ObjectStreamException { +      return super.writeReplace(); +    } +     +    public static com.orbekk.protobuf.Data.Response parseFrom( +        com.google.protobuf.ByteString data) +        throws com.google.protobuf.InvalidProtocolBufferException { +      return newBuilder().mergeFrom(data).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Response 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.protobuf.Data.Response parseFrom(byte[] data) +        throws com.google.protobuf.InvalidProtocolBufferException { +      return newBuilder().mergeFrom(data).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Response parseFrom( +        byte[] data, +        com.google.protobuf.ExtensionRegistryLite extensionRegistry) +        throws com.google.protobuf.InvalidProtocolBufferException { +      return newBuilder().mergeFrom(data, extensionRegistry) +               .buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Response parseFrom(java.io.InputStream input) +        throws java.io.IOException { +      return newBuilder().mergeFrom(input).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Response parseFrom( +        java.io.InputStream input, +        com.google.protobuf.ExtensionRegistryLite extensionRegistry) +        throws java.io.IOException { +      return newBuilder().mergeFrom(input, extensionRegistry) +               .buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Response 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.protobuf.Data.Response 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.protobuf.Data.Response parseFrom( +        com.google.protobuf.CodedInputStream input) +        throws java.io.IOException { +      return newBuilder().mergeFrom(input).buildParsed(); +    } +    public static com.orbekk.protobuf.Data.Response 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.protobuf.Data.Response prototype) { +      return newBuilder().mergeFrom(prototype); +    } +    public Builder toBuilder() { return newBuilder(this); } +     +    @java.lang.Override +    protected Builder newBuilderForType( +        com.google.protobuf.GeneratedMessage.BuilderParent parent) { +      Builder builder = new Builder(parent); +      return builder; +    } +    public static final class Builder extends +        com.google.protobuf.GeneratedMessage.Builder<Builder> +       implements com.orbekk.protobuf.Data.ResponseOrBuilder { +      public static final com.google.protobuf.Descriptors.Descriptor +          getDescriptor() { +        return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Response_descriptor; +      } +       +      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable +          internalGetFieldAccessorTable() { +        return com.orbekk.protobuf.Data.internal_static_com_orbekk_protobuf_Response_fieldAccessorTable; +      } +       +      // Construct using com.orbekk.protobuf.Data.Response.newBuilder() +      private Builder() { +        maybeForceBuilderInitialization(); +      } +       +      private Builder(BuilderParent parent) { +        super(parent); +        maybeForceBuilderInitialization(); +      } +      private void maybeForceBuilderInitialization() { +        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { +        } +      } +      private static Builder create() { +        return new Builder(); +      } +       +      public Builder clear() { +        super.clear(); +        responseProto_ = com.google.protobuf.ByteString.EMPTY; +        bitField0_ = (bitField0_ & ~0x00000001); +        error_ = com.orbekk.protobuf.Data.Response.RpcError.UNKNOWN_SERVICE; +        bitField0_ = (bitField0_ & ~0x00000002); +        requestId_ = 0L; +        bitField0_ = (bitField0_ & ~0x00000004); +        hasFailed_ = false; +        bitField0_ = (bitField0_ & ~0x00000008); +        canceled_ = false; +        bitField0_ = (bitField0_ & ~0x00000010); +        done_ = true; +        bitField0_ = (bitField0_ & ~0x00000020); +        errorText_ = ""; +        bitField0_ = (bitField0_ & ~0x00000040); +        return this; +      } +       +      public Builder clone() { +        return create().mergeFrom(buildPartial()); +      } +       +      public com.google.protobuf.Descriptors.Descriptor +          getDescriptorForType() { +        return com.orbekk.protobuf.Data.Response.getDescriptor(); +      } +       +      public com.orbekk.protobuf.Data.Response getDefaultInstanceForType() { +        return com.orbekk.protobuf.Data.Response.getDefaultInstance(); +      } +       +      public com.orbekk.protobuf.Data.Response build() { +        com.orbekk.protobuf.Data.Response result = buildPartial(); +        if (!result.isInitialized()) { +          throw newUninitializedMessageException(result); +        } +        return result; +      } +       +      private com.orbekk.protobuf.Data.Response buildParsed() +          throws com.google.protobuf.InvalidProtocolBufferException { +        com.orbekk.protobuf.Data.Response result = buildPartial(); +        if (!result.isInitialized()) { +          throw newUninitializedMessageException( +            result).asInvalidProtocolBufferException(); +        } +        return result; +      } +       +      public com.orbekk.protobuf.Data.Response buildPartial() { +        com.orbekk.protobuf.Data.Response result = new com.orbekk.protobuf.Data.Response(this); +        int from_bitField0_ = bitField0_; +        int to_bitField0_ = 0; +        if (((from_bitField0_ & 0x00000001) == 0x00000001)) { +          to_bitField0_ |= 0x00000001; +        } +        result.responseProto_ = responseProto_; +        if (((from_bitField0_ & 0x00000002) == 0x00000002)) { +          to_bitField0_ |= 0x00000002; +        } +        result.error_ = error_; +        if (((from_bitField0_ & 0x00000004) == 0x00000004)) { +          to_bitField0_ |= 0x00000004; +        } +        result.requestId_ = requestId_; +        if (((from_bitField0_ & 0x00000008) == 0x00000008)) { +          to_bitField0_ |= 0x00000008; +        } +        result.hasFailed_ = hasFailed_; +        if (((from_bitField0_ & 0x00000010) == 0x00000010)) { +          to_bitField0_ |= 0x00000010; +        } +        result.canceled_ = canceled_; +        if (((from_bitField0_ & 0x00000020) == 0x00000020)) { +          to_bitField0_ |= 0x00000020; +        } +        result.done_ = done_; +        if (((from_bitField0_ & 0x00000040) == 0x00000040)) { +          to_bitField0_ |= 0x00000040; +        } +        result.errorText_ = errorText_; +        result.bitField0_ = to_bitField0_; +        onBuilt(); +        return result; +      } +       +      public Builder mergeFrom(com.google.protobuf.Message other) { +        if (other instanceof com.orbekk.protobuf.Data.Response) { +          return mergeFrom((com.orbekk.protobuf.Data.Response)other); +        } else { +          super.mergeFrom(other); +          return this; +        } +      } +       +      public Builder mergeFrom(com.orbekk.protobuf.Data.Response other) { +        if (other == com.orbekk.protobuf.Data.Response.getDefaultInstance()) return this; +        if (other.hasResponseProto()) { +          setResponseProto(other.getResponseProto()); +        } +        if (other.hasError()) { +          setError(other.getError()); +        } +        if (other.hasRequestId()) { +          setRequestId(other.getRequestId()); +        } +        if (other.hasHasFailed()) { +          setHasFailed(other.getHasFailed()); +        } +        if (other.hasCanceled()) { +          setCanceled(other.getCanceled()); +        } +        if (other.hasDone()) { +          setDone(other.getDone()); +        } +        if (other.hasErrorText()) { +          setErrorText(other.getErrorText()); +        } +        this.mergeUnknownFields(other.getUnknownFields()); +        return this; +      } +       +      public final boolean isInitialized() { +        return true; +      } +       +      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()); +              onChanged(); +              return this; +            default: { +              if (!parseUnknownField(input, unknownFields, +                                     extensionRegistry, tag)) { +                this.setUnknownFields(unknownFields.build()); +                onChanged(); +                return this; +              } +              break; +            } +            case 10: { +              bitField0_ |= 0x00000001; +              responseProto_ = input.readBytes(); +              break; +            } +            case 16: { +              int rawValue = input.readEnum(); +              com.orbekk.protobuf.Data.Response.RpcError value = com.orbekk.protobuf.Data.Response.RpcError.valueOf(rawValue); +              if (value == null) { +                unknownFields.mergeVarintField(2, rawValue); +              } else { +                bitField0_ |= 0x00000002; +                error_ = value; +              } +              break; +            } +            case 26: { +              bitField0_ |= 0x00000040; +              errorText_ = input.readBytes(); +              break; +            } +            case 32: { +              bitField0_ |= 0x00000008; +              hasFailed_ = input.readBool(); +              break; +            } +            case 40: { +              bitField0_ |= 0x00000004; +              requestId_ = input.readInt64(); +              break; +            } +            case 48: { +              bitField0_ |= 0x00000010; +              canceled_ = input.readBool(); +              break; +            } +            case 56: { +              bitField0_ |= 0x00000020; +              done_ = input.readBool(); +              break; +            } +          } +        } +      } +       +      private int bitField0_; +       +      // optional bytes response_proto = 1; +      private com.google.protobuf.ByteString responseProto_ = com.google.protobuf.ByteString.EMPTY; +      public boolean hasResponseProto() { +        return ((bitField0_ & 0x00000001) == 0x00000001); +      } +      public com.google.protobuf.ByteString getResponseProto() { +        return responseProto_; +      } +      public Builder setResponseProto(com.google.protobuf.ByteString value) { +        if (value == null) { +    throw new NullPointerException(); +  } +  bitField0_ |= 0x00000001; +        responseProto_ = value; +        onChanged(); +        return this; +      } +      public Builder clearResponseProto() { +        bitField0_ = (bitField0_ & ~0x00000001); +        responseProto_ = getDefaultInstance().getResponseProto(); +        onChanged(); +        return this; +      } +       +      // optional .com.orbekk.protobuf.Response.RpcError error = 2; +      private com.orbekk.protobuf.Data.Response.RpcError error_ = com.orbekk.protobuf.Data.Response.RpcError.UNKNOWN_SERVICE; +      public boolean hasError() { +        return ((bitField0_ & 0x00000002) == 0x00000002); +      } +      public com.orbekk.protobuf.Data.Response.RpcError getError() { +        return error_; +      } +      public Builder setError(com.orbekk.protobuf.Data.Response.RpcError value) { +        if (value == null) { +          throw new NullPointerException(); +        } +        bitField0_ |= 0x00000002; +        error_ = value; +        onChanged(); +        return this; +      } +      public Builder clearError() { +        bitField0_ = (bitField0_ & ~0x00000002); +        error_ = com.orbekk.protobuf.Data.Response.RpcError.UNKNOWN_SERVICE; +        onChanged(); +        return this; +      } +       +      // optional int64 request_id = 5; +      private long requestId_ ; +      public boolean hasRequestId() { +        return ((bitField0_ & 0x00000004) == 0x00000004); +      } +      public long getRequestId() { +        return requestId_; +      } +      public Builder setRequestId(long value) { +        bitField0_ |= 0x00000004; +        requestId_ = value; +        onChanged(); +        return this; +      } +      public Builder clearRequestId() { +        bitField0_ = (bitField0_ & ~0x00000004); +        requestId_ = 0L; +        onChanged(); +        return this; +      } +       +      // optional bool hasFailed = 4; +      private boolean hasFailed_ ; +      public boolean hasHasFailed() { +        return ((bitField0_ & 0x00000008) == 0x00000008); +      } +      public boolean getHasFailed() { +        return hasFailed_; +      } +      public Builder setHasFailed(boolean value) { +        bitField0_ |= 0x00000008; +        hasFailed_ = value; +        onChanged(); +        return this; +      } +      public Builder clearHasFailed() { +        bitField0_ = (bitField0_ & ~0x00000008); +        hasFailed_ = false; +        onChanged(); +        return this; +      } +       +      // optional bool canceled = 6; +      private boolean canceled_ ; +      public boolean hasCanceled() { +        return ((bitField0_ & 0x00000010) == 0x00000010); +      } +      public boolean getCanceled() { +        return canceled_; +      } +      public Builder setCanceled(boolean value) { +        bitField0_ |= 0x00000010; +        canceled_ = value; +        onChanged(); +        return this; +      } +      public Builder clearCanceled() { +        bitField0_ = (bitField0_ & ~0x00000010); +        canceled_ = false; +        onChanged(); +        return this; +      } +       +      // optional bool done = 7 [default = true]; +      private boolean done_ = true; +      public boolean hasDone() { +        return ((bitField0_ & 0x00000020) == 0x00000020); +      } +      public boolean getDone() { +        return done_; +      } +      public Builder setDone(boolean value) { +        bitField0_ |= 0x00000020; +        done_ = value; +        onChanged(); +        return this; +      } +      public Builder clearDone() { +        bitField0_ = (bitField0_ & ~0x00000020); +        done_ = true; +        onChanged(); +        return this; +      } +       +      // optional string error_text = 3; +      private java.lang.Object errorText_ = ""; +      public boolean hasErrorText() { +        return ((bitField0_ & 0x00000040) == 0x00000040); +      } +      public String getErrorText() { +        java.lang.Object ref = errorText_; +        if (!(ref instanceof String)) { +          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); +          errorText_ = s; +          return s; +        } else { +          return (String) ref; +        } +      } +      public Builder setErrorText(String value) { +        if (value == null) { +    throw new NullPointerException(); +  } +  bitField0_ |= 0x00000040; +        errorText_ = value; +        onChanged(); +        return this; +      } +      public Builder clearErrorText() { +        bitField0_ = (bitField0_ & ~0x00000040); +        errorText_ = getDefaultInstance().getErrorText(); +        onChanged(); +        return this; +      } +      void setErrorText(com.google.protobuf.ByteString value) { +        bitField0_ |= 0x00000040; +        errorText_ = value; +        onChanged(); +      } +       +      // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.Response) +    } +     +    static { +      defaultInstance = new Response(true); +      defaultInstance.initFields(); +    } +     +    // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.Response) +  } +   +  private static com.google.protobuf.Descriptors.Descriptor +    internal_static_com_orbekk_protobuf_Request_descriptor; +  private static +    com.google.protobuf.GeneratedMessage.FieldAccessorTable +      internal_static_com_orbekk_protobuf_Request_fieldAccessorTable; +  private static com.google.protobuf.Descriptors.Descriptor +    internal_static_com_orbekk_protobuf_Response_descriptor; +  private static +    com.google.protobuf.GeneratedMessage.FieldAccessorTable +      internal_static_com_orbekk_protobuf_Response_fieldAccessorTable; +   +  public static com.google.protobuf.Descriptors.FileDescriptor +      getDescriptor() { +    return descriptor; +  } +  private static com.google.protobuf.Descriptors.FileDescriptor +      descriptor; +  static { +    java.lang.String[] descriptorData = { +      "\n,src/main/java/com/orbekk/protobuf/Data" + +      ".proto\022\023com.orbekk.protobuf\"d\n\007Request\022\031" + +      "\n\021full_service_name\030\001 \001(\t\022\023\n\013method_name" + +      "\030\002 \001(\t\022\025\n\rrequest_proto\030\003 \001(\014\022\022\n\nrequest" + +      "_id\030\004 \001(\003\"\375\001\n\010Response\022\026\n\016response_proto" + +      "\030\001 \001(\014\0225\n\005error\030\002 \001(\0162&.com.orbekk.proto" + +      "buf.Response.RpcError\022\022\n\nrequest_id\030\005 \001(" + +      "\003\022\021\n\thasFailed\030\004 \001(\010\022\020\n\010canceled\030\006 \001(\010\022\022" + +      "\n\004done\030\007 \001(\010:\004true\022\022\n\nerror_text\030\003 \001(\t\"A" + +      "\n\010RpcError\022\023\n\017UNKNOWN_SERVICE\020\000\022\022\n\016UNKNO", +      "WN_METHOD\020\001\022\014\n\010CANCELED\020\002" +    }; +    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_protobuf_Request_descriptor = +            getDescriptor().getMessageTypes().get(0); +          internal_static_com_orbekk_protobuf_Request_fieldAccessorTable = new +            com.google.protobuf.GeneratedMessage.FieldAccessorTable( +              internal_static_com_orbekk_protobuf_Request_descriptor, +              new java.lang.String[] { "FullServiceName", "MethodName", "RequestProto", "RequestId", }, +              com.orbekk.protobuf.Data.Request.class, +              com.orbekk.protobuf.Data.Request.Builder.class); +          internal_static_com_orbekk_protobuf_Response_descriptor = +            getDescriptor().getMessageTypes().get(1); +          internal_static_com_orbekk_protobuf_Response_fieldAccessorTable = new +            com.google.protobuf.GeneratedMessage.FieldAccessorTable( +              internal_static_com_orbekk_protobuf_Response_descriptor, +              new java.lang.String[] { "ResponseProto", "Error", "RequestId", "HasFailed", "Canceled", "Done", "ErrorText", }, +              com.orbekk.protobuf.Data.Response.class, +              com.orbekk.protobuf.Data.Response.Builder.class); +          return null; +        } +      }; +    com.google.protobuf.Descriptors.FileDescriptor +      .internalBuildGeneratedFileFrom(descriptorData, +        new com.google.protobuf.Descriptors.FileDescriptor[] { +        }, assigner); +  } +   +  // @@protoc_insertion_point(outer_class_scope) +} diff --git a/src/main/java/com/orbekk/protobuf/Rpc.proto b/src/main/java/com/orbekk/protobuf/Data.proto index e4865fa..168ef29 100644 --- a/src/main/java/com/orbekk/protobuf/Rpc.proto +++ b/src/main/java/com/orbekk/protobuf/Data.proto @@ -8,17 +8,20 @@ message Request {      optional int64 request_id = 4;  } -// Next tag: 6 +// Next tag: 8  message Response {      optional bytes response_proto = 1; -    enum Error { +    enum RpcError {          UNKNOWN_SERVICE = 0;          UNKNOWN_METHOD = 1;          CANCELED = 2; -        APP_ERROR = 3;      }; -    optional Error error = 2; -    optional int32 app_error = 4; -    optional string error_message = 3; +    optional RpcError error = 2;      optional int64 request_id = 5; +     +    // Rpc status +    optional bool hasFailed = 4; +    optional bool canceled = 6; +    optional bool done = 7 [default = true]; +    optional string error_text = 3;  } diff --git a/src/main/java/com/orbekk/protobuf/Rpc.java b/src/main/java/com/orbekk/protobuf/Rpc.java index 38ff1ea..9b087d7 100644 --- a/src/main/java/com/orbekk/protobuf/Rpc.java +++ b/src/main/java/com/orbekk/protobuf/Rpc.java @@ -1,1348 +1,99 @@ -// Generated by the protocol buffer compiler.  DO NOT EDIT! -// source: src/main/java/com/orbekk/protobuf/Rpc.proto -  package com.orbekk.protobuf; -public final class Rpc { -  private Rpc() {} -  public static void registerAllExtensions( -      com.google.protobuf.ExtensionRegistry registry) { -  } -  public interface RequestOrBuilder -      extends com.google.protobuf.MessageOrBuilder { -     -    // optional string full_service_name = 1; -    boolean hasFullServiceName(); -    String getFullServiceName(); -     -    // optional string method_name = 2; -    boolean hasMethodName(); -    String getMethodName(); -     -    // optional bytes request_proto = 3; -    boolean hasRequestProto(); -    com.google.protobuf.ByteString getRequestProto(); -     -    // optional int64 request_id = 4; -    boolean hasRequestId(); -    long getRequestId(); -  } -  public static final class Request extends -      com.google.protobuf.GeneratedMessage -      implements RequestOrBuilder { -    // Use Request.newBuilder() to construct. -    private Request(Builder builder) { -      super(builder); -    } -    private Request(boolean noInit) {} -     -    private static final Request defaultInstance; -    public static Request getDefaultInstance() { -      return defaultInstance; -    } -     -    public Request getDefaultInstanceForType() { -      return defaultInstance; -    } -     -    public static final com.google.protobuf.Descriptors.Descriptor -        getDescriptor() { -      return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Request_descriptor; -    } -     -    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable -        internalGetFieldAccessorTable() { -      return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Request_fieldAccessorTable; -    } -     -    private int bitField0_; -    // optional string full_service_name = 1; -    public static final int FULL_SERVICE_NAME_FIELD_NUMBER = 1; -    private java.lang.Object fullServiceName_; -    public boolean hasFullServiceName() { -      return ((bitField0_ & 0x00000001) == 0x00000001); -    } -    public String getFullServiceName() { -      java.lang.Object ref = fullServiceName_; -      if (ref instanceof String) { -        return (String) ref; -      } else { -        com.google.protobuf.ByteString bs =  -            (com.google.protobuf.ByteString) ref; -        String s = bs.toStringUtf8(); -        if (com.google.protobuf.Internal.isValidUtf8(bs)) { -          fullServiceName_ = s; -        } -        return s; -      } -    } -    private com.google.protobuf.ByteString getFullServiceNameBytes() { -      java.lang.Object ref = fullServiceName_; -      if (ref instanceof String) { -        com.google.protobuf.ByteString b =  -            com.google.protobuf.ByteString.copyFromUtf8((String) ref); -        fullServiceName_ = b; -        return b; -      } else { -        return (com.google.protobuf.ByteString) ref; -      } -    } -     -    // optional string method_name = 2; -    public static final int METHOD_NAME_FIELD_NUMBER = 2; -    private java.lang.Object methodName_; -    public boolean hasMethodName() { -      return ((bitField0_ & 0x00000002) == 0x00000002); -    } -    public String getMethodName() { -      java.lang.Object ref = methodName_; -      if (ref instanceof String) { -        return (String) ref; -      } else { -        com.google.protobuf.ByteString bs =  -            (com.google.protobuf.ByteString) ref; -        String s = bs.toStringUtf8(); -        if (com.google.protobuf.Internal.isValidUtf8(bs)) { -          methodName_ = s; -        } -        return s; -      } -    } -    private com.google.protobuf.ByteString getMethodNameBytes() { -      java.lang.Object ref = methodName_; -      if (ref instanceof String) { -        com.google.protobuf.ByteString b =  -            com.google.protobuf.ByteString.copyFromUtf8((String) ref); -        methodName_ = b; -        return b; -      } else { -        return (com.google.protobuf.ByteString) ref; -      } -    } -     -    // optional bytes request_proto = 3; -    public static final int REQUEST_PROTO_FIELD_NUMBER = 3; -    private com.google.protobuf.ByteString requestProto_; -    public boolean hasRequestProto() { -      return ((bitField0_ & 0x00000004) == 0x00000004); -    } -    public com.google.protobuf.ByteString getRequestProto() { -      return requestProto_; -    } -     -    // optional int64 request_id = 4; -    public static final int REQUEST_ID_FIELD_NUMBER = 4; -    private long requestId_; -    public boolean hasRequestId() { -      return ((bitField0_ & 0x00000008) == 0x00000008); -    } -    public long getRequestId() { -      return requestId_; -    } -     -    private void initFields() { -      fullServiceName_ = ""; -      methodName_ = ""; -      requestProto_ = com.google.protobuf.ByteString.EMPTY; -      requestId_ = 0L; -    } -    private byte memoizedIsInitialized = -1; -    public final boolean isInitialized() { -      byte isInitialized = memoizedIsInitialized; -      if (isInitialized != -1) return isInitialized == 1; -       -      memoizedIsInitialized = 1; -      return true; -    } -     -    public void writeTo(com.google.protobuf.CodedOutputStream output) -                        throws java.io.IOException { -      getSerializedSize(); -      if (((bitField0_ & 0x00000001) == 0x00000001)) { -        output.writeBytes(1, getFullServiceNameBytes()); -      } -      if (((bitField0_ & 0x00000002) == 0x00000002)) { -        output.writeBytes(2, getMethodNameBytes()); -      } -      if (((bitField0_ & 0x00000004) == 0x00000004)) { -        output.writeBytes(3, requestProto_); -      } -      if (((bitField0_ & 0x00000008) == 0x00000008)) { -        output.writeInt64(4, requestId_); -      } -      getUnknownFields().writeTo(output); -    } -     -    private int memoizedSerializedSize = -1; -    public int getSerializedSize() { -      int size = memoizedSerializedSize; -      if (size != -1) return size; -     -      size = 0; -      if (((bitField0_ & 0x00000001) == 0x00000001)) { -        size += com.google.protobuf.CodedOutputStream -          .computeBytesSize(1, getFullServiceNameBytes()); -      } -      if (((bitField0_ & 0x00000002) == 0x00000002)) { -        size += com.google.protobuf.CodedOutputStream -          .computeBytesSize(2, getMethodNameBytes()); -      } -      if (((bitField0_ & 0x00000004) == 0x00000004)) { -        size += com.google.protobuf.CodedOutputStream -          .computeBytesSize(3, requestProto_); -      } -      if (((bitField0_ & 0x00000008) == 0x00000008)) { -        size += com.google.protobuf.CodedOutputStream -          .computeInt64Size(4, requestId_); -      } -      size += getUnknownFields().getSerializedSize(); -      memoizedSerializedSize = size; -      return size; -    } -     -    private static final long serialVersionUID = 0L; -    @java.lang.Override -    protected java.lang.Object writeReplace() -        throws java.io.ObjectStreamException { -      return super.writeReplace(); -    } -     -    public static com.orbekk.protobuf.Rpc.Request parseFrom( -        com.google.protobuf.ByteString data) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Request 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.protobuf.Rpc.Request parseFrom(byte[] data) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Request parseFrom( -        byte[] data, -        com.google.protobuf.ExtensionRegistryLite extensionRegistry) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data, extensionRegistry) -               .buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Request parseFrom(java.io.InputStream input) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Request parseFrom( -        java.io.InputStream input, -        com.google.protobuf.ExtensionRegistryLite extensionRegistry) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input, extensionRegistry) -               .buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Request 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.protobuf.Rpc.Request 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.protobuf.Rpc.Request parseFrom( -        com.google.protobuf.CodedInputStream input) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Request parseFrom( -        com.google.protobuf.CodedInputStream input, -        com.google.protobuf.ExtensionRegistryLite extensionRegistry) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input, extensionRegistry) -               .buildParsed(); -    } +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; + +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; + +public class Rpc implements RpcController { +    private String errorText = ""; +    private boolean hasFailed; +    private boolean canceled; +    private List<RpcCallback<Object>> cancelNotificationListeners = null; -    public static Builder newBuilder() { return Builder.create(); } -    public Builder newBuilderForType() { return newBuilder(); } -    public static Builder newBuilder(com.orbekk.protobuf.Rpc.Request prototype) { -      return newBuilder().mergeFrom(prototype); +    public Rpc() {      } -    public Builder toBuilder() { return newBuilder(this); } -    @java.lang.Override -    protected Builder newBuilderForType( -        com.google.protobuf.GeneratedMessage.BuilderParent parent) { -      Builder builder = new Builder(parent); -      return builder; +    public Rpc(Rpc other) { +        copyFrom(other);      } -    public static final class Builder extends -        com.google.protobuf.GeneratedMessage.Builder<Builder> -       implements com.orbekk.protobuf.Rpc.RequestOrBuilder { -      public static final com.google.protobuf.Descriptors.Descriptor -          getDescriptor() { -        return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Request_descriptor; -      } -       -      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable -          internalGetFieldAccessorTable() { -        return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Request_fieldAccessorTable; -      } -       -      // Construct using com.orbekk.protobuf.Rpc.Request.newBuilder() -      private Builder() { -        maybeForceBuilderInitialization(); -      } -       -      private Builder(BuilderParent parent) { -        super(parent); -        maybeForceBuilderInitialization(); -      } -      private void maybeForceBuilderInitialization() { -        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { -        } -      } -      private static Builder create() { -        return new Builder(); -      } -       -      public Builder clear() { -        super.clear(); -        fullServiceName_ = ""; -        bitField0_ = (bitField0_ & ~0x00000001); -        methodName_ = ""; -        bitField0_ = (bitField0_ & ~0x00000002); -        requestProto_ = com.google.protobuf.ByteString.EMPTY; -        bitField0_ = (bitField0_ & ~0x00000004); -        requestId_ = 0L; -        bitField0_ = (bitField0_ & ~0x00000008); -        return this; -      } -       -      public Builder clone() { -        return create().mergeFrom(buildPartial()); -      } -       -      public com.google.protobuf.Descriptors.Descriptor -          getDescriptorForType() { -        return com.orbekk.protobuf.Rpc.Request.getDescriptor(); -      } -       -      public com.orbekk.protobuf.Rpc.Request getDefaultInstanceForType() { -        return com.orbekk.protobuf.Rpc.Request.getDefaultInstance(); -      } -       -      public com.orbekk.protobuf.Rpc.Request build() { -        com.orbekk.protobuf.Rpc.Request result = buildPartial(); -        if (!result.isInitialized()) { -          throw newUninitializedMessageException(result); -        } -        return result; -      } -       -      private com.orbekk.protobuf.Rpc.Request buildParsed() -          throws com.google.protobuf.InvalidProtocolBufferException { -        com.orbekk.protobuf.Rpc.Request result = buildPartial(); -        if (!result.isInitialized()) { -          throw newUninitializedMessageException( -            result).asInvalidProtocolBufferException(); -        } -        return result; -      } -       -      public com.orbekk.protobuf.Rpc.Request buildPartial() { -        com.orbekk.protobuf.Rpc.Request result = new com.orbekk.protobuf.Rpc.Request(this); -        int from_bitField0_ = bitField0_; -        int to_bitField0_ = 0; -        if (((from_bitField0_ & 0x00000001) == 0x00000001)) { -          to_bitField0_ |= 0x00000001; -        } -        result.fullServiceName_ = fullServiceName_; -        if (((from_bitField0_ & 0x00000002) == 0x00000002)) { -          to_bitField0_ |= 0x00000002; -        } -        result.methodName_ = methodName_; -        if (((from_bitField0_ & 0x00000004) == 0x00000004)) { -          to_bitField0_ |= 0x00000004; -        } -        result.requestProto_ = requestProto_; -        if (((from_bitField0_ & 0x00000008) == 0x00000008)) { -          to_bitField0_ |= 0x00000008; -        } -        result.requestId_ = requestId_; -        result.bitField0_ = to_bitField0_; -        onBuilt(); -        return result; -      } -       -      public Builder mergeFrom(com.google.protobuf.Message other) { -        if (other instanceof com.orbekk.protobuf.Rpc.Request) { -          return mergeFrom((com.orbekk.protobuf.Rpc.Request)other); -        } else { -          super.mergeFrom(other); -          return this; -        } -      } -       -      public Builder mergeFrom(com.orbekk.protobuf.Rpc.Request other) { -        if (other == com.orbekk.protobuf.Rpc.Request.getDefaultInstance()) return this; -        if (other.hasFullServiceName()) { -          setFullServiceName(other.getFullServiceName()); -        } -        if (other.hasMethodName()) { -          setMethodName(other.getMethodName()); -        } -        if (other.hasRequestProto()) { -          setRequestProto(other.getRequestProto()); -        } -        if (other.hasRequestId()) { -          setRequestId(other.getRequestId()); -        } -        this.mergeUnknownFields(other.getUnknownFields()); -        return this; -      } -       -      public final boolean isInitialized() { -        return true; -      } -       -      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()); -              onChanged(); -              return this; -            default: { -              if (!parseUnknownField(input, unknownFields, -                                     extensionRegistry, tag)) { -                this.setUnknownFields(unknownFields.build()); -                onChanged(); -                return this; -              } -              break; -            } -            case 10: { -              bitField0_ |= 0x00000001; -              fullServiceName_ = input.readBytes(); -              break; -            } -            case 18: { -              bitField0_ |= 0x00000002; -              methodName_ = input.readBytes(); -              break; -            } -            case 26: { -              bitField0_ |= 0x00000004; -              requestProto_ = input.readBytes(); -              break; -            } -            case 32: { -              bitField0_ |= 0x00000008; -              requestId_ = input.readInt64(); -              break; + +    public void copyFrom(Rpc other) { +        errorText = other.errorText; +        hasFailed = other.hasFailed; +        canceled = other.canceled; +        if (other.cancelNotificationListeners != null) { +            for (RpcCallback<Object> listener : +                    other.cancelNotificationListeners) { +                notifyOnCancel(listener);              } -          } -        } -      } -       -      private int bitField0_; -       -      // optional string full_service_name = 1; -      private java.lang.Object fullServiceName_ = ""; -      public boolean hasFullServiceName() { -        return ((bitField0_ & 0x00000001) == 0x00000001); -      } -      public String getFullServiceName() { -        java.lang.Object ref = fullServiceName_; -        if (!(ref instanceof String)) { -          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); -          fullServiceName_ = s; -          return s; -        } else { -          return (String) ref; -        } -      } -      public Builder setFullServiceName(String value) { -        if (value == null) { -    throw new NullPointerException(); -  } -  bitField0_ |= 0x00000001; -        fullServiceName_ = value; -        onChanged(); -        return this; -      } -      public Builder clearFullServiceName() { -        bitField0_ = (bitField0_ & ~0x00000001); -        fullServiceName_ = getDefaultInstance().getFullServiceName(); -        onChanged(); -        return this; -      } -      void setFullServiceName(com.google.protobuf.ByteString value) { -        bitField0_ |= 0x00000001; -        fullServiceName_ = value; -        onChanged(); -      } -       -      // optional string method_name = 2; -      private java.lang.Object methodName_ = ""; -      public boolean hasMethodName() { -        return ((bitField0_ & 0x00000002) == 0x00000002); -      } -      public String getMethodName() { -        java.lang.Object ref = methodName_; -        if (!(ref instanceof String)) { -          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); -          methodName_ = s; -          return s; -        } else { -          return (String) ref;          } -      } -      public Builder setMethodName(String value) { -        if (value == null) { -    throw new NullPointerException(); -  } -  bitField0_ |= 0x00000002; -        methodName_ = value; -        onChanged(); -        return this; -      } -      public Builder clearMethodName() { -        bitField0_ = (bitField0_ & ~0x00000002); -        methodName_ = getDefaultInstance().getMethodName(); -        onChanged(); -        return this; -      } -      void setMethodName(com.google.protobuf.ByteString value) { -        bitField0_ |= 0x00000002; -        methodName_ = value; -        onChanged(); -      } -       -      // optional bytes request_proto = 3; -      private com.google.protobuf.ByteString requestProto_ = com.google.protobuf.ByteString.EMPTY; -      public boolean hasRequestProto() { -        return ((bitField0_ & 0x00000004) == 0x00000004); -      } -      public com.google.protobuf.ByteString getRequestProto() { -        return requestProto_; -      } -      public Builder setRequestProto(com.google.protobuf.ByteString value) { -        if (value == null) { -    throw new NullPointerException(); -  } -  bitField0_ |= 0x00000004; -        requestProto_ = value; -        onChanged(); -        return this; -      } -      public Builder clearRequestProto() { -        bitField0_ = (bitField0_ & ~0x00000004); -        requestProto_ = getDefaultInstance().getRequestProto(); -        onChanged(); -        return this; -      } -       -      // optional int64 request_id = 4; -      private long requestId_ ; -      public boolean hasRequestId() { -        return ((bitField0_ & 0x00000008) == 0x00000008); -      } -      public long getRequestId() { -        return requestId_; -      } -      public Builder setRequestId(long value) { -        bitField0_ |= 0x00000008; -        requestId_ = value; -        onChanged(); -        return this; -      } -      public Builder clearRequestId() { -        bitField0_ = (bitField0_ & ~0x00000008); -        requestId_ = 0L; -        onChanged(); -        return this; -      } -       -      // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.Request) -    } -     -    static { -      defaultInstance = new Request(true); -      defaultInstance.initFields(); -    } -     -    // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.Request) -  } -   -  public interface ResponseOrBuilder -      extends com.google.protobuf.MessageOrBuilder { -     -    // optional bytes response_proto = 1; -    boolean hasResponseProto(); -    com.google.protobuf.ByteString getResponseProto(); -     -    // optional .com.orbekk.protobuf.Response.Error error = 2; -    boolean hasError(); -    com.orbekk.protobuf.Rpc.Response.Error getError(); -     -    // optional int32 app_error = 4; -    boolean hasAppError(); -    int getAppError(); -     -    // optional string error_message = 3; -    boolean hasErrorMessage(); -    String getErrorMessage(); -     -    // optional int64 request_id = 5; -    boolean hasRequestId(); -    long getRequestId(); -  } -  public static final class Response extends -      com.google.protobuf.GeneratedMessage -      implements ResponseOrBuilder { -    // Use Response.newBuilder() to construct. -    private Response(Builder builder) { -      super(builder);      } -    private Response(boolean noInit) {} -    private static final Response defaultInstance; -    public static Response getDefaultInstance() { -      return defaultInstance; +    public void writeTo(Data.Response.Builder response) { +        response.setHasFailed(hasFailed); +        response.setCanceled(canceled); +        response.setErrorText(errorText);      } -    public Response getDefaultInstanceForType() { -      return defaultInstance; +    public void readFrom(Data.Response response) { +        hasFailed = response.getHasFailed(); +        canceled = response.getCanceled(); +        errorText = response.getErrorText();      } -    public static final com.google.protobuf.Descriptors.Descriptor -        getDescriptor() { -      return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Response_descriptor; +    @Override +    public String errorText() { +        return errorText;      } -     -    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable -        internalGetFieldAccessorTable() { -      return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Response_fieldAccessorTable; -    } -     -    public enum Error -        implements com.google.protobuf.ProtocolMessageEnum { -      UNKNOWN_SERVICE(0, 0), -      UNKNOWN_METHOD(1, 1), -      CANCELED(2, 2), -      APP_ERROR(3, 3), -      ; -       -      public static final int UNKNOWN_SERVICE_VALUE = 0; -      public static final int UNKNOWN_METHOD_VALUE = 1; -      public static final int CANCELED_VALUE = 2; -      public static final int APP_ERROR_VALUE = 3; -       -       -      public final int getNumber() { return value; } -       -      public static Error valueOf(int value) { -        switch (value) { -          case 0: return UNKNOWN_SERVICE; -          case 1: return UNKNOWN_METHOD; -          case 2: return CANCELED; -          case 3: return APP_ERROR; -          default: return null; -        } -      } -       -      public static com.google.protobuf.Internal.EnumLiteMap<Error> -          internalGetValueMap() { -        return internalValueMap; -      } -      private static com.google.protobuf.Internal.EnumLiteMap<Error> -          internalValueMap = -            new com.google.protobuf.Internal.EnumLiteMap<Error>() { -              public Error findValueByNumber(int number) { -                return Error.valueOf(number); -              } -            }; -       -      public final com.google.protobuf.Descriptors.EnumValueDescriptor -          getValueDescriptor() { -        return getDescriptor().getValues().get(index); -      } -      public final com.google.protobuf.Descriptors.EnumDescriptor -          getDescriptorForType() { -        return getDescriptor(); -      } -      public static final com.google.protobuf.Descriptors.EnumDescriptor -          getDescriptor() { -        return com.orbekk.protobuf.Rpc.Response.getDescriptor().getEnumTypes().get(0); -      } -       -      private static final Error[] VALUES = { -        UNKNOWN_SERVICE, UNKNOWN_METHOD, CANCELED, APP_ERROR,  -      }; -       -      public static Error valueOf( -          com.google.protobuf.Descriptors.EnumValueDescriptor desc) { -        if (desc.getType() != getDescriptor()) { -          throw new java.lang.IllegalArgumentException( -            "EnumValueDescriptor is not for this type."); -        } -        return VALUES[desc.getIndex()]; -      } -       -      private final int index; -      private final int value; -       -      private Error(int index, int value) { -        this.index = index; -        this.value = value; -      } -       -      // @@protoc_insertion_point(enum_scope:com.orbekk.protobuf.Response.Error) -    } -     -    private int bitField0_; -    // optional bytes response_proto = 1; -    public static final int RESPONSE_PROTO_FIELD_NUMBER = 1; -    private com.google.protobuf.ByteString responseProto_; -    public boolean hasResponseProto() { -      return ((bitField0_ & 0x00000001) == 0x00000001); -    } -    public com.google.protobuf.ByteString getResponseProto() { -      return responseProto_; -    } -     -    // optional .com.orbekk.protobuf.Response.Error error = 2; -    public static final int ERROR_FIELD_NUMBER = 2; -    private com.orbekk.protobuf.Rpc.Response.Error error_; -    public boolean hasError() { -      return ((bitField0_ & 0x00000002) == 0x00000002); -    } -    public com.orbekk.protobuf.Rpc.Response.Error getError() { -      return error_; + +    public boolean isOk() { +        return !hasFailed && !canceled;      } -    // optional int32 app_error = 4; -    public static final int APP_ERROR_FIELD_NUMBER = 4; -    private int appError_; -    public boolean hasAppError() { -      return ((bitField0_ & 0x00000004) == 0x00000004); +    @Override +    public boolean failed() { +        return hasFailed;      } -    public int getAppError() { -      return appError_; -    } -     -    // optional string error_message = 3; -    public static final int ERROR_MESSAGE_FIELD_NUMBER = 3; -    private java.lang.Object errorMessage_; -    public boolean hasErrorMessage() { -      return ((bitField0_ & 0x00000008) == 0x00000008); + +    @Override +    public boolean isCanceled() { +        return canceled;      } -    public String getErrorMessage() { -      java.lang.Object ref = errorMessage_; -      if (ref instanceof String) { -        return (String) ref; -      } else { -        com.google.protobuf.ByteString bs =  -            (com.google.protobuf.ByteString) ref; -        String s = bs.toStringUtf8(); -        if (com.google.protobuf.Internal.isValidUtf8(bs)) { -          errorMessage_ = s; + +    @Override +    public void notifyOnCancel(RpcCallback<Object> listener) { +        if (cancelNotificationListeners == null) { +            cancelNotificationListeners = +                    new ArrayList<RpcCallback<Object>>();          } -        return s; -      } -    } -    private com.google.protobuf.ByteString getErrorMessageBytes() { -      java.lang.Object ref = errorMessage_; -      if (ref instanceof String) { -        com.google.protobuf.ByteString b =  -            com.google.protobuf.ByteString.copyFromUtf8((String) ref); -        errorMessage_ = b; -        return b; -      } else { -        return (com.google.protobuf.ByteString) ref; -      } -    } -     -    // optional int64 request_id = 5; -    public static final int REQUEST_ID_FIELD_NUMBER = 5; -    private long requestId_; -    public boolean hasRequestId() { -      return ((bitField0_ & 0x00000010) == 0x00000010); -    } -    public long getRequestId() { -      return requestId_; -    } -     -    private void initFields() { -      responseProto_ = com.google.protobuf.ByteString.EMPTY; -      error_ = com.orbekk.protobuf.Rpc.Response.Error.UNKNOWN_SERVICE; -      appError_ = 0; -      errorMessage_ = ""; -      requestId_ = 0L; -    } -    private byte memoizedIsInitialized = -1; -    public final boolean isInitialized() { -      byte isInitialized = memoizedIsInitialized; -      if (isInitialized != -1) return isInitialized == 1; -       -      memoizedIsInitialized = 1; -      return true; -    } -     -    public void writeTo(com.google.protobuf.CodedOutputStream output) -                        throws java.io.IOException { -      getSerializedSize(); -      if (((bitField0_ & 0x00000001) == 0x00000001)) { -        output.writeBytes(1, responseProto_); -      } -      if (((bitField0_ & 0x00000002) == 0x00000002)) { -        output.writeEnum(2, error_.getNumber()); -      } -      if (((bitField0_ & 0x00000008) == 0x00000008)) { -        output.writeBytes(3, getErrorMessageBytes()); -      } -      if (((bitField0_ & 0x00000004) == 0x00000004)) { -        output.writeInt32(4, appError_); -      } -      if (((bitField0_ & 0x00000010) == 0x00000010)) { -        output.writeInt64(5, requestId_); -      } -      getUnknownFields().writeTo(output); -    } -     -    private int memoizedSerializedSize = -1; -    public int getSerializedSize() { -      int size = memoizedSerializedSize; -      if (size != -1) return size; -     -      size = 0; -      if (((bitField0_ & 0x00000001) == 0x00000001)) { -        size += com.google.protobuf.CodedOutputStream -          .computeBytesSize(1, responseProto_); -      } -      if (((bitField0_ & 0x00000002) == 0x00000002)) { -        size += com.google.protobuf.CodedOutputStream -          .computeEnumSize(2, error_.getNumber()); -      } -      if (((bitField0_ & 0x00000008) == 0x00000008)) { -        size += com.google.protobuf.CodedOutputStream -          .computeBytesSize(3, getErrorMessageBytes()); -      } -      if (((bitField0_ & 0x00000004) == 0x00000004)) { -        size += com.google.protobuf.CodedOutputStream -          .computeInt32Size(4, appError_); -      } -      if (((bitField0_ & 0x00000010) == 0x00000010)) { -        size += com.google.protobuf.CodedOutputStream -          .computeInt64Size(5, requestId_); -      } -      size += getUnknownFields().getSerializedSize(); -      memoizedSerializedSize = size; -      return size; -    } -     -    private static final long serialVersionUID = 0L; -    @java.lang.Override -    protected java.lang.Object writeReplace() -        throws java.io.ObjectStreamException { -      return super.writeReplace(); -    } -     -    public static com.orbekk.protobuf.Rpc.Response parseFrom( -        com.google.protobuf.ByteString data) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Response parseFrom( -        com.google.protobuf.ByteString data, -        com.google.protobuf.ExtensionRegistryLite extensionRegistry) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data, extensionRegistry) -               .buildParsed(); +        cancelNotificationListeners.add(listener);      } -    public static com.orbekk.protobuf.Rpc.Response parseFrom(byte[] data) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Response parseFrom( -        byte[] data, -        com.google.protobuf.ExtensionRegistryLite extensionRegistry) -        throws com.google.protobuf.InvalidProtocolBufferException { -      return newBuilder().mergeFrom(data, extensionRegistry) -               .buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Response parseFrom(java.io.InputStream input) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Response parseFrom( -        java.io.InputStream input, -        com.google.protobuf.ExtensionRegistryLite extensionRegistry) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input, extensionRegistry) -               .buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Response 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.protobuf.Rpc.Response 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.protobuf.Rpc.Response parseFrom( -        com.google.protobuf.CodedInputStream input) -        throws java.io.IOException { -      return newBuilder().mergeFrom(input).buildParsed(); -    } -    public static com.orbekk.protobuf.Rpc.Response 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.protobuf.Rpc.Response prototype) { -      return newBuilder().mergeFrom(prototype); -    } -    public Builder toBuilder() { return newBuilder(this); } -     -    @java.lang.Override -    protected Builder newBuilderForType( -        com.google.protobuf.GeneratedMessage.BuilderParent parent) { -      Builder builder = new Builder(parent); -      return builder; + +    @Override +    public void reset() { +        copyFrom(new Rpc());      } -    public static final class Builder extends -        com.google.protobuf.GeneratedMessage.Builder<Builder> -       implements com.orbekk.protobuf.Rpc.ResponseOrBuilder { -      public static final com.google.protobuf.Descriptors.Descriptor -          getDescriptor() { -        return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Response_descriptor; -      } -       -      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable -          internalGetFieldAccessorTable() { -        return com.orbekk.protobuf.Rpc.internal_static_com_orbekk_protobuf_Response_fieldAccessorTable; -      } -       -      // Construct using com.orbekk.protobuf.Rpc.Response.newBuilder() -      private Builder() { -        maybeForceBuilderInitialization(); -      } -       -      private Builder(BuilderParent parent) { -        super(parent); -        maybeForceBuilderInitialization(); -      } -      private void maybeForceBuilderInitialization() { -        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { -        } -      } -      private static Builder create() { -        return new Builder(); -      } -       -      public Builder clear() { -        super.clear(); -        responseProto_ = com.google.protobuf.ByteString.EMPTY; -        bitField0_ = (bitField0_ & ~0x00000001); -        error_ = com.orbekk.protobuf.Rpc.Response.Error.UNKNOWN_SERVICE; -        bitField0_ = (bitField0_ & ~0x00000002); -        appError_ = 0; -        bitField0_ = (bitField0_ & ~0x00000004); -        errorMessage_ = ""; -        bitField0_ = (bitField0_ & ~0x00000008); -        requestId_ = 0L; -        bitField0_ = (bitField0_ & ~0x00000010); -        return this; -      } -       -      public Builder clone() { -        return create().mergeFrom(buildPartial()); -      } -       -      public com.google.protobuf.Descriptors.Descriptor -          getDescriptorForType() { -        return com.orbekk.protobuf.Rpc.Response.getDescriptor(); -      } -       -      public com.orbekk.protobuf.Rpc.Response getDefaultInstanceForType() { -        return com.orbekk.protobuf.Rpc.Response.getDefaultInstance(); -      } -       -      public com.orbekk.protobuf.Rpc.Response build() { -        com.orbekk.protobuf.Rpc.Response result = buildPartial(); -        if (!result.isInitialized()) { -          throw newUninitializedMessageException(result); -        } -        return result; -      } -       -      private com.orbekk.protobuf.Rpc.Response buildParsed() -          throws com.google.protobuf.InvalidProtocolBufferException { -        com.orbekk.protobuf.Rpc.Response result = buildPartial(); -        if (!result.isInitialized()) { -          throw newUninitializedMessageException( -            result).asInvalidProtocolBufferException(); -        } -        return result; -      } -       -      public com.orbekk.protobuf.Rpc.Response buildPartial() { -        com.orbekk.protobuf.Rpc.Response result = new com.orbekk.protobuf.Rpc.Response(this); -        int from_bitField0_ = bitField0_; -        int to_bitField0_ = 0; -        if (((from_bitField0_ & 0x00000001) == 0x00000001)) { -          to_bitField0_ |= 0x00000001; -        } -        result.responseProto_ = responseProto_; -        if (((from_bitField0_ & 0x00000002) == 0x00000002)) { -          to_bitField0_ |= 0x00000002; -        } -        result.error_ = error_; -        if (((from_bitField0_ & 0x00000004) == 0x00000004)) { -          to_bitField0_ |= 0x00000004; -        } -        result.appError_ = appError_; -        if (((from_bitField0_ & 0x00000008) == 0x00000008)) { -          to_bitField0_ |= 0x00000008; -        } -        result.errorMessage_ = errorMessage_; -        if (((from_bitField0_ & 0x00000010) == 0x00000010)) { -          to_bitField0_ |= 0x00000010; -        } -        result.requestId_ = requestId_; -        result.bitField0_ = to_bitField0_; -        onBuilt(); -        return result; -      } -       -      public Builder mergeFrom(com.google.protobuf.Message other) { -        if (other instanceof com.orbekk.protobuf.Rpc.Response) { -          return mergeFrom((com.orbekk.protobuf.Rpc.Response)other); -        } else { -          super.mergeFrom(other); -          return this; -        } -      } -       -      public Builder mergeFrom(com.orbekk.protobuf.Rpc.Response other) { -        if (other == com.orbekk.protobuf.Rpc.Response.getDefaultInstance()) return this; -        if (other.hasResponseProto()) { -          setResponseProto(other.getResponseProto()); -        } -        if (other.hasError()) { -          setError(other.getError()); -        } -        if (other.hasAppError()) { -          setAppError(other.getAppError()); -        } -        if (other.hasErrorMessage()) { -          setErrorMessage(other.getErrorMessage()); -        } -        if (other.hasRequestId()) { -          setRequestId(other.getRequestId()); -        } -        this.mergeUnknownFields(other.getUnknownFields()); -        return this; -      } -       -      public final boolean isInitialized() { -        return true; -      } -       -      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()); -              onChanged(); -              return this; -            default: { -              if (!parseUnknownField(input, unknownFields, -                                     extensionRegistry, tag)) { -                this.setUnknownFields(unknownFields.build()); -                onChanged(); -                return this; -              } -              break; -            } -            case 10: { -              bitField0_ |= 0x00000001; -              responseProto_ = input.readBytes(); -              break; -            } -            case 16: { -              int rawValue = input.readEnum(); -              com.orbekk.protobuf.Rpc.Response.Error value = com.orbekk.protobuf.Rpc.Response.Error.valueOf(rawValue); -              if (value == null) { -                unknownFields.mergeVarintField(2, rawValue); -              } else { -                bitField0_ |= 0x00000002; -                error_ = value; -              } -              break; -            } -            case 26: { -              bitField0_ |= 0x00000008; -              errorMessage_ = input.readBytes(); -              break; -            } -            case 32: { -              bitField0_ |= 0x00000004; -              appError_ = input.readInt32(); -              break; -            } -            case 40: { -              bitField0_ |= 0x00000010; -              requestId_ = input.readInt64(); -              break; + +    @Override +    public void setFailed(String message) { +        hasFailed = true; +        errorText = message; +    } +     +    public void cancel() { +        canceled = true; +        if (cancelNotificationListeners != null) { +            for (RpcCallback<Object> listener : +                    cancelNotificationListeners) { +                listener.run(null);              } -          } -        } -      } -       -      private int bitField0_; -       -      // optional bytes response_proto = 1; -      private com.google.protobuf.ByteString responseProto_ = com.google.protobuf.ByteString.EMPTY; -      public boolean hasResponseProto() { -        return ((bitField0_ & 0x00000001) == 0x00000001); -      } -      public com.google.protobuf.ByteString getResponseProto() { -        return responseProto_; -      } -      public Builder setResponseProto(com.google.protobuf.ByteString value) { -        if (value == null) { -    throw new NullPointerException(); -  } -  bitField0_ |= 0x00000001; -        responseProto_ = value; -        onChanged(); -        return this; -      } -      public Builder clearResponseProto() { -        bitField0_ = (bitField0_ & ~0x00000001); -        responseProto_ = getDefaultInstance().getResponseProto(); -        onChanged(); -        return this; -      } -       -      // optional .com.orbekk.protobuf.Response.Error error = 2; -      private com.orbekk.protobuf.Rpc.Response.Error error_ = com.orbekk.protobuf.Rpc.Response.Error.UNKNOWN_SERVICE; -      public boolean hasError() { -        return ((bitField0_ & 0x00000002) == 0x00000002); -      } -      public com.orbekk.protobuf.Rpc.Response.Error getError() { -        return error_; -      } -      public Builder setError(com.orbekk.protobuf.Rpc.Response.Error value) { -        if (value == null) { -          throw new NullPointerException(); -        } -        bitField0_ |= 0x00000002; -        error_ = value; -        onChanged(); -        return this; -      } -      public Builder clearError() { -        bitField0_ = (bitField0_ & ~0x00000002); -        error_ = com.orbekk.protobuf.Rpc.Response.Error.UNKNOWN_SERVICE; -        onChanged(); -        return this; -      } -       -      // optional int32 app_error = 4; -      private int appError_ ; -      public boolean hasAppError() { -        return ((bitField0_ & 0x00000004) == 0x00000004); -      } -      public int getAppError() { -        return appError_; -      } -      public Builder setAppError(int value) { -        bitField0_ |= 0x00000004; -        appError_ = value; -        onChanged(); -        return this; -      } -      public Builder clearAppError() { -        bitField0_ = (bitField0_ & ~0x00000004); -        appError_ = 0; -        onChanged(); -        return this; -      } -       -      // optional string error_message = 3; -      private java.lang.Object errorMessage_ = ""; -      public boolean hasErrorMessage() { -        return ((bitField0_ & 0x00000008) == 0x00000008); -      } -      public String getErrorMessage() { -        java.lang.Object ref = errorMessage_; -        if (!(ref instanceof String)) { -          String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); -          errorMessage_ = s; -          return s; -        } else { -          return (String) ref;          } -      } -      public Builder setErrorMessage(String value) { -        if (value == null) { -    throw new NullPointerException(); -  } -  bitField0_ |= 0x00000008; -        errorMessage_ = value; -        onChanged(); -        return this; -      } -      public Builder clearErrorMessage() { -        bitField0_ = (bitField0_ & ~0x00000008); -        errorMessage_ = getDefaultInstance().getErrorMessage(); -        onChanged(); -        return this; -      } -      void setErrorMessage(com.google.protobuf.ByteString value) { -        bitField0_ |= 0x00000008; -        errorMessage_ = value; -        onChanged(); -      } -       -      // optional int64 request_id = 5; -      private long requestId_ ; -      public boolean hasRequestId() { -        return ((bitField0_ & 0x00000010) == 0x00000010); -      } -      public long getRequestId() { -        return requestId_; -      } -      public Builder setRequestId(long value) { -        bitField0_ |= 0x00000010; -        requestId_ = value; -        onChanged(); -        return this; -      } -      public Builder clearRequestId() { -        bitField0_ = (bitField0_ & ~0x00000010); -        requestId_ = 0L; -        onChanged(); -        return this; -      } -       -      // @@protoc_insertion_point(builder_scope:com.orbekk.protobuf.Response)      } -     -    static { -      defaultInstance = new Response(true); -      defaultInstance.initFields(); + +    @Override +    public void startCancel() {      } -     -    // @@protoc_insertion_point(class_scope:com.orbekk.protobuf.Response) -  } -   -  private static com.google.protobuf.Descriptors.Descriptor -    internal_static_com_orbekk_protobuf_Request_descriptor; -  private static -    com.google.protobuf.GeneratedMessage.FieldAccessorTable -      internal_static_com_orbekk_protobuf_Request_fieldAccessorTable; -  private static com.google.protobuf.Descriptors.Descriptor -    internal_static_com_orbekk_protobuf_Response_descriptor; -  private static -    com.google.protobuf.GeneratedMessage.FieldAccessorTable -      internal_static_com_orbekk_protobuf_Response_fieldAccessorTable; -   -  public static com.google.protobuf.Descriptors.FileDescriptor -      getDescriptor() { -    return descriptor; -  } -  private static com.google.protobuf.Descriptors.FileDescriptor -      descriptor; -  static { -    java.lang.String[] descriptorData = { -      "\n+src/main/java/com/orbekk/protobuf/Rpc." + -      "proto\022\023com.orbekk.protobuf\"d\n\007Request\022\031\n" + -      "\021full_service_name\030\001 \001(\t\022\023\n\013method_name\030" + -      "\002 \001(\t\022\025\n\rrequest_proto\030\003 \001(\014\022\022\n\nrequest_" + -      "id\030\004 \001(\003\"\343\001\n\010Response\022\026\n\016response_proto\030" + -      "\001 \001(\014\0222\n\005error\030\002 \001(\0162#.com.orbekk.protob" + -      "uf.Response.Error\022\021\n\tapp_error\030\004 \001(\005\022\025\n\r" + -      "error_message\030\003 \001(\t\022\022\n\nrequest_id\030\005 \001(\003\"" + -      "M\n\005Error\022\023\n\017UNKNOWN_SERVICE\020\000\022\022\n\016UNKNOWN" + -      "_METHOD\020\001\022\014\n\010CANCELED\020\002\022\r\n\tAPP_ERROR\020\003" -    }; -    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_protobuf_Request_descriptor = -            getDescriptor().getMessageTypes().get(0); -          internal_static_com_orbekk_protobuf_Request_fieldAccessorTable = new -            com.google.protobuf.GeneratedMessage.FieldAccessorTable( -              internal_static_com_orbekk_protobuf_Request_descriptor, -              new java.lang.String[] { "FullServiceName", "MethodName", "RequestProto", "RequestId", }, -              com.orbekk.protobuf.Rpc.Request.class, -              com.orbekk.protobuf.Rpc.Request.Builder.class); -          internal_static_com_orbekk_protobuf_Response_descriptor = -            getDescriptor().getMessageTypes().get(1); -          internal_static_com_orbekk_protobuf_Response_fieldAccessorTable = new -            com.google.protobuf.GeneratedMessage.FieldAccessorTable( -              internal_static_com_orbekk_protobuf_Response_descriptor, -              new java.lang.String[] { "ResponseProto", "Error", "AppError", "ErrorMessage", "RequestId", }, -              com.orbekk.protobuf.Rpc.Response.class, -              com.orbekk.protobuf.Rpc.Response.Builder.class); -          return null; -        } -      }; -    com.google.protobuf.Descriptors.FileDescriptor -      .internalBuildGeneratedFileFrom(descriptorData, -        new com.google.protobuf.Descriptors.FileDescriptor[] { -        }, assigner); -  } -   -  // @@protoc_insertion_point(outer_class_scope)  } diff --git a/src/main/java/com/orbekk/protobuf/RpcChannel.java b/src/main/java/com/orbekk/protobuf/RpcChannel.java index 56b54c2..94ab8a5 100644 --- a/src/main/java/com/orbekk/protobuf/RpcChannel.java +++ b/src/main/java/com/orbekk/protobuf/RpcChannel.java @@ -7,6 +7,8 @@ import java.net.UnknownHostException;  import java.util.Collections;  import java.util.HashMap;  import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue;  import java.util.concurrent.atomic.AtomicLong;  import java.util.logging.Level;  import java.util.logging.Logger; @@ -28,19 +30,20 @@ public class RpcChannel extends Thread implements      private Map<Long, RpcChannel.OngoingRequest> rpcs =              Collections.synchronizedMap(                      new HashMap<Long, RpcChannel.OngoingRequest>()); +    private BlockingQueue<Socket> sockets = new LinkedBlockingQueue<Socket>();      private static class OngoingRequest implements Closeable {          long id; -        RpcController controller; +        Rpc rpc;          RpcCallback<Message> done;          Message responsePrototype;          Map<Long, RpcChannel.OngoingRequest> rpcs; -        public OngoingRequest(long id, RpcController controller, +        public OngoingRequest(long id, Rpc rpc,                  RpcCallback<Message> done, Message responsePrototype,                  Map<Long, RpcChannel.OngoingRequest> rpcs) {              this.id = id; -            this.controller = controller; +            this.rpc = rpc;              this.done = done;              this.responsePrototype = responsePrototype;              this.rpcs = rpcs; @@ -67,10 +70,8 @@ public class RpcChannel extends Thread implements          if (socket == null || socket.isClosed()) {              try {                  logger.info("Creating new socket to " + host + ":" + port); -                synchronized (this) { -                    socket = new Socket(host, port); -                    notify(); -                } +                socket = new Socket(host, port); +                sockets.add(socket);              } catch (UnknownHostException e) {                  return null;              } catch (IOException e) { @@ -82,17 +83,18 @@ public class RpcChannel extends Thread implements          return socket;      } -    private Rpc.Request createRequest(Descriptors.MethodDescriptor method, +    private Data.Request createRequest(Descriptors.MethodDescriptor method,              RpcController controller,              Message requestMessage,              Message responsePrototype,              RpcCallback<Message> done) {          long id = nextId.incrementAndGet(); -        OngoingRequest ongoingRequest = new OngoingRequest(id, controller, +        Rpc rpc = (Rpc)controller; +        OngoingRequest ongoingRequest = new OngoingRequest(id, rpc,                  done, responsePrototype, rpcs);          rpcs.put(id, ongoingRequest); -        Rpc.Request request = Rpc.Request.newBuilder() +        Data.Request request = Data.Request.newBuilder()                  .setRequestId(id)                  .setFullServiceName(method.getService().getFullName())                  .setMethodName(method.getName()) @@ -102,12 +104,13 @@ public class RpcChannel extends Thread implements          return request;      } -    private void finishRequest(Rpc.Response response) { +    private void finishRequest(Data.Response response) {          OngoingRequest ongoingRequest = rpcs.remove(response.getRequestId());          if (ongoingRequest != null) {              try {                  Message responsePb = ongoingRequest.responsePrototype.toBuilder()                          .mergeFrom(response.getResponseProto()).build(); +                ongoingRequest.rpc.readFrom(response);                  ongoingRequest.done.run(responsePb);              } catch (InvalidProtocolBufferException e) {                  throw new AssertionError("Should fail here."); @@ -122,7 +125,7 @@ public class RpcChannel extends Thread implements              Message responsePrototype,              RpcCallback<Message> done) {          try { -            Rpc.Request request = createRequest(method, controller, +            Data.Request request = createRequest(method, controller,                      requestMessage, responsePrototype, done);              Socket socket = getSocket();              request.writeDelimitedTo(socket.getOutputStream()); @@ -135,13 +138,17 @@ public class RpcChannel extends Thread implements          try {              logger.info("Handling responses to socket " + socket);              while (!socket.isClosed()) { -                Rpc.Response response; -                response = Rpc.Response.parseDelimitedFrom( +                Data.Response response; +                response = Data.Response.parseDelimitedFrom(                          socket.getInputStream());                  finishRequest(response);              }          } catch (IOException e) { -            // Breaks the loop. +            if (!rpcs.isEmpty()) { +                logger.log(Level.WARNING, "IO Error. Canceling " + +                        rpcs.size() + " requests.", e); +                cancelAllRpcs(); +            }          } finally {              if (socket != null && !socket.isClosed()) {                  try { @@ -153,17 +160,21 @@ public class RpcChannel extends Thread implements          }      } +    private void cancelAllRpcs() { +        synchronized (rpcs) { +            for (OngoingRequest request : rpcs.values()) { +                request.rpc.setFailed("connection closed"); +                request.done.run(null); +            } +            rpcs.clear(); +        }        +    } +          public void run() {          while (!Thread.interrupted()) {              try { -                synchronized (this) { -                    if (socket == null) { -                        wait(); -                    } -                } -                if (socket != null) { -                    handleResponses(socket); -                } +                Socket socket = sockets.take(); +                handleResponses(socket);              } catch (InterruptedException e) {                  // Interrupts handled by outer loop              } diff --git a/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java b/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java deleted file mode 100644 index 7d0dc6a..0000000 --- a/src/main/java/com/orbekk/protobuf/SimpleProtobufClient.java +++ /dev/null @@ -1,39 +0,0 @@ -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(); -//    } -} diff --git a/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java b/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java index 690da81..f597556 100644 --- a/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java +++ b/src/main/java/com/orbekk/protobuf/SimpleProtobufServer.java @@ -1,27 +1,32 @@  package com.orbekk.protobuf; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.io.OutputStream;  import java.io.IOException; +import java.io.OutputStream;  import java.net.InetSocketAddress;  import java.net.ServerSocket;  import java.net.Socket; -import java.util.Scanner; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.HashSet; + +import com.google.protobuf.Descriptors;  import com.google.protobuf.Message; -import com.google.protobuf.Service; -import com.google.protobuf.RpcController;  import com.google.protobuf.RpcCallback; -import com.google.protobuf.Descriptors; -import java.util.Map; -import java.util.HashMap; +import com.google.protobuf.Service;  public class SimpleProtobufServer extends Thread {      private static Logger logger = Logger.getLogger(              SimpleProtobufServer.class.getName());      private ServerSocket serverSocket; +    private Set<Socket> activeClientSockets =  +            Collections.synchronizedSet(new HashSet<Socket>());      private Map<String, Service> registeredServices = -            new HashMap<String, Service>(); +            Collections.synchronizedMap( +                    new HashMap<String, Service>());      public static SimpleProtobufServer create(int port) {          try { @@ -44,7 +49,7 @@ public class SimpleProtobufServer extends Thread {          return serverSocket.getLocalPort();      } -    public synchronized void registerService(Service service) { +    public void registerService(Service service) {          String serviceName = service.getDescriptorForType().getFullName();          if (registeredServices.containsKey(serviceName)) {              logger.warning("Already registered service with this name."); @@ -53,25 +58,31 @@ public class SimpleProtobufServer extends Thread {          registeredServices.put(serviceName, service);      } -    public void handleRequest(Rpc.Request request, OutputStream out) +    public void handleRequest(Data.Request request, OutputStream out)              throws IOException { -        Service service = registeredServices.get(request.getFullServiceName()); -        final Rpc.Response.Builder response = Rpc.Response.newBuilder(); +        final Service service = registeredServices.get(request.getFullServiceName()); +        Rpc rpc = new Rpc(); +        final Data.Response.Builder response = Data.Response.newBuilder();          response.setRequestId(request.getRequestId());          if (service == null) { -            response.setError(Rpc.Response.Error.UNKNOWN_SERVICE); +            response.setError(Data.Response.RpcError.UNKNOWN_SERVICE);              response.build().writeDelimitedTo(out);              return;          } -        Descriptors.MethodDescriptor method = service.getDescriptorForType() +        final Descriptors.MethodDescriptor method = service.getDescriptorForType()                  .findMethodByName(request.getMethodName());          if (method == null) { -            response.setError(Rpc.Response.Error.UNKNOWN_METHOD); +            response.setError(Data.Response.RpcError.UNKNOWN_METHOD);              response.build().writeDelimitedTo(out);              return;          }          RpcCallback<Message> doneCallback = new RpcCallback<Message>() {              @Override public void run(Message responseMessage) { +                if (responseMessage == null) { +                    responseMessage = service +                            .getResponsePrototype(method) +                            .toBuilder().build(); +                }                  response.setResponseProto(responseMessage.toByteString());              }          }; @@ -79,16 +90,18 @@ public class SimpleProtobufServer extends Thread {                  .toBuilder()                  .mergeFrom(request.getRequestProto())                  .build(); -        service.callMethod(method, null,  requestMessage, doneCallback); +        service.callMethod(method, rpc, requestMessage, doneCallback); +        rpc.writeTo(response);          response.build().writeDelimitedTo(out);      }      private void handleConnection(final Socket connection) {          new Thread(new Runnable() {              @Override public void run() { +                activeClientSockets.add(connection);                  try {                      while (true) { -                        Rpc.Request r1 = Rpc.Request.parseDelimitedFrom( +                        Data.Request r1 = Data.Request.parseDelimitedFrom(                              connection.getInputStream());                          if (r1 == null) {                              try { @@ -106,10 +119,28 @@ public class SimpleProtobufServer extends Thread {                          connection.close();                      } catch (IOException e) {                      } +                    activeClientSockets.remove(connection);                  }              }          }).start();      } +     +    @Override public void interrupt() { +        super.interrupt(); +        for (Socket socket : activeClientSockets) { +            try { +                socket.close(); +            } catch (IOException e) { +                logger.log(Level.WARNING, "Error closing socket.", e); +            } +        } +         +        try { +            serverSocket.close(); +        } catch (IOException e) { +            logger.log(Level.WARNING, "Error closing socket.", e); +        } +    }      public void run() {          logger.info("Running server on port " + serverSocket.getLocalPort()); @@ -122,26 +153,6 @@ public class SimpleProtobufServer extends Thread {                          e);              }          } +        logger.info("Server exits.");      } - -//    public static void main(String[] args) { -//        SimpleProtobufServer server = SimpleProtobufServer.create(10000); -//        Test.TestService testService = new Test.TestService() { -//            @Override public void run(RpcController controller, -//                    Test.TestRequest request, -//                    RpcCallback<Test.TestResponse> done) { -//                System.out.println("Hello from TestService!"); -//                done.run(Test.TestResponse.newBuilder() -//                        .setId("Hello from server.") -//                        .build()); -//            } -//        }; -//        server.registerService(testService); -//        server.start(); -//        try { -//            server.join(); -//        } catch (InterruptedException e) { -//            System.out.println("Stopped."); -//        } -//    }  }  | 
