Java 类com.google.protobuf.Descriptors.MethodDescriptor 实例源码

项目:ditb    文件:RpcServer.java   
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH",
    justification="Can't figure why this complaint is happening... see below")
Call(int id, final BlockingService service, final MethodDescriptor md, RequestHeader header,
     Message param, CellScanner cellScanner, Connection connection, Responder responder,
     long size, TraceInfo tinfo, final InetAddress remoteAddress) {
  this.id = id;
  this.service = service;
  this.md = md;
  this.header = header;
  this.param = param;
  this.cellScanner = cellScanner;
  this.connection = connection;
  this.timestamp = System.currentTimeMillis();
  this.response = null;
  this.responder = responder;
  this.isError = false;
  this.size = size;
  this.tinfo = tinfo;
  this.user = connection == null? null: connection.user; // FindBugs: NP_NULL_ON_SOME_PATH
  this.remoteAddress = remoteAddress;
  this.retryImmediatelySupported =
      connection == null? null: connection.retryImmediatelySupported;
}
项目:ditb    文件:TestRpcHandlerException.java   
@Ignore
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
  PriorityFunction qosFunction = mock(PriorityFunction.class);
  Abortable abortable = new AbortServer();
  RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0);
  RpcServer rpcServer = new TestRpcServer(scheduler);
  RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT);
  try {
    rpcServer.start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    PayloadCarryingRpcController controller =
        new PayloadCarryingRpcController(CellUtil.createCellScanner(ImmutableList.of(CELL)));
    InetSocketAddress address = rpcServer.getListenerAddress();
    if (address == null) {
      throw new IOException("Listener channel is closed");
    }
    client.call(controller, md, param, md.getOutputType().toProto(), User.getCurrent(),
        address, new MetricsConnection.CallStats());
  } catch (Throwable e) {
    assert(abortable.isAborted() == true);
  } finally {
    rpcServer.stop();
  }
}
项目:ditb    文件:AbstractTestIPC.java   
/**
 * Ensure we do not HAVE TO HAVE a codec.
 * @throws InterruptedException
 * @throws IOException
 */
