Class ConnectionHandler
java.lang.Object
org.tentackle.trip.transport.ConnectionHandler
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
LoopbackConnectionHandler
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 Summary
ConstructorsConstructorDescriptionConnectionHandler(Transport transport, String connectionName, InputStream inputStream, OutputStream outputStream) Creates a new handler. -
Method Summary
Modifier and TypeMethodDescriptionprotected TripStreamcreateStream(UUID id) Creates a new stream for the given UUID.Gets the name of the connection.Gets the input stream associated with this connection.Gets the output stream associated with this connection.Gets the transport associated with this handler.protected booleanChecks whether the connection is still alive.voidrun()Handles the new connection.
-
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-loopconnectionName- the name of the connectioninputStream- the input stream associated with this connectionoutputStream- the output stream associated with this connection
-
-
Method Details
-
getTransport
Gets the transport associated with this handler.- Returns:
- the transport
-
getConnectionName
-
getInputStream
Gets the input stream associated with this connection.- Returns:
- the input stream
-
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.
-
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
Creates a new stream for the given UUID.- Parameters:
id- the UUID of the client's transport- Returns:
- the trip stream
-