コード例 #1
0
 public ServiceHolderImpl(@NotNull BlockingService... services) {
   final ImmutableMap.Builder<String, ServiceInfo> builder =
       ImmutableMap.<String, ServiceInfo>builder();
   for (BlockingService service : services) {
     String name = service.getDescriptorForType().getName().toLowerCase();
     ServiceInfo info = new ServiceInfo(new BlockingServiceWrapper(service));
     builder.put(name, info);
   }
   this.services = builder.build();
 }
コード例 #2
0
  private Response forwardToBlockingService(Request rpcRequest, BlockingService blockingService)
      throws RpcException {
    // 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) {
      throw new RpcException(
          ErrorReason.RPC_ERROR, "Error running method " + method.getFullName(), e);
    }
  }
コード例 #3
0
 @Override
 public void callMethod(
     @NotNull Descriptors.MethodDescriptor method,
     @NotNull RpcController controller,
     @NotNull Message request,
     @NotNull RpcCallback<Message> done) {
   try {
     done.run(service.callBlockingMethod(method, controller, request));
   } catch (ServiceException e) {
     log.error("Blocking method error " + method.getFullName(), e);
     done.run(null);
   }
 }
コード例 #4
0
 @NotNull
 @Override
 public Message getResponsePrototype(@NotNull Descriptors.MethodDescriptor method) {
   return service.getResponsePrototype(method);
 }
コード例 #5
0
 @NotNull
 @Override
 public Descriptors.ServiceDescriptor getDescriptorForType() {
   return service.getDescriptorForType();
 }
コード例 #6
0
 /** Register an RPC blocking service implementation to this forwarder. */
 public void registerBlockingService(BlockingService service) {
   blockingServiceMap.put(service.getDescriptorForType().getFullName(), service);
 }