Package com.google.protobuf

Examples of com.google.protobuf.Message$Builder


      if (t != null) this.isError = true;
      BufferChain bc = null;
      try {
        ResponseHeader.Builder headerBuilder = ResponseHeader.newBuilder();
        // Presume it a pb Message.  Could be null.
        Message result = (Message)m;
        // Call id.
        headerBuilder.setCallId(this.id);
        if (t != null) {
          ExceptionResponse.Builder exceptionBuilder = ExceptionResponse.newBuilder();
          exceptionBuilder.setExceptionClassName(t.getClass().getName());
          exceptionBuilder.setStackTrace(errorMsg);
          exceptionBuilder.setDoNotRetry(t instanceof DoNotRetryIOException);
          if (t instanceof RegionMovedException) {
            // Special casing for this exception.  This is only one carrying a payload.
            // Do this instead of build a generic system for allowing exceptions carry
            // any kind of payload.
            RegionMovedException rme = (RegionMovedException)t;
            exceptionBuilder.setHostname(rme.getHostname());
            exceptionBuilder.setPort(rme.getPort());
          }
          // Set the exception as the result of the method invocation.
          headerBuilder.setException(exceptionBuilder.build());
        }
        ByteBuffer cellBlock =
          ipcUtil.buildCellBlock(this.connection.codec, this.connection.compressionCodec, cells);
        if (cellBlock != null) {
          CellBlockMeta.Builder cellBlockBuilder = CellBlockMeta.newBuilder();
          // Presumes the cellBlock bytebuffer has been flipped so limit has total size in it.
          cellBlockBuilder.setLength(cellBlock.limit());
          headerBuilder.setCellBlockMeta(cellBlockBuilder.build());
        }
        Message header = headerBuilder.build();

        // Organize the response as a set of bytebuffers rather than collect it all together inside
        // one big byte array; save on allocations.
        ByteBuffer bbHeader = IPCUtil.getDelimitedMessageAsByteBuffer(header);
        ByteBuffer bbResult = IPCUtil.getDelimitedMessageAsByteBuffer(result);
View Full Code Here


      if (params[1] == null) {
        throw new ServiceException("null param while calling Method: ["
            + method.getName() + "]");
      }

      Message param = (Message) params[1];
      builder.setRequestProto(param.toByteString());

      rpcRequest = builder.build();
      return rpcRequest;
    }
View Full Code Here

        exception.fillInStackTrace();
        ServiceException se = new ServiceException(exception);
        throw se;
      }
     
      Message prototype = null;
      try {
        prototype = getReturnProtoType(method);
      } catch (Exception e) {
        throw new ServiceException(e);
      }
      Message actualReturnMessage = prototype.newBuilderForType()
          .mergeFrom(response.getResponseProto()).build();
      return actualReturnMessage;
    }
View Full Code Here

      } else {
        Class<?> returnType = method.getReturnType();

        Method newInstMethod = returnType.getMethod("getDefaultInstance");
        newInstMethod.setAccessible(true);
        Message prototype = (Message) newInstMethod.invoke(null,
            (Object[]) null);
        returnTypes.put(method.getName(), prototype);
        return prototype;
      }
    }
View Full Code Here

        String msg = "Unknown method " + methodName + " called on "
            + protocol + " protocol.";
        LOG.warn(msg);
        return handleException(new IOException(msg));
      }
      Message prototype = service.getRequestPrototype(methodDescriptor);
      Message param = prototype.newBuilderForType()
          .mergeFrom(rpcRequest.getRequestProto()).build();
      Message result;
      try {
        result = service.callBlockingMethod(methodDescriptor, null, param);
      } catch (ServiceException e) {
        e.printStackTrace();
        return handleException(e);
View Full Code Here

    if (source instanceof Loop) {
      return ((Loop) source).extract(index, fieldNames);
    }

    if (source instanceof Message) {
      Message m = (Message) source;
      for (FieldDescriptor field : m.getDescriptorForType().getFields()) {
        if (field.getName().equals(fieldNames[index])) {
          return extract(m.getField(field), index + 1, fieldNames);
        }
        if (field.isRepeated() && (field.getName() + "_size").equals(fieldNames[index])) {
          return extract(m.getRepeatedFieldCount(field), index + 1, fieldNames);
        }
        if (field.isRepeated() && (field.getName() + "_list").equals(fieldNames[index])) {
          return extract(m.getField(field), index + 1, fieldNames);
        }
      }
      throw new IllegalArgumentException("Unknown field: " + fieldNames[index]);
    }
View Full Code Here

    // Get matching method
    MethodDescriptor method = getMethod(rpcRequest,
        blockingService.getDescriptorForType());

    // Create request for method
    Message request = getRequestProto(rpcRequest,
        blockingService.getRequestPrototype(method));

    // Call method
    SocketRpcController socketController = new SocketRpcController();
    try {
      Message response = blockingService.callBlockingMethod(method,
          socketController, request);
      return createRpcResponse(response, true, socketController);
    } catch (ServiceException e) {
      throw new RpcException(ErrorReason.RPC_FAILED, e.getMessage(), e);
    } catch (RuntimeException e) {
View Full Code Here

    // Get matching method
    MethodDescriptor method = getMethod(rpcRequest,
        service.getDescriptorForType());

    // Create request for method
    Message request = getRequestProto(rpcRequest,
        service.getRequestPrototype(method));

    // Call method
    try {
      service.callMethod(method, socketController, request, callback);
View Full Code Here

      public void run() {
        try {
          // Thread blocks here until server sends a response
          Response rpcResponse = receiveRpcResponse(socketController,
              connection);
          Message response = handleRpcResponse(responsePrototype, rpcResponse,
              socketController);

          // Callback if failed or server invoked callback
          if (socketController.failed() || rpcResponse.getCallback()) {
            if (done != null) {
View Full Code Here

      status.setRPCPacket(param);
      status.resume("Servicing call");
      //get an instance of the method arg type
      long startTime = System.currentTimeMillis();
      PayloadCarryingRpcController controller = new PayloadCarryingRpcController(cellScanner);
      Message result = service.callBlockingMethod(md, controller, param);
      int processingTime = (int) (System.currentTimeMillis() - startTime);
      int qTime = (int) (startTime - receiveTime);
      if (LOG.isTraceEnabled()) {
        LOG.trace(CurCall.get().toString() +
            ", response " + TextFormat.shortDebugString(result) +
            " queueTime: " + qTime +
            " processingTime: " + processingTime);
      }
      metrics.dequeuedCall(qTime);
      metrics.processedCall(processingTime);
      long responseSize = result.getSerializedSize();
      // log any RPC responses that are slower than the configured warn
      // response time or larger than configured warning size
      boolean tooSlow = (processingTime > warnResponseTime && warnResponseTime > -1);
      boolean tooLarge = (responseSize > warnResponseSize && warnResponseSize > -1);
      if (tooSlow || tooLarge) {
View Full Code Here

TOP

Related Classes of com.google.protobuf.Message$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.