Class ConnectionHandler

java.lang.Object
org.tentackle.trip.transport.ConnectionHandler
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
LoopbackConnectionHandler

public class ConnectionHandler extends Object implements Runnable
Handler for a new incoming connection.

Each handler runs in a virtual thread, so that the deserialization of remote calls, which takes time depending on the incoming data rate, does not block regular threads. When a call is deserialized, it is dispatched to a regular thread from the call thread pool. This combination of virtual and regular threads reduces the total number of threads, since we don't need a regular thread per incoming connection anymore, but only that many threads that are necessary to handle the remote calls concurrently.

See Also:
  • Constructor Details

    • ConnectionHandler

      public ConnectionHandler(Transport transport, String connectionName, InputStream inputStream, OutputStream outputStream)
      Creates a new handler.
      Parameters:
      transport - the transport associated with this accept-loop
      connectionName - the name of the connection
      inputStream - the input stream associated with this connection
      outputStream - the output stream associated with this connection
  • Method Details

    • getTransport

      public Transport getTransport()
      Gets the transport associated with this handler.
      Returns:
      the transport
    • getConnectionName

      public String getConnectionName()
      Gets the name of the connection.
      Returns:
      the name
    • getInputStream

      public InputStream getInputStream()
      Gets the input stream associated with this connection.
      Returns:
      the input stream
    • getOutputStream

      public OutputStream getOutputStream()
      Gets the output stream associated with this connection.
      Returns:
      the output stream
    • run

      public void run()
      Handles the new connection.

      • reads the connection request: the TRIP magic followed by the UUID of the client's transport
      • the UUID is used to determine the dictionary and a TRIP stream is created
      • reads the remote calls from the stream and dispatches them to the call handler thread pool.
      Specified by:
      run in interface Runnable
    • isConnectionAlive

      protected boolean isConnectionAlive()
      Checks whether the connection is still alive.
      Returns:
      true if the connection is still alive, false to terminate the handler
    • createStream

      protected TripStream createStream(UUID id)
      Creates a new stream for the given UUID.
      Parameters:
      id - the UUID of the client's transport
      Returns:
      the trip stream