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.ConnectionHandler(Transport transport, String connectionName, InputStream inputStream, OutputStream outputStream, Supplier<List<X509Certificate>> peerCertificates) Creates a new handler for a connection that may provide peer certificates. -
Method Summary
Modifier and TypeMethodDescriptionprotected TripStreamcreateStream(UUID id, boolean clientDictionaryEmpty) Creates a new stream for the given UUID.protected voidevict()Closes the connection on behalf of the pre-authentication policy.
Unblocks the thread reading from the connection.Gets the name of the connection.Gets the input stream associated with this connection.Gets the output stream associated with this connection.protected List<X509Certificate> Gets the verified certificate chain of the peer.
Invoked once the connection request has been read.Gets the transport associated with this handler.booleanReturns whether the client of this connection is authenticated.protected booleanChecks whether the connection is still alive.protected booleanisErrorSuppressed(PreAuthenticationPolicy policy, PreAuthenticationPolicy.Admission admission) Returns whether errors are not answered.
As long as the client is not authenticated by an enforcing policy, the server sends nothing but the responses of successful calls.protected booleanReturns whether rejections are delayed by theRejectionDelay.
A peer must not tell from the response time why it was rejected, or whether it talks to a TRIP server at all.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 handlerconnectionName- the name of the connectioninputStream- the input stream associated with this connectionoutputStream- the output stream associated with this connection
-
ConnectionHandler
public ConnectionHandler(Transport transport, String connectionName, InputStream inputStream, OutputStream outputStream, Supplier<List<X509Certificate>> peerCertificates) Creates a new handler for a connection that may provide peer certificates.The certificates are requested once the connection request has been read, i.e. when the TLS handshake, if any, is complete. They are passed on to the
TransportClientInfo.- Parameters:
transport- the transport associated with this handlerconnectionName- the name of the connectioninputStream- the input stream associated with this connectionoutputStream- the output stream associated with this connectionpeerCertificates- supplies the verified certificate chain of the peer, leaf first, empty if none
-
-
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
and whether the client's dictionary is still empty. An invalid magic, a stale dictionary or any other
failure of the handshake closes the connection after the
RejectionDelay. - 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.
- reads the connection request: the TRIP magic followed by the UUID of the client's transport
and whether the client's dictionary is still empty. An invalid magic, a stale dictionary or any other
failure of the handshake closes the connection after the
-
isAuthenticated
public boolean isAuthenticated()Returns whether the client of this connection is authenticated.- Returns:
- true if authenticated, false if not or the handshake is not complete yet
-
evict
protected void evict()Closes the connection on behalf of the pre-authentication policy.
Unblocks the thread reading from the connection. -
getPeerCertificates
Gets the verified certificate chain of the peer.
Invoked once the connection request has been read.- Returns:
- the certificates, leaf first, empty if none
- Throws:
TripRuntimeException- if the certificates cannot be determined
-
isRejectionDelayed
protected boolean isRejectionDelayed()Returns whether rejections are delayed by theRejectionDelay.
A peer must not tell from the response time why it was rejected, or whether it talks to a TRIP server at all.- Returns:
- true if delayed (default)
-
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 transportclientDictionaryEmpty- true if the client's dictionary is still empty- Returns:
- the trip stream
-
isErrorSuppressed
protected boolean isErrorSuppressed(PreAuthenticationPolicy policy, PreAuthenticationPolicy.Admission admission) Returns whether errors are not answered.
As long as the client is not authenticated by an enforcing policy, the server sends nothing but the responses of successful calls. An error message would tell a prober that it talks to a TRIP server.- Parameters:
policy- the pre-authentication policy, null if noneadmission- the admission, null if none or authenticated- Returns:
- true if errors are not answered
-