Class MultiProtocolRequestHandler

  • All Implemented Interfaces:
    RequestHandler

    public class MultiProtocolRequestHandler
    extends Object
    implements RequestHandler
    Request handler implementation that forwards all requests to a registered protocol-specific handler. All unknown protocols are forwarded to a default request handler. Protocols and their handlers are registered with registerProtocols(RequestHandler, String[]). An incoming request should be of the form: protocol://additional-info. Requests for protocols that doesn't have a registered handler and requests that doesn't follow the above form are forwarded to the default handler.
    Since:
    2.16
    Author:
    Nicklas
    Last modified
    $Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
    • Field Detail

      • log

        private static final org.slf4j.Logger log
        Logger.
      • agent

        private final Agent agent
      • isClosed

        private boolean isClosed
    • Constructor Detail

      • MultiProtocolRequestHandler

        public MultiProtocolRequestHandler​(Agent agent,
                                           RequestHandler defaultHandler)
        Create a new multi-protocol request handler.
        Parameters:
        defaultHandler - The default handler that should receive all requests that hasn't a registered specific handler
    • Method Detail

      • handleCmd

        public String handleCmd​(Socket socket,
                                String cmd)
        Description copied from interface: RequestHandler
        Handle a command that was sent by an incoming request.
        Specified by:
        handleCmd in interface RequestHandler
        Parameters:
        socket - The socket that is handling the communication with the remote client
        cmd - The command
        Returns:
        The answer
      • registerProtocols

        public void registerProtocols​(RequestHandler handler,
                                      String... protocols)
        Register a handler for one or more protocols. Ignored if this request handler has been closed.
        Parameters:
        handler - The handler
        protocols - An array with protocol names
      • unregisterProtocols

        public void unregisterProtocols​(String... protocols)
        Unregister a handler for one or more protocols. Ignored if this request handler has been closed.
        Parameters:
        protocols - An array with protocol names
        Since:
        2.16
      • close

        public void close()
        Close this handler. It can't be used again.
      • isClosed

        public boolean isClosed()
        If the request handler is closed, it will igore all method calls.