Class OperationRoutingServerConnectionHandler

  • All Implemented Interfaces:
    AutoCloseable

    public class OperationRoutingServerConnectionHandler
    extends ServerConnectionHandler
    ServerConnectionHandler implementation that routes continuations to specific operation specific message handlers
    • Constructor Detail

      • OperationRoutingServerConnectionHandler

        public OperationRoutingServerConnectionHandler​(ServerConnection serverConnection,
                                                       Map<String,​java.util.function.Function<ServerConnectionContinuation,​ServerConnectionContinuationHandler>> operationMapping)
        binds an operation handler mapping to a server connection
        Parameters:
        serverConnection - connection to route messages for
        operationMapping - mapping of operation names to message handlers.
    • Method Detail

      • onProtocolMessage

        protected void onProtocolMessage​(List<Header> headers,
                                         byte[] payload,
                                         MessageType messageType,
                                         int messageFlags)
        By default, automatically responds to pings when received, and routes connect requests. Feel free to override this function if you want different behavior.
        Specified by:
        onProtocolMessage in class ServerConnectionHandler
        Parameters:
        headers - List of EventStream headers for the message received.
        payload - Payload for the message received
        messageType - message type for the message
        messageFlags - message flags for the message
      • onConnectRequest

        protected void onConnectRequest​(List<Header> headers,
                                        byte[] payload)
        To customize how the connect request is handled, override this function. You're responsible for sending the response. By default, it accepts all incoming connections.
        Parameters:
        headers - list of headers received in the message
        payload - payload received in the message
      • onIncomingStream

        protected final ServerConnectionContinuationHandler onIncomingStream​(ServerConnectionContinuation continuation,
                                                                             String operationName)
        When a new stream continuation is received, it routes to the configured operation name to handler mapping. If no such mapping exists, an Unsupported Operation message of type ApplicationError is sent to the peer. You can't override this function, because well, if you do, you might as well not use this class in the first place.
        Specified by:
        onIncomingStream in class ServerConnectionHandler
        Parameters:
        continuation - continuation representing the new incoming stream
        operationName - operation name for the new incoming stream
        Returns:
        a new instance of ServerConnectionContinuationHandler for handling continuation events.