Class NonblockingSocketClientHandler

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, PServiceCallHandler

    public class NonblockingSocketClientHandler
    extends java.lang.Object
    implements PServiceCallHandler, java.io.Closeable
    Client handler for thrift RPC using the TNonblockingServer, or similar that uses the TFramedTransport message wrapper. It is able to handle a true async-like message and response order, so even if the server sends responses out of order this client will match to the correct caller. The client handler is dependent on that there is a single client with unique sequence IDs on incoming service calls, otherwise there will be trouble with matching responses to the requesting thread. When using this client handler make sure to close it when no longer in use. Otherwise it will keep the socket channel open almost indefinitely.
    • Constructor Detail

      • NonblockingSocketClientHandler

        public NonblockingSocketClientHandler​(Serializer serializer,
                                              java.net.SocketAddress address,
                                              PService service)
      • NonblockingSocketClientHandler

        public NonblockingSocketClientHandler​(Serializer serializer,
                                              java.net.SocketAddress address,
                                              PService service,
                                              int connect_timeout,
                                              int read_timeout)
      • NonblockingSocketClientHandler

        public NonblockingSocketClientHandler​(Serializer serializer,
                                              java.net.SocketAddress address,
                                              PService service,
                                              PServiceCallInstrumentation instrumentation,
                                              int connect_timeout,
                                              int read_timeout)
      • NonblockingSocketClientHandler

        public NonblockingSocketClientHandler​(Serializer serializer,
                                              java.net.SocketAddress address,
                                              PService service,
                                              PServiceCallInstrumentation instrumentation,
                                              int connect_timeout,
                                              int read_timeout,
                                              int response_timeout)
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • handleCall

        public <Request extends PMessage<Request>,​Response extends PMessage<Response>> PServiceCall<Response> handleCall​(PServiceCall<Request> call,
                                                                                                                               PService service)
                                                                                                                        throws java.io.IOException
        Description copied from interface: PServiceCallHandler
        Handle a service call.
        Specified by:
        handleCall in interface PServiceCallHandler
        Type Parameters:
        Request - Request type.
        Response - Response type.
        Parameters:
        call - The request call.
        service - The service to be handled.
        Returns:
        The response service call object, or null if none (e.g. oneway).
        Throws:
        java.io.IOException - On read or write failure.