@Test
public void testNoCodec() throws InterruptedException, IOException {
  Configuration conf = HBaseConfiguration.create();
  AbstractRpcClient client = createRpcClientNoCodec(conf);
  TestRpcServer rpcServer = new TestRpcServer();
  try {
    rpcServer.start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    final String message = "hello";
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage(message).build();
    InetSocketAddress address = rpcServer.getListenerAddress();
    if (address == null) {
      throw new IOException("Listener channel is closed");
    }
    Pair<Message, CellScanner> r =
        client.call(null, md, param, md.getOutputType().toProto(), User.getCurrent(), address,
            new MetricsConnection.CallStats());
    assertTrue(r.getSecond() == null);
    // Silly assertion that the message is in the returned pb.
    assertTrue(r.getFirst().toString().contains(message));
  } finally {
    client.close();
    rpcServer.stop();
  }
}
项目:ditb    文件:AbstractTestIPC.java   
@Test
public void testRTEDuringConnectionSetup() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  TestRpcServer rpcServer = new TestRpcServer();
  AbstractRpcClient client = createRpcClientRTEDuringConnectionSetup(conf);
  try {
    rpcServer.start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    InetSocketAddress address = rpcServer.getListenerAddress();
    if (address == null) {
      throw new IOException("Listener channel is closed");
    }
    client.call(null, md, param, null, User.getCurrent(), address,
        new MetricsConnection.CallStats());
    fail("Expected an exception to have been thrown!");
  } catch (Exception e) {
    LOG.info("Caught expected exception: " + e.toString());
    assertTrue(StringUtils.stringifyException(e).contains("Injected fault"));
  } finally {
    client.close();
    rpcServer.stop();
  }
}
项目:Okra-Ax    文件:GpbMessageContext.java   
public void registerGpbMsgDesc(FileDescriptor fileDescriptor) {
    if (fileDescriptor == null) return;
    //  service
    for (ServiceDescriptor service : fileDescriptor.getServices()) {
        for (MethodDescriptor method : service.getMethods()) {
            if (gpbMsgDescMap.containsKey(method.getName())) {
                LOG.error("[Gpb] the method [" + method.getName() + "] already registered.");
            }
            registerGpbMessage(method.getInputType());
            methodInputTypeMap.put(method.getName(), method.getInputType().getName());
        }
    }
    //  message
    for (Descriptor descriptor : fileDescriptor.getMessageTypes()) {
        registerGpbMessage(descriptor);
    }
}
项目:Okra-Ax    文件:GpbMessageDescTest.java   
@Test
public void testUnpack() throws InvalidProtocolBufferException {
    for (Descriptors.ServiceDescriptor serviceDescriptor : FyChessSi.getDescriptor().getServices()) {
        MethodDescriptor methodByName = serviceDescriptor.findMethodByName("onEnterRoom");
        if (methodByName != null) {
            GpbMessageDesc method = new GpbMessageDesc(methodByName);
            //
            VoEnterRoom message = VoEnterRoom.newBuilder()
                    .setRoomId(999)
                    .setSeat(8)
                    .build();
            Message unpack = method.unpack(message.toByteString());
            Message pack = method.pack(new Object[]{
                    999, 8, 10001L, "xx"
            });
            System.out.println();

        }
    }


}
项目:protobuf-socket-rpc    文件:RpcForwarder.java   
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);
  }
}
项目:protobuf-socket-rpc    文件:RpcChannelImpl.java   
@Override
public Message callBlockingMethod(MethodDescriptor method,
    RpcController controller, Message request, Message responsePrototype)
    throws ServiceException {
  // Must pass in a SocketRpcController
  SocketRpcController socketController = (SocketRpcController) controller;
  final Connection connection = createConnection(socketController);
  try {
    sendRpcRequest(method, socketController, request, connection);
    Response rpcResponse = receiveRpcResponse(socketController, connection);
    return handleRpcResponse(responsePrototype, rpcResponse,
        socketController);
  } finally {
    close(connection);
  }
}
项目:protobuf-socket-rpc    文件:RpcChannelImpl.java   
private void sendRpcRequest(MethodDescriptor method,
    SocketRpcController socketController, Message request,
    Connection connection) throws ServiceException {
  // Check request
  if (!request.isInitialized()) {
    handleError(socketController, ErrorReason.INVALID_REQUEST_PROTO,
        "Request is uninitialized", null);
  }

  // Create RPC request protobuf
  SocketRpcProtos.Request rpcRequest = SocketRpcProtos.Request.newBuilder()
      .setRequestProto(request.toByteString())
      .setServiceName(method.getService().getFullName())
      .setMethodName(method.getName())
      .build();

  // Send request
  try {
    connection.sendProtoMessage(rpcRequest);
  } catch (IOException e) {
    handleError(socketController, ErrorReason.IO_ERROR, String.format(
        "Error writing over connection %s", connection), e);
  }
}
项目:pbase    文件:RpcServer.java   
Call(int id, final BlockingService service, final MethodDescriptor md, RequestHeader header,
     Message param, CellScanner cellScanner, Connection connection, Responder responder,
     long size, TraceInfo tinfo) {
  this.id = id;
  this.service = service;
  this.md = md;
  this.header = header;
  this.param = param;
  this.cellScanner = cellScanner;
  this.connection = connection;
  this.timestamp = System.currentTimeMillis();
  this.response = null;
  this.delayResponse = false;
  this.responder = responder;
  this.isError = false;
  this.size = size;
  this.tinfo = tinfo;
}
项目:pbase    文件:TestRpcHandlerException.java   
@Ignore
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
  PriorityFunction qosFunction = mock(PriorityFunction.class);
  Abortable abortable = new AbortServer();
  RpcScheduler scheduler = new SimpleRpcScheduler(CONF, 2, 0, 0, qosFunction, abortable, 0);
  RpcServer rpcServer = new TestRpcServer(scheduler);
  RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT);
  try {
    rpcServer.start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    client.call(null, md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)), md
      .getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0);
  } catch (Throwable e) {
    assert(abortable.isAborted() == true);
  } finally {
    rpcServer.stop();
  }
}
项目:pbase    文件:TestIPC.java   
private void doSimpleTest(final Configuration conf, final RpcClientImpl client)
throws InterruptedException, IOException {
  TestRpcServer rpcServer = new TestRpcServer();
  List<Cell> cells = new ArrayList<Cell>();
  int count = 3;
  for (int i = 0; i < count; i++) cells.add(CELL);
  try {
    rpcServer.start();
    InetSocketAddress address = rpcServer.getListenerAddress();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    Pair<Message, CellScanner> r = client.call(null, md, param, CellUtil.createCellScanner(cells),
      md.getOutputType().toProto(), User.getCurrent(), address, 0);
    int index = 0;
    while (r.getSecond().advance()) {
      assertTrue(CELL.equals(r.getSecond().current()));
      index++;
    }
    assertEquals(count, index);
  } finally {
    client.close();
    rpcServer.stop();
  }
}
项目:pbase    文件:TestIPC.java   
/** Tests that the rpc scheduler is called when requests arrive. */
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
  RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1));
  RpcServer rpcServer = new TestRpcServer(scheduler);
  verify(scheduler).init((RpcScheduler.Context) anyObject());
  RpcClientImpl client = new RpcClientImpl(CONF, HConstants.CLUSTER_ID_DEFAULT);
  try {
    rpcServer.start();
    verify(scheduler).start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    for (int i = 0; i < 10; i++) {
      client.call(null, md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)),
          md.getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0);
    }
    verify(scheduler, times(10)).dispatch((CallRunner) anyObject());
  } finally {
    rpcServer.stop();
    verify(scheduler).stop();
  }
}
项目:vsminecraft    文件:ServiceTest.java   
public void testNewReflectiveBlockingService() throws ServiceException {
  ServiceWithNoOuter.BlockingInterface impl =
      control.createMock(ServiceWithNoOuter.BlockingInterface.class);
  RpcController controller = control.createMock(RpcController.class);
  BlockingService service =
      ServiceWithNoOuter.newReflectiveBlockingService(impl);

  MethodDescriptor fooMethod =
      ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
  MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();

  TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
  EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
      .andReturn(expectedResponse);

  control.replay();

  Message response =
      service.callBlockingMethod(fooMethod, controller, request);
  assertEquals(expectedResponse, response);

  control.verify();
}
项目:HIndex    文件:RpcServer.java   
Call(int id, final BlockingService service, final MethodDescriptor md, RequestHeader header,
     Message param, CellScanner cellScanner, Connection connection, Responder responder,
     long size, TraceInfo tinfo) {
  this.id = id;
  this.service = service;
  this.md = md;
  this.header = header;
  this.param = param;
  this.cellScanner = cellScanner;
  this.connection = connection;
  this.timestamp = System.currentTimeMillis();
  this.response = null;
  this.delayResponse = false;
  this.responder = responder;
  this.isError = false;
  this.size = size;
  this.tinfo = tinfo;
}
项目:HIndex    文件:TestIPC.java   
private void doSimpleTest(final Configuration conf, final RpcClient client)
throws InterruptedException, IOException {
  TestRpcServer rpcServer = new TestRpcServer();
  List<Cell> cells = new ArrayList<Cell>();
  int count = 3;
  for (int i = 0; i < count; i++) cells.add(CELL);
  try {
    rpcServer.start();
    InetSocketAddress address = rpcServer.getListenerAddress();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    Pair<Message, CellScanner> r = client.call(md, param, CellUtil.createCellScanner(cells),
      md.getOutputType().toProto(), User.getCurrent(), address, 0);
    int index = 0;
    while (r.getSecond().advance()) {
      assertTrue(CELL.equals(r.getSecond().current()));
      index++;
    }
    assertEquals(count, index);
  } finally {
    client.stop();
    rpcServer.stop();
  }
}
项目:HIndex    文件:TestIPC.java   
/** Tests that the rpc scheduler is called when requests arrive. */
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
  RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1));
  RpcServer rpcServer = new TestRpcServer(scheduler);
  verify(scheduler).init((RpcScheduler.Context) anyObject());
  RpcClient client = new RpcClient(CONF, HConstants.CLUSTER_ID_DEFAULT);
  try {
    rpcServer.start();
    verify(scheduler).start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    for (int i = 0; i < 10; i++) {
      client.call(md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)),
          md.getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0);
    }
    verify(scheduler, times(10)).dispatch((CallRunner) anyObject());
  } finally {
    rpcServer.stop();
    verify(scheduler).stop();
  }
}
项目:armeria    文件:GrpcDocServicePlugin.java   
@VisibleForTesting
MethodInfo newMethodInfo(MethodDescriptor method, ServiceEntry service) {
    Set<EndpointInfo> methodEndpoints =
            service.endpointInfos.stream()
                                 .map(e -> new EndpointInfo(
                                         e.hostnamePattern(),
                                         e.path() + method.getName(),
                                         e.fragment(),
                                         e.defaultMimeType(),
                                         e.availableMimeTypes()))
                                 .collect(toImmutableSet());
    return new MethodInfo(
            method.getName(),
            namedMessageSignature(method.getOutputType()),
            // gRPC methods always take a single request parameter of message type.
            ImmutableList.of(
                    new FieldInfo(
                            "request",
                            FieldRequirement.REQUIRED,
                            namedMessageSignature(method.getInputType()))),
            ImmutableList.of(),
            methodEndpoints);
}
项目:coyote    文件:ProtobufServiceTranslator.java   
public RpcRequestResponse translate(MethodDescriptor method, Message message,
    StreamCarryingRpcController controller) {
  // first convert the request to an RPC request
  Rpc.Builder msg = makeHeader(method.getName());
  // add the request to the header
  GeneratedExtension<Rpc, Message> extension = extensions.getExtension(message);
  msg.setExtension(extension, message);

  // then create the actual rpc that will be sent
  RpcRequestResponse rpc = new RpcRequestResponse(msg);
  if (controller != null && controller.getOutboundTrailer() != null) {
    rpc.setData(controller.getOutboundTrailer(), controller.getOutboundTrailerLength());
  }

  return rpc;
}
项目:tajo    文件:BlockingRpcClient.java   
@Override
public Message callBlockingMethod(final MethodDescriptor method,
                                  final RpcController controller,
                                  final Message param,
                                  final Message responsePrototype)
    throws TajoServiceException {

  int nextSeqId = sequence.getAndIncrement();
  RpcProtos.RpcRequest rpcRequest = buildRequest(nextSeqId, method, param);
  ProtoCallFuture callFuture = new ProtoCallFuture(controller, responsePrototype);

  invoke(rpcRequest, callFuture, 0);

  try {
    return callFuture.get();
  } catch (Throwable t) {
    if (t instanceof ExecutionException) {
      Throwable cause = t.getCause();
      if (cause != null && cause instanceof TajoServiceException) {
        throw (TajoServiceException) cause;
      }
    }
    throw new TajoServiceException(t.getMessage());
  }
}
项目:grpc-java    文件:ProtoReflectionService.java   
private void processService(ServiceDescriptor service, FileDescriptor fd) {
  String serviceName = service.getFullName();
  checkState(
      !fileDescriptorsBySymbol.containsKey(serviceName),
      "Service already defined: %s",
      serviceName);
  fileDescriptorsBySymbol.put(serviceName, fd);
  for (MethodDescriptor method : service.getMethods()) {
    String methodName = method.getFullName();
    checkState(
        !fileDescriptorsBySymbol.containsKey(methodName),
        "Method already defined: %s",
        methodName);
    fileDescriptorsBySymbol.put(methodName, fd);
  }
}
项目:hbase    文件:RegionServerCoprocessorRpcChannelImpl.java   
private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request,
    Message responsePrototype, HBaseRpcController controller, ClientService.Interface stub) {
  CompletableFuture<Message> future = new CompletableFuture<>();
  CoprocessorServiceRequest csr =
      CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  stub.execRegionServerService(
    controller,
    csr,
    new org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<CoprocessorServiceResponse>() {

      @Override
      public void run(CoprocessorServiceResponse resp) {
        if (controller.failed()) {
          future.completeExceptionally(controller.getFailed());
        } else {
          try {
            future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
          } catch (IOException e) {
            future.completeExceptionally(e);
          }
        }
      }
    });
  return future;
}
项目:hbase    文件:MasterCoprocessorRpcChannelImpl.java   
private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request,
    Message responsePrototype, HBaseRpcController controller, MasterService.Interface stub) {
  CompletableFuture<Message> future = new CompletableFuture<>();
  CoprocessorServiceRequest csr =
      CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
  stub.execMasterService(
    controller,
    csr,
    new org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<CoprocessorServiceResponse>() {

      @Override
      public void run(CoprocessorServiceResponse resp) {
        if (controller.failed()) {
          future.completeExceptionally(controller.getFailed());
        } else {
          try {
            future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
          } catch (IOException e) {
            future.completeExceptionally(e);
          }
        }
      }
    });
  return future;
}
项目:incubator-tajo    文件:BlockingRpcClient.java   
public Message callBlockingMethod(final MethodDescriptor method,
                                  final RpcController controller,
                                  final Message param,
                                  final Message responsePrototype)
    throws ServiceException {

  int nextSeqId = sequence.getAndIncrement();

  Message rpcRequest = buildRequest(nextSeqId, method, param);

  ProtoCallFuture callFuture =
      new ProtoCallFuture(controller, responsePrototype);
  requests.put(nextSeqId, callFuture);
  getChannel().write(rpcRequest);

  try {
    return callFuture.get();
  } catch (Throwable t) {
    if(t instanceof ExecutionException) {
      ExecutionException ee = (ExecutionException)t;
      throw new ServiceException(ee.getCause());
    } else {
      throw new RemoteException(t);
    }
  }
}
项目:tajo-cdh    文件:BlockingRpcClient.java   
public Message callBlockingMethod(final MethodDescriptor method,
                                  final RpcController controller,
                                  final Message param,
                                  final Message responsePrototype)
    throws ServiceException {

  int nextSeqId = sequence.getAndIncrement();

  Message rpcRequest = buildRequest(nextSeqId, method, param);

  ProtoCallFuture callFuture =
      new ProtoCallFuture(controller, responsePrototype);
  requests.put(nextSeqId, callFuture);
  getChannel().write(rpcRequest);

  try {
    return callFuture.get();
  } catch (Throwable t) {
    if(t instanceof ExecutionException) {
      ExecutionException ee = (ExecutionException)t;
      throw new ServiceException(ee.getCause());
    } else {
      throw new RemoteException(t);
    }
  }
}
项目:PyroDB    文件:RpcServer.java   
Call(int id, final BlockingService service, final MethodDescriptor md, RequestHeader header,
     Message param, CellScanner cellScanner, Connection connection, Responder responder,
     long size, TraceInfo tinfo) {
  this.id = id;
  this.service = service;
  this.md = md;
  this.header = header;
  this.param = param;
  this.cellScanner = cellScanner;
  this.connection = connection;
  this.timestamp = System.currentTimeMillis();
  this.response = null;
  this.delayResponse = false;
  this.responder = responder;
  this.isError = false;
  this.size = size;
  this.tinfo = tinfo;
}
项目:PyroDB    文件:TestIPC.java   
private void doSimpleTest(final Configuration conf, final RpcClient client)
throws InterruptedException, IOException {
  TestRpcServer rpcServer = new TestRpcServer();
  List<Cell> cells = new ArrayList<Cell>();
  int count = 3;
  for (int i = 0; i < count; i++) cells.add(CELL);
  try {
    rpcServer.start();
    InetSocketAddress address = rpcServer.getListenerAddress();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    Pair<Message, CellScanner> r = client.call(md, param, CellUtil.createCellScanner(cells),
      md.getOutputType().toProto(), User.getCurrent(), address, 0);
    int index = 0;
    while (r.getSecond().advance()) {
      assertTrue(CELL.equals(r.getSecond().current()));
      index++;
    }
    assertEquals(count, index);
  } finally {
    client.stop();
    rpcServer.stop();
  }
}
项目:PyroDB    文件:TestIPC.java   
/** Tests that the rpc scheduler is called when requests arrive. */
@Test
public void testRpcScheduler() throws IOException, InterruptedException {
  RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1));
  RpcServer rpcServer = new TestRpcServer(scheduler);
  verify(scheduler).init((RpcScheduler.Context) anyObject());
  RpcClient client = new RpcClient(CONF, HConstants.CLUSTER_ID_DEFAULT);
  try {
    rpcServer.start();
    verify(scheduler).start();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    for (int i = 0; i < 10; i++) {
      client.call(md, param, CellUtil.createCellScanner(ImmutableList.of(CELL)),
          md.getOutputType().toProto(), User.getCurrent(), rpcServer.getListenerAddress(), 0);
    }
    verify(scheduler, times(10)).dispatch((CallRunner) anyObject());
  } finally {
    rpcServer.stop();
    verify(scheduler).stop();
  }
}
项目:PyroDB    文件:RpcClient.java   
@Override
public Message callBlockingMethod(MethodDescriptor md, RpcController controller,
                                  Message param, Message returnType) throws ServiceException {
  PayloadCarryingRpcController pcrc;
  if (controller != null) {
    pcrc = (PayloadCarryingRpcController) controller;
    if (!pcrc.hasCallTimeout()){
      pcrc.setCallTimeout(defaultOperationTimeout);
    }
  } else {
    pcrc =  new PayloadCarryingRpcController();
    pcrc.setCallTimeout(defaultOperationTimeout);
  }

  return this.rpcClient.callBlockingMethod(md, pcrc, param, returnType, this.ticket, this.isa);
}
项目:NeverwinterDP-Commons    文件:RPCChannelClient.java   
public Message callBlockingMethod(MethodDescriptor method, RpcController controller,
                                  Message request, Message responsePrototype) throws ServiceException {
  Request.Builder requestB = Request.newBuilder();
  requestB.setServiceId(method.getService().getFullName()) ;
  requestB.setMethodId(method.getName()) ;
  requestB.setParams(request.toByteString()) ;
  //System.out.println("Response: " + response) ;
  try {
    Response response = client.call(requestB.build());
    if(response.hasError()) {
      //System.out.println("Remote Service Error");
      //System.out.println("  message:    " + response.getError().getMessage());
      //System.out.println("  stacktrace: " + response.getError().getStacktrace());
      throw new ServiceException("Remote Service Error: " + response.getError().getMessage()) ;
    }
    Message ret = responsePrototype.getParserForType().parseFrom(response.getResult()) ;
    return ret ;
  } catch (Exception e) {
    throw new ServiceException(e) ;
  }
}
项目:bazel    文件:ServiceTest.java   
public void testNewReflectiveBlockingService() throws ServiceException {
  ServiceWithNoOuter.BlockingInterface impl =
      control.createMock(ServiceWithNoOuter.BlockingInterface.class);
  RpcController controller = control.createMock(RpcController.class);
  BlockingService service =
      ServiceWithNoOuter.newReflectiveBlockingService(impl);

  MethodDescriptor fooMethod =
      ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
  MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();

  TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
  EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
      .andReturn(expectedResponse);

  control.replay();

  Message response =
      service.callBlockingMethod(fooMethod, controller, request);
  assertEquals(expectedResponse, response);

  control.verify();
}
项目:c5    文件:RpcServer.java   
Call(int id, final BlockingService service, final MethodDescriptor md, Message param,
    CellScanner cellScanner, Connection connection, Responder responder, long size,
    TraceInfo tinfo) {
  this.id = id;
  this.service = service;
  this.md = md;
  this.param = param;
  this.cellScanner = cellScanner;
  this.connection = connection;
  this.timestamp = System.currentTimeMillis();
  this.response = null;
  this.delayResponse = false;
  this.responder = responder;
  this.isError = false;
  this.size = size;
  this.tinfo = tinfo;
}
项目:c5    文件:TestIPC.java   
private void doSimpleTest(final Configuration conf, final RpcClient client)
throws InterruptedException, IOException {
  TestRpcServer rpcServer = new TestRpcServer();
  List<Cell> cells = new ArrayList<Cell>();
  int count = 3;
  for (int i = 0; i < count; i++) cells.add(CELL);
  try {
    rpcServer.start();
    InetSocketAddress address = rpcServer.getListenerAddress();
    MethodDescriptor md = SERVICE.getDescriptorForType().findMethodByName("echo");
    EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build();
    Pair<Message, CellScanner> r = client.call(md, param, CellUtil.createCellScanner(cells),
      md.getOutputType().toProto(), User.getCurrent(), address, 0);
    int index = 0;
    while (r.getSecond().advance()) {
      assertTrue(CELL.equals(r.getSecond().current()));
      index++;
    }
    assertEquals(count, index);
  } finally {
    client.stop();
    rpcServer.stop();
  }
}
项目:CmRaft    文件:ServerChannelHandler.java   
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);
}
项目:CmRaft    文件:ClientChannelHandler.java   
@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);
}
项目:bazel    文件:ServiceTest.java   
public void testNewReflectiveBlockingService() throws ServiceException {
  ServiceWithNoOuter.BlockingInterface impl =
      control.createMock(ServiceWithNoOuter.BlockingInterface.class);
  RpcController controller = control.createMock(RpcController.class);
  BlockingService service =
      ServiceWithNoOuter.newReflectiveBlockingService(impl);

  MethodDescriptor fooMethod =
      ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
  MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();

  TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
  EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
      .andReturn(expectedResponse);

  control.replay();

  Message response =
      service.callBlockingMethod(fooMethod, controller, request);
  assertEquals(expectedResponse, response);

  control.verify();
}
项目:sstore-soft    文件:ThreadChannel.java   
@Override
    public void callMethod(MethodDescriptor method, RpcController controller,
            Message request, Message responsePrototype,
            RpcCallback<Message> done) {
//        System.out.println("added task to thread");
        inputQueue.add(new TableTask(method, request, done));
    }
