當前位置: 首頁>>代碼示例>>Java>>正文


Java Builder.mergeDelimitedFrom方法代碼示例

本文整理匯總了Java中com.google.protobuf.Message.Builder.mergeDelimitedFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java Builder.mergeDelimitedFrom方法的具體用法?Java Builder.mergeDelimitedFrom怎麽用?Java Builder.mergeDelimitedFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.Message.Builder的用法示例。


在下文中一共展示了Builder.mergeDelimitedFrom方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decode

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)       
    throws Exception {
  ByteBufInputStream in = new ByteBufInputStream(msg);

  RequestHeader.Builder hbuilder = RequestHeader.newBuilder();
  hbuilder.mergeDelimitedFrom(in);
  RequestHeader header = hbuilder.build();

  BlockingService service = RaftRpcService.create().getService();
  
  MethodDescriptor md = service.getDescriptorForType().findMethodByName(header.getRequestName());
  Builder builder = service.getRequestPrototype(md).newBuilderForType();
  Message body = null;
  if (builder != null) {
    if(builder.mergeDelimitedFrom(in)) {
      body = builder.build();
    } else {
      LOG.error("Parsing packet failed!");
    }
  }
  RpcCall call = new RpcCall(header.getId(), header, body, md);
  out.add(call);
}
 
開發者ID:chicm,項目名稱:CmRaft,代碼行數:24,代碼來源:ServerChannelHandler.java

示例2: decode

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)       
    throws Exception {
  
  ByteBufInputStream in = new ByteBufInputStream(msg);

  ResponseHeader.Builder hbuilder = ResponseHeader.newBuilder();
  hbuilder.mergeDelimitedFrom(in);
  ResponseHeader header = hbuilder.build();

  BlockingService service = RaftRpcService.create().getService();
  
  MethodDescriptor md = service.getDescriptorForType().findMethodByName(header.getResponseName());
  Builder builder = service.getResponsePrototype(md).newBuilderForType();
  Message body = null;
  if (builder != null) {
    if(builder.mergeDelimitedFrom(in)) {
      body = builder.build();
    } else {
      LOG.error("Parse packet failed!!");
    }
  }
  RpcCall call = new RpcCall(header.getId(), header, body, md);

  out.add(call);
}
 
開發者ID:chicm,項目名稱:CmRaft,代碼行數:27,代碼來源:ClientChannelHandler.java

示例3: decodeProtobufFromStream

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
/**
 * Decode the a protobuf from the given input stream 
 * @param builder - Builder of the protobuf to decode
 * @param dis - DataInputStream to read the protobuf
 * @return Message - decoded protobuf
 * @throws WrappedRpcServerException - deserialization failed
 */
@SuppressWarnings("unchecked")
private <T extends Message> T decodeProtobufFromStream(Builder builder,
    DataInputStream dis) throws WrappedRpcServerException {
  try {
    builder.mergeDelimitedFrom(dis);
    return (T)builder.build();
  } catch (Exception ioe) {
    Class<?> protoClass = builder.getDefaultInstanceForType().getClass();
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_DESERIALIZING_REQUEST,
        "Error decoding " + protoClass.getSimpleName() + ": "+ ioe);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:21,代碼來源:Server.java

示例4: decode

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)       
    throws Exception {
  //System.out.println("size:" + msg.capacity());
  long t = System.currentTimeMillis();
 // System.out.println("ispooled:" + msg.)
  ByteBufInputStream in = new ByteBufInputStream(msg);

  RequestHeader.Builder hbuilder = RequestHeader.newBuilder();
  hbuilder.mergeDelimitedFrom(in);
  RequestHeader header = hbuilder.build();
  //System.out.println("header:" + header);

  BlockingService service = RaftRpcService.create().getService();
  
  MethodDescriptor md = service.getDescriptorForType().findMethodByName(header.getRequestName());
  Builder builder = service.getRequestPrototype(md).newBuilderForType();
  Message body = null;
  if (builder != null) {
    if(builder.mergeDelimitedFrom(in)) {
      body = builder.build();
      //System.out.println("body parsed");
      
    } else {
      //System.out.println("parse failed");
    }
  }
  RpcCall call = new RpcCall(header.getId(), header, body, md);
  //  System.out.println("Parse Rpc request from socket: " + call.getCallId() 
  //    + ", takes" + (System.currentTimeMillis() -t) + " ms");

  out.add(call);
}
 
開發者ID:chicm,項目名稱:CmRaft,代碼行數:33,代碼來源:TestNettyServer.java

