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


Java Service.callMethod方法代碼示例

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


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

示例1: forwardToService

import com.google.protobuf.Service; //導入方法依賴的package包/類
private void forwardToService(SocketRpcProtos.Request rpcRequest,
    RpcCallback<Message> callback, Service service,
    RpcController socketController) throws RpcException {
  // 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);
  } catch (RuntimeException e) {
    throw new RpcException(ErrorReason.RPC_ERROR,
        "Error running method " + method.getFullName(), e);
  }
}
 
開發者ID:sdeo,項目名稱:protobuf-socket-rpc,代碼行數:20,代碼來源:RpcForwarder.java

示例2: execMasterService

import com.google.protobuf.Service; //導入方法依賴的package包/類
@Override
public ClientProtos.CoprocessorServiceResponse execMasterService(final RpcController controller,
    final ClientProtos.CoprocessorServiceRequest request) throws ServiceException {
  try {
    master.checkInitialized();
    ServerRpcController execController = new ServerRpcController();

    ClientProtos.CoprocessorServiceCall call = request.getCall();
    String serviceName = call.getServiceName();
    String methodName = call.getMethodName();
    if (!master.coprocessorServiceHandlers.containsKey(serviceName)) {
      throw new UnknownProtocolException(null,
        "No registered master coprocessor service found for name "+serviceName);
    }

    Service service = master.coprocessorServiceHandlers.get(serviceName);
    Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
    Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
    if (methodDesc == null) {
      throw new UnknownProtocolException(service.getClass(),
        "Unknown method "+methodName+" called on master service "+serviceName);
    }

    //invoke the method
    Message.Builder builderForType = service.getRequestPrototype(methodDesc).newBuilderForType();
    ProtobufUtil.mergeFrom(builderForType, call.getRequest());
    Message execRequest = builderForType.build();
    final Message.Builder responseBuilder =
        service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, execController, execRequest, new RpcCallback<Message>() {
      @Override
      public void run(Message message) {
        if (message != null) {
          responseBuilder.mergeFrom(message);
        }
      }
    });
    Message execResult = responseBuilder.build();

    if (execController.getFailedOn() != null) {
      throw execController.getFailedOn();
    }
    ClientProtos.CoprocessorServiceResponse.Builder builder =
      ClientProtos.CoprocessorServiceResponse.newBuilder();
    builder.setRegion(RequestConverter.buildRegionSpecifier(
      RegionSpecifierType.REGION_NAME, HConstants.EMPTY_BYTE_ARRAY));
    builder.setValue(
      builder.getValueBuilder().setName(execResult.getClass().getName())
        .setValue(execResult.toByteString()));
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:55,代碼來源:MasterRpcServices.java

示例3: execRegionServerService

import com.google.protobuf.Service; //導入方法依賴的package包/類
public CoprocessorServiceResponse execRegionServerService(
    @SuppressWarnings("UnusedParameters") final RpcController controller,
    final CoprocessorServiceRequest serviceRequest) throws ServiceException {
  try {
    ServerRpcController serviceController = new ServerRpcController();
    CoprocessorServiceCall call = serviceRequest.getCall();
    String serviceName = call.getServiceName();
    String methodName = call.getMethodName();
    if (!coprocessorServiceHandlers.containsKey(serviceName)) {
      throw new UnknownProtocolException(null,
          "No registered coprocessor service found for name " + serviceName);
    }
    Service service = coprocessorServiceHandlers.get(serviceName);
    Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
    Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
    if (methodDesc == null) {
      throw new UnknownProtocolException(service.getClass(),
          "Unknown method " + methodName + " called on service " + serviceName);
    }
    Message.Builder builderForType = service.getRequestPrototype(methodDesc).newBuilderForType();
    ProtobufUtil.mergeFrom(builderForType, call.getRequest());
    Message request = builderForType.build();
    final Message.Builder responseBuilder =
        service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, serviceController, request, new RpcCallback<Message>() {
      @Override public void run(Message message) {
        if (message != null) {
          responseBuilder.mergeFrom(message);
        }
      }
    });
    IOException exception = ResponseConverter.getControllerException(serviceController);
    if (exception != null) {
      throw exception;
    }
    Message execResult = responseBuilder.build();
    ClientProtos.CoprocessorServiceResponse.Builder builder =
        ClientProtos.CoprocessorServiceResponse.newBuilder();
    builder.setRegion(RequestConverter
        .buildRegionSpecifier(RegionSpecifierType.REGION_NAME, HConstants.EMPTY_BYTE_ARRAY));
    builder.setValue(builder.getValueBuilder().setName(execResult.getClass().getName())
        .setValue(execResult.toByteString()));
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:48,代碼來源:HRegionServer.java

示例4: execService

import com.google.protobuf.Service; //導入方法依賴的package包/類
@Override public Message execService(RpcController controller, CoprocessorServiceCall call)
    throws IOException {
  String serviceName = call.getServiceName();
  String methodName = call.getMethodName();
  if (!coprocessorServiceHandlers.containsKey(serviceName)) {
    throw new UnknownProtocolException(null,
        "No registered coprocessor service found for name " + serviceName + " in region " + Bytes
            .toStringBinary(getRegionInfo().getRegionName()));
  }

  Service service = coprocessorServiceHandlers.get(serviceName);
  Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
  Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
  if (methodDesc == null) {
    throw new UnknownProtocolException(service.getClass(),
        "Unknown method " + methodName + " called on service " + serviceName + " in region "
            + Bytes.toStringBinary(getRegionInfo().getRegionName()));
  }

  Message.Builder builder = service.getRequestPrototype(methodDesc).newBuilderForType();
  ProtobufUtil.mergeFrom(builder, call.getRequest());
  Message request = builder.build();

  if (coprocessorHost != null) {
    request = coprocessorHost.preEndpointInvocation(service, methodName, request);
  }

  final Message.Builder responseBuilder =
      service.getResponsePrototype(methodDesc).newBuilderForType();
  service.callMethod(methodDesc, controller, request, new RpcCallback<Message>() {
    @Override public void run(Message message) {
      if (message != null) {
        responseBuilder.mergeFrom(message);
      }
    }
  });

  if (coprocessorHost != null) {
    coprocessorHost.postEndpointInvocation(service, methodName, request, responseBuilder);
  }

  IOException exception = ResponseConverter.getControllerException(controller);
  if (exception != null) {
    throw exception;
  }

  return responseBuilder.build();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:49,代碼來源:HRegion.java

示例5: execMasterService

import com.google.protobuf.Service; //導入方法依賴的package包/類
@Override
public ClientProtos.CoprocessorServiceResponse execMasterService(final RpcController controller,
    final ClientProtos.CoprocessorServiceRequest request) throws ServiceException {
  try {
    master.checkInitialized();
    ServerRpcController execController = new ServerRpcController();

    ClientProtos.CoprocessorServiceCall call = request.getCall();
    String serviceName = call.getServiceName();
    String methodName = call.getMethodName();
    if (!master.coprocessorServiceHandlers.containsKey(serviceName)) {
      throw new UnknownProtocolException(null,
        "No registered master coprocessor service found for name "+serviceName);
    }

    Service service = master.coprocessorServiceHandlers.get(serviceName);
    Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
    Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
    if (methodDesc == null) {
      throw new UnknownProtocolException(service.getClass(),
        "Unknown method "+methodName+" called on master service "+serviceName);
    }

    //invoke the method
    Message execRequest = service.getRequestPrototype(methodDesc).newBuilderForType()
        .mergeFrom(call.getRequest()).build();
    final Message.Builder responseBuilder =
        service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, execController, execRequest, new RpcCallback<Message>() {
      @Override
      public void run(Message message) {
        if (message != null) {
          responseBuilder.mergeFrom(message);
        }
      }
    });
    Message execResult = responseBuilder.build();

    if (execController.getFailedOn() != null) {
      throw execController.getFailedOn();
    }
    ClientProtos.CoprocessorServiceResponse.Builder builder =
      ClientProtos.CoprocessorServiceResponse.newBuilder();
    builder.setRegion(RequestConverter.buildRegionSpecifier(
      RegionSpecifierType.REGION_NAME, HConstants.EMPTY_BYTE_ARRAY));
    builder.setValue(
      builder.getValueBuilder().setName(execResult.getClass().getName())
        .setValue(execResult.toByteString()));
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:54,代碼來源:MasterRpcServices.java

示例6: execRegionServerService

import com.google.protobuf.Service; //導入方法依賴的package包/類
public CoprocessorServiceResponse execRegionServerService(final RpcController controller,
                                                          final CoprocessorServiceRequest serviceRequest) throws ServiceException {
    try {
        ServerRpcController execController = new ServerRpcController();
        CoprocessorServiceCall call = serviceRequest.getCall();
        String serviceName = call.getServiceName();
        String methodName = call.getMethodName();
        if (!coprocessorServiceHandlers.containsKey(serviceName)) {
            throw new UnknownProtocolException(null,
                    "No registered coprocessor service found for name " + serviceName);
        }
        Service service = coprocessorServiceHandlers.get(serviceName);
        Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
        Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
        if (methodDesc == null) {
            throw new UnknownProtocolException(service.getClass(), "Unknown method " + methodName
                    + " called on service " + serviceName);
        }
        Message request =
                service.getRequestPrototype(methodDesc).newBuilderForType().mergeFrom(call.getRequest())
                        .build();
        final Message.Builder responseBuilder =
                service.getResponsePrototype(methodDesc).newBuilderForType();
        service.callMethod(methodDesc, controller, request, new RpcCallback<Message>() {
            @Override
            public void run(Message message) {
                if (message != null) {
                    responseBuilder.mergeFrom(message);
                }
            }
        });
        Message execResult = responseBuilder.build();
        if (execController.getFailedOn() != null) {
            throw execController.getFailedOn();
        }
        ClientProtos.CoprocessorServiceResponse.Builder builder =
                ClientProtos.CoprocessorServiceResponse.newBuilder();
        builder.setRegion(RequestConverter.buildRegionSpecifier(RegionSpecifierType.REGION_NAME,
                HConstants.EMPTY_BYTE_ARRAY));
        builder.setValue(builder.getValueBuilder().setName(execResult.getClass().getName())
                .setValue(execResult.toByteString()));
        return builder.build();
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:47,代碼來源:HRegionServer.java

示例7: execService

import com.google.protobuf.Service; //導入方法依賴的package包/類
/**
 * Executes a single protocol buffer coprocessor endpoint {@link Service} method using
 * the registered protocol handlers.  {@link Service} implementations must be registered via the
 * {@link HRegion#registerService(com.google.protobuf.Service)}
 * method before they are available.
 *
 * @param controller an {@code RpcController} implementation to pass to the invoked service
 * @param call       a {@code CoprocessorServiceCall} instance identifying the service, method,
 *                   and parameters for the method invocation
 * @return a protocol buffer {@code Message} instance containing the method's result
 * @throws IOException if no registered service handler is found or an error
 *                     occurs during the invocation
 * @see org.apache.hadoop.hbase.regionserver.HRegion#registerService(com.google.protobuf.Service)
 */
public Message execService(RpcController controller, CoprocessorServiceCall call)
        throws IOException {
    String serviceName = call.getServiceName();
    String methodName = call.getMethodName();
    if (!coprocessorServiceHandlers.containsKey(serviceName)) {
        throw new UnknownProtocolException(null,
                "No registered coprocessor service found for name " + serviceName +
                        " in region " + Bytes.toStringBinary(getRegionName()));
    }

    Service service = coprocessorServiceHandlers.get(serviceName);
    Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
    Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
    if (methodDesc == null) {
        throw new UnknownProtocolException(service.getClass(),
                "Unknown method " + methodName + " called on service " + serviceName +
                        " in region " + Bytes.toStringBinary(getRegionName()));
    }

    Message request = service.getRequestPrototype(methodDesc).newBuilderForType()
            .mergeFrom(call.getRequest()).build();

    if (coprocessorHost != null) {
        request = coprocessorHost.preEndpointInvocation(service, methodName, request);
    }

    final Message.Builder responseBuilder =
            service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, controller, request, new RpcCallback<Message>() {
        @Override
        public void run(Message message) {
            if (message != null) {
                responseBuilder.mergeFrom(message);
            }
        }
    });

    if (coprocessorHost != null) {
        coprocessorHost.postEndpointInvocation(service, methodName, request, responseBuilder);
    }

    return responseBuilder.build();
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:58,代碼來源:HRegion.java

示例8: execMasterService

import com.google.protobuf.Service; //導入方法依賴的package包/類
@Override
public ClientProtos.CoprocessorServiceResponse execMasterService(final RpcController controller,
    final ClientProtos.CoprocessorServiceRequest request) throws ServiceException {
  try {
    ServerRpcController execController = new ServerRpcController();

    ClientProtos.CoprocessorServiceCall call = request.getCall();
    String serviceName = call.getServiceName();
    String methodName = call.getMethodName();
    if (!coprocessorServiceHandlers.containsKey(serviceName)) {
      throw new UnknownProtocolException(null,
          "No registered master coprocessor service found for name "+serviceName);
    }

    Service service = coprocessorServiceHandlers.get(serviceName);
    Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
    Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
    if (methodDesc == null) {
      throw new UnknownProtocolException(service.getClass(),
          "Unknown method "+methodName+" called on master service "+serviceName);
    }

    //invoke the method
    Message execRequest = service.getRequestPrototype(methodDesc).newBuilderForType()
        .mergeFrom(call.getRequest()).build();
    final Message.Builder responseBuilder =
        service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, execController, execRequest, new RpcCallback<Message>() {
      @Override
      public void run(Message message) {
        if (message != null) {
          responseBuilder.mergeFrom(message);
        }
      }
    });
    Message execResult = responseBuilder.build();

    if (execController.getFailedOn() != null) {
      throw execController.getFailedOn();
    }
    ClientProtos.CoprocessorServiceResponse.Builder builder =
        ClientProtos.CoprocessorServiceResponse.newBuilder();
    builder.setRegion(RequestConverter.buildRegionSpecifier(
        RegionSpecifierType.REGION_NAME, HConstants.EMPTY_BYTE_ARRAY));
    builder.setValue(
        builder.getValueBuilder().setName(execResult.getClass().getName())
            .setValue(execResult.toByteString()));
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:53,代碼來源:HMaster.java

示例9: execService

import com.google.protobuf.Service; //導入方法依賴的package包/類
/**
 * Executes a single protocol buffer coprocessor endpoint {@link Service} method using
 * the registered protocol handlers.  {@link Service} implementations must be registered via the
 * {@link HRegion#registerService(com.google.protobuf.Service)}
 * method before they are available.
 *
 * @param controller an {@code RpcContoller} implementation to pass to the invoked service
 * @param call a {@code CoprocessorServiceCall} instance identifying the service, method,
 *     and parameters for the method invocation
 * @return a protocol buffer {@code Message} instance containing the method's result
 * @throws IOException if no registered service handler is found or an error
 *     occurs during the invocation
 * @see org.apache.hadoop.hbase.regionserver.HRegion#registerService(com.google.protobuf.Service)
 */
public Message execService(RpcController controller, CoprocessorServiceCall call)
    throws IOException {
  String serviceName = call.getServiceName();
  String methodName = call.getMethodName();
  if (!coprocessorServiceHandlers.containsKey(serviceName)) {
    throw new UnknownProtocolException(null,
        "No registered coprocessor service found for name "+serviceName+
        " in region "+Bytes.toStringBinary(getRegionName()));
  }

  Service service = coprocessorServiceHandlers.get(serviceName);
  Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
  Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
  if (methodDesc == null) {
    throw new UnknownProtocolException(service.getClass(),
        "Unknown method "+methodName+" called on service "+serviceName+
            " in region "+Bytes.toStringBinary(getRegionName()));
  }

  Message request = service.getRequestPrototype(methodDesc).newBuilderForType()
      .mergeFrom(call.getRequest()).build();

  if (coprocessorHost != null) {
    request = coprocessorHost.preEndpointInvocation(service, methodName, request);
  }

  final Message.Builder responseBuilder =
      service.getResponsePrototype(methodDesc).newBuilderForType();
  service.callMethod(methodDesc, controller, request, new RpcCallback<Message>() {
    @Override
    public void run(Message message) {
      if (message != null) {
        responseBuilder.mergeFrom(message);
      }
    }
  });

  if (coprocessorHost != null) {
    coprocessorHost.postEndpointInvocation(service, methodName, request, responseBuilder);
  }

  return responseBuilder.build();
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:58,代碼來源:HRegion.java


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