Package com.googlecode.protobuf.socketrpc.RpcConnectionFactory

Examples of com.googlecode.protobuf.socketrpc.RpcConnectionFactory.Connection


      LOG.info("Starting RPC server");
      try {
        running = true;
        while (running) {
          // Thread blocks here waiting for requests
          Connection connection = rpcConnectionFactory.createConnection();
          if (running && !executor.isShutdown()) {
            if (connection.isClosed()) {
              // Connection was closed, don't execute
              try {
                Thread.sleep(100);
              } catch (InterruptedException e) {
                throw new RuntimeException(e);
View Full Code Here


    // Must pass in a SocketRpcController
    final SocketRpcController socketController
        = (SocketRpcController) controller;

    // Send request over connection
    final Connection connection;
    try {
      connection = createConnection(socketController);
    } catch (ServiceException e) {
      // Call done with null, controller has the error information
      callbackWithNull(done);
View Full Code Here

  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);
View Full Code Here

  public void testCreateConnection() throws IOException {
    Request request1 = createRequest(1);
    FakeSocket socket1 = new FakeSocket(true).withRequest(request1);
    fakeSocketFactory.returnsSocket(socket1);
    Connection connection1 = socketServerConnectionFactory.createConnection();

    Request request2 = createRequest(1);
    FakeSocket socket2 = new FakeSocket(true).withRequest(request2);
    fakeSocketFactory.returnsSocket(socket2);
    Connection connection2 = socketServerConnectionFactory.createConnection();

    Request.Builder builder = Request.newBuilder();
    connection1.receiveProtoMessage(builder);
    assertEquals(request1, builder.build());

    builder = Request.newBuilder();
    connection2.receiveProtoMessage(builder);
    assertEquals(request2, builder.build());

    Response response1 = createResponse(1);
    connection1.sendProtoMessage(response1);

    Response response2 = createResponse(2);
    connection2.sendProtoMessage(response2);

    assertEquals(response1, socket1.getResponse());
    assertEquals(response2, socket2.getResponse());
  }
View Full Code Here

  public void testConnectionOutputInput() throws IOException {
    FakeSocket socket = new FakeSocket(true);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    MESSAGE.writeDelimitedTo(os);
    socket.withInputBytes(os.toByteArray());
    Connection connection = connectionForSocket(socket);

    connection.sendProtoMessage(MESSAGE);
    ByteArrayInputStream is = new ByteArrayInputStream(socket.getOutputBytes());
    assertEquals(MESSAGE, Request.parseDelimitedFrom(is));

    Builder builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE, builder.build());
  }
View Full Code Here

  public void testConnectionInputOutput() throws IOException {
    FakeSocket socket = new FakeSocket(true);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    MESSAGE.writeDelimitedTo(os);
    socket.withInputBytes(os.toByteArray());
    Connection connection = connectionForSocket(socket);

    Builder builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE, builder.build());

    connection.sendProtoMessage(MESSAGE);
    ByteArrayInputStream is = new ByteArrayInputStream(socket.getOutputBytes());
    assertEquals(MESSAGE, Request.parseDelimitedFrom(is));
  }
View Full Code Here

  private void doTestClose(FakeSocket socket, boolean isDelimited) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    writeToOutputStream(MESSAGE1, os, isDelimited);
    socket.withInputBytes(os.toByteArray());

    Connection connection = new SocketConnection(socket, isDelimited);
    assertFalse(connection.isClosed());
    connection.close();
    assertTrue(connection.isClosed());
  }
View Full Code Here

      throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    writeToOutputStream(MESSAGE1, os, isDelimited);
    socket.withInputBytes(os.toByteArray());

    Connection connection = new SocketConnection(socket, isDelimited);
    connection.sendProtoMessage(MESSAGE1);
    ByteArrayInputStream is = new ByteArrayInputStream(socket.getOutputBytes());
    assertEquals(MESSAGE1, readFromInputStream(is, isDelimited));

    Builder builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE1, builder.build());
  }
View Full Code Here

      throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    writeToOutputStream(MESSAGE1, os, isDelimited);
    socket.withInputBytes(os.toByteArray());

    Connection connection = new SocketConnection(socket, isDelimited);
    Builder builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE1, builder.build());

    connection.sendProtoMessage(MESSAGE1);
    ByteArrayInputStream is = new ByteArrayInputStream(socket.getOutputBytes());
    assertEquals(MESSAGE1, readFromInputStream(is, isDelimited));
  }
View Full Code Here

    writeToOutputStream(MESSAGE2, os, true);
    writeToOutputStream(MESSAGE1, os, true);
    delimited.withInputBytes(os.toByteArray());

    // Send and receive first
    Connection connection = new SocketConnection(delimited, true);
    connection.sendProtoMessage(MESSAGE2);
    Builder builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE1, builder.build());

    // Receive and send second
    builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE2, builder.build());
    connection.sendProtoMessage(MESSAGE1);

    // Send and receive third
    connection.sendProtoMessage(MESSAGE2);
    builder = Request.newBuilder();
    connection.receiveProtoMessage(builder);
    assertEquals(MESSAGE1, builder.build());

    // Get 3 messages from output
    ByteArrayInputStream is = new ByteArrayInputStream(
        delimited.getOutputBytes());
View Full Code Here

TOP

Related Classes of com.googlecode.protobuf.socketrpc.RpcConnectionFactory.Connection

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.