/**
   * Handle the receipt of the OOB response.
   *
   * @param msg the out-of-band response
   * @return true the message processed, null if none processed.
   */
  public Message receiveOobResponse(OobResponse msg) {
    if (msg.getCorrelationId() != correlationId) {
      // only possible with race condition on client reset and re-use when a server message
      // comes back
      log.info(
          "Correlation mismatch client "
              + correlationId
              + " OobResponse "
              + msg.getCorrelationId());

      return null; // don't process the server message anymore in this case.
    }
    if (onOobResponsePrototype != null && onOobResponseFunction != null) {
      Message onMsg = null;
      try {
        onMsg = onOobResponsePrototype.newBuilderForType().mergeFrom(msg.getMessageBytes()).build();

        onOobResponseFunction.run(onMsg);

        return onMsg;
      } catch (InvalidProtocolBufferException e) {
        String errorMessage = "Invalid OobResponse Protobuf for correlationId " + correlationId;

        log.warn(errorMessage, e);
      }

    } else {
      if (log.isDebugEnabled()) {
        log.debug("No onOobResponseCallbackFunction registered for correlationId " + correlationId);
      }
    }
    return null;
  }
 /** Get request protobuf for the RPC method. */
 private Message getRequestProto(SocketRpcProtos.Request rpcRequest, Message requestPrototype)
     throws RpcException {
   Message.Builder builder;
   try {
     builder = requestPrototype.newBuilderForType().mergeFrom(rpcRequest.getRequestProto());
     if (!builder.isInitialized()) {
       throw new RpcException(ErrorReason.BAD_REQUEST_PROTO, "Invalid request proto", null);
     }
   } catch (InvalidProtocolBufferException e) {
     throw new RpcException(ErrorReason.BAD_REQUEST_PROTO, "Invalid request proto", e);
   }
   return builder.build();
 }
Пример #3
0
 /**
  * Decodes protobuf messages of given type from buffer. If not enough data has been presented
  * delegates to the {@link CumulativeProtocolDecoder} base class to read more data from the wire.
  *
  * <p>It uses instance of internal {@link SizeContext} class to calculate size of buffer expected
  * by the given type of message. The size of every message that arrives on the wire is specified
  * by the prepending varint value.
  *
  * @param session The session used to store internal {@link SizeContext}.
  * @param in The buffer used to read messages if contains enough data.
  * @param out The output for messages decoded from data provided.
  * @see ProtobufEncoder
  * @see SizeContext
  */
 @Override
 protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)
     throws Exception {
   SizeContext ctx = SizeContext.get(session, in);
   if (ctx.hasEnoughData(in)) {
     try {
       Message.Builder builder = prototype.newBuilderForType();
       ctx.getInputStream(in).readMessage(builder, extentions);
       out.write(builder.build());
       return true;
     } finally {
       ctx.shiftPositionAndReset(session, in);
     }
   }
   return false;
 }