项目:sstore-soft    文件:ServiceRegistry.java   
public void register(Service service) {
    // TODO: Support registering multiple local services? Needs "local 2PC" effectively. Yuck.
    Descriptors.ServiceDescriptor descriptor = service.getDescriptorForType();
    for (MethodDescriptor i : descriptor.getMethods()) {
        if (methods.containsKey(i.getFullName())) {
            throw new IllegalStateException(
                    "method " + i.getFullName() + " is already registered");
        }
        methods.put(i.getFullName(), new ProtoMethodInvoker(service, i));
    }
}
项目:sstore-soft    文件:ServiceTest.java   
public void testNewReflectiveService() {
  ServiceWithNoOuter.Interface impl =
      control.createMock(ServiceWithNoOuter.Interface.class);
  RpcController controller = control.createMock(RpcController.class);
  Service service = ServiceWithNoOuter.newReflectiveService(impl);

  MethodDescriptor fooMethod =
      ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
  MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
  RpcCallback<Message> callback = new RpcCallback<Message>() {
    public void run(Message parameter) {
      // No reason this should be run.
      fail();
    }
  };
  RpcCallback<TestAllTypes> specializedCallback =
      RpcUtil.specializeCallback(callback);

  impl.foo(EasyMock.same(controller), EasyMock.same(request),
      EasyMock.same(specializedCallback));
  EasyMock.expectLastCall();

  control.replay();

  service.callMethod(fooMethod, controller, request, callback);

  control.verify();
}
项目:sstore-soft    文件:ServiceTest.java   
public void testNewReflectiveBlockingService() throws ServiceException {
  ServiceWithNoOuter.BlockingInterface impl =
      control.createMock(ServiceWithNoOuter.BlockingInterface.class);
  RpcController controller = control.createMock(RpcController.class);
  BlockingService service =
      ServiceWithNoOuter.newReflectiveBlockingService(impl);

  MethodDescriptor fooMethod =
      ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
  MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
  RpcCallback<Message> callback = new RpcCallback<Message>() {
    public void run(Message parameter) {
      // No reason this should be run.
      fail();
    }
  };

  TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
  EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
      .andReturn(expectedResponse);

  control.replay();

  Message response =
      service.callBlockingMethod(fooMethod, controller, request);
  assertEquals(expectedResponse, response);

  control.verify();
}