示例5: readResponse

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
protected void readResponse() {
  if (shouldCloseConnection.get()) return;
  Call call = null;
  boolean expectedCall = false;
  try {
    // See HBaseServer.Call.setResponse for where we write out the response.
    // Total size of the response.  Unused.  But have to read it in anyways.
    int totalSize = in.readInt();

    // Read the header
    ResponseHeader responseHeader = ResponseHeader.parseDelimitedFrom(in);
    int id = responseHeader.getCallId();
    call = calls.remove(id); // call.done have to be set before leaving this method
    expectedCall = (call != null && !call.done);
    if (!expectedCall) {
      // So we got a response for which we have no corresponding 'call' here on the client-side.
      // We probably timed out waiting, cleaned up all references, and now the server decides
      // to return a response.  There is nothing we can do w/ the response at this stage. Clean
      // out the wire of the response so its out of the way and we can get other responses on
      // this connection.
      int readSoFar = IPCUtil.getTotalSizeWhenWrittenDelimited(responseHeader);
      int whatIsLeftToRead = totalSize - readSoFar;
      IOUtils.skipFully(in, whatIsLeftToRead);
      return;
    }
    if (responseHeader.hasException()) {
      ExceptionResponse exceptionResponse = responseHeader.getException();
      RemoteException re = createRemoteException(exceptionResponse);
      call.setException(re);
      if (isFatalConnectionException(exceptionResponse)) {
        markClosed(re);
      }
    } else {
      Message value = null;
      if (call.responseDefaultType != null) {
        Builder builder = call.responseDefaultType.newBuilderForType();
        builder.mergeDelimitedFrom(in);
        value = builder.build();
      }
      CellScanner cellBlockScanner = null;
      if (responseHeader.hasCellBlockMeta()) {
        int size = responseHeader.getCellBlockMeta().getLength();
        byte [] cellBlock = new byte[size];
        IOUtils.readFully(this.in, cellBlock, 0, cellBlock.length);
        cellBlockScanner = ipcUtil.createCellScanner(this.codec, this.compressor, cellBlock);
      }
      call.setResponse(value, cellBlockScanner);
    }
  } catch (IOException e) {
    if (expectedCall) call.setException(e);
    if (e instanceof SocketTimeoutException) {
      // Clean up open calls but don't treat this as a fatal condition,
      // since we expect certain responses to not make it by the specified
      // {@link ConnectionId#rpcTimeout}.
      if (LOG.isTraceEnabled()) LOG.trace("ignored", e);
    } else {
      // Treat this as a fatal condition and close this connection
      markClosed(e);
    }
  } finally {
    cleanupCalls(false);
  }
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:64,代碼來源:RpcClientImpl.java

示例6: readResponse

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
protected void readResponse() {
  if (shouldCloseConnection.get()) return;
  touch();
  int totalSize = -1;
  try {
    // See HBaseServer.Call.setResponse for where we write out the response.
    // Total size of the response.  Unused.  But have to read it in anyways.
    totalSize = in.readInt();

    // Read the header
    ResponseHeader responseHeader = ResponseHeader.parseDelimitedFrom(in);
    int id = responseHeader.getCallId();
    if (LOG.isDebugEnabled()) {
      LOG.debug(getName() + ": got response header " +
        TextFormat.shortDebugString(responseHeader) + ", totalSize: " + totalSize + " bytes");
    }
    Call call = calls.get(id);
    if (call == null) {
      // So we got a response for which we have no corresponding 'call' here on the client-side.
      // We probably timed out waiting, cleaned up all references, and now the server decides
      // to return a response.  There is nothing we can do w/ the response at this stage. Clean
      // out the wire of the response so its out of the way and we can get other responses on
      // this connection.
      int readSoFar = IPCUtil.getTotalSizeWhenWrittenDelimited(responseHeader);
      int whatIsLeftToRead = totalSize - readSoFar;
      LOG.debug("Unknown callId: " + id + ", skipping over this response of " +
        whatIsLeftToRead + " bytes");
      IOUtils.skipFully(in, whatIsLeftToRead);
    }
    if (responseHeader.hasException()) {
      ExceptionResponse exceptionResponse = responseHeader.getException();
      RemoteException re = createRemoteException(exceptionResponse);
      if (isFatalConnectionException(exceptionResponse)) {
        markClosed(re);
      } else {
        if (call != null) call.setException(re);
      }
    } else {
      Message value = null;
      // Call may be null because it may have timedout and been cleaned up on this side already
      if (call != null && call.responseDefaultType != null) {
        Builder builder = call.responseDefaultType.newBuilderForType();
        builder.mergeDelimitedFrom(in);
        value = builder.build();
      }
      CellScanner cellBlockScanner = null;
      if (responseHeader.hasCellBlockMeta()) {
        int size = responseHeader.getCellBlockMeta().getLength();
        byte [] cellBlock = new byte[size];
        IOUtils.readFully(this.in, cellBlock, 0, cellBlock.length);
        cellBlockScanner = ipcUtil.createCellScanner(this.codec, this.compressor, cellBlock);
      }
      // it's possible that this call may have been cleaned up due to a RPC
      // timeout, so check if it still exists before setting the value.
      if (call != null) call.setResponse(value, cellBlockScanner);
    }
    if (call != null) calls.remove(id);
  } catch (IOException e) {
    if (e instanceof SocketTimeoutException && remoteId.rpcTimeout > 0) {
      // Clean up open calls but don't treat this as a fatal condition,
      // since we expect certain responses to not make it by the specified
      // {@link ConnectionId#rpcTimeout}.
      closeException = e;
    } else {
      // Treat this as a fatal condition and close this connection
      markClosed(e);
    }
  } finally {
    if (remoteId.rpcTimeout > 0) {
      cleanupCalls(remoteId.rpcTimeout);
    }
  }
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:74,代碼來源:RpcClient.java

示例7: readResponse

import com.google.protobuf.Message.Builder; //導入方法依賴的package包/類
protected void readResponse() {
  if (shouldCloseConnection.get()) return;
  Call call = null;
  boolean expectedCall = false;
  try {
    // See HBaseServer.Call.setResponse for where we write out the response.
    // Total size of the response.  Unused.  But have to read it in anyways.
    int totalSize = in.readInt();

    // Read the header
    ResponseHeader responseHeader = ResponseHeader.parseDelimitedFrom(in);
    int id = responseHeader.getCallId();
    if (LOG.isDebugEnabled()) {
      LOG.debug(getName() + ": got response header " +
        TextFormat.shortDebugString(responseHeader) + ", totalSize: " + totalSize + " bytes");
    }
    call = calls.remove(id); // call.done have to be set before leaving this method
    expectedCall = (call != null && !call.done);
    if (!expectedCall) {
      // So we got a response for which we have no corresponding 'call' here on the client-side.
      // We probably timed out waiting, cleaned up all references, and now the server decides
      // to return a response.  There is nothing we can do w/ the response at this stage. Clean
      // out the wire of the response so its out of the way and we can get other responses on
      // this connection.
      int readSoFar = IPCUtil.getTotalSizeWhenWrittenDelimited(responseHeader);
      int whatIsLeftToRead = totalSize - readSoFar;
      LOG.debug("Unknown callId: " + id + ", skipping over this response of " +
          whatIsLeftToRead + " bytes");
      IOUtils.skipFully(in, whatIsLeftToRead);
    }
    if (responseHeader.hasException()) {
      ExceptionResponse exceptionResponse = responseHeader.getException();
      RemoteException re = createRemoteException(exceptionResponse);
      if (expectedCall) call.setException(re);
      if (isFatalConnectionException(exceptionResponse)) {
        markClosed(re);
      }
    } else {
      Message value = null;
      // Call may be null because it may have timeout and been cleaned up on this side already
      if (expectedCall && call.responseDefaultType != null) {
        Builder builder = call.responseDefaultType.newBuilderForType();
        builder.mergeDelimitedFrom(in);
        value = builder.build();
      }
      CellScanner cellBlockScanner = null;
      if (responseHeader.hasCellBlockMeta()) {
        int size = responseHeader.getCellBlockMeta().getLength();
        byte [] cellBlock = new byte[size];
        IOUtils.readFully(this.in, cellBlock, 0, cellBlock.length);
        cellBlockScanner = ipcUtil.createCellScanner(this.codec, this.compressor, cellBlock);
      }
      // it's possible that this call may have been cleaned up due to a RPC
      // timeout, so check if it still exists before setting the value.
      if (expectedCall) call.setResponse(value, cellBlockScanner);
    }
  } catch (IOException e) {
    if (expectedCall) call.setException(e);
    if (e instanceof SocketTimeoutException) {
      // Clean up open calls but don't treat this as a fatal condition,
      // since we expect certain responses to not make it by the specified
      // {@link ConnectionId#rpcTimeout}.
    } else {
      // Treat this as a fatal condition and close this connection
      markClosed(e);
    }
  } finally {
    cleanupCalls(false);
    if (expectedCall && !call.done) {
      LOG.warn("Coding error: code should be true for callId=" + call.id +
          ", server=" + getRemoteAddress() +
          ", shouldCloseConnection=" + shouldCloseConnection.get());
    }
  }
}
 
開發者ID:shenli-uiuc,項目名稱:PyroDB,代碼行數:76,代碼來源:RpcClient.java


注:本文中的com.google.protobuf.Message.Builder.mergeDelimitedFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。