Class DemuxingIoHandler

    • Constructor Detail

      • DemuxingIoHandler

        public DemuxingIoHandler()
        Creates a new instance with no registered MessageHandlers.
    • Method Detail

      • addReceivedMessageHandler

        public <E> MessageHandler<? super E> addReceivedMessageHandler​(java.lang.Class<E> type,
                                                                       MessageHandler<? super E> handler)
        Registers a MessageHandler that handles the received messages of the specified type.
        Type Parameters:
        E - The message handler's type
        Parameters:
        type - The message's type
        handler - The message handler
        Returns:
        the old handler if there is already a registered handler for the specified type. null otherwise.
      • removeReceivedMessageHandler

        public <E> MessageHandler<? super E> removeReceivedMessageHandler​(java.lang.Class<E> type)
        Deregisters a MessageHandler that handles the received messages of the specified type.
        Type Parameters:
        E - The message handler's type
        Parameters:
        type - The message's type
        Returns:
        the removed handler if successfully removed. null otherwise.
      • addSentMessageHandler

        public <E> MessageHandler<? super E> addSentMessageHandler​(java.lang.Class<E> type,
                                                                   MessageHandler<? super E> handler)
        Registers a MessageHandler that handles the sent messages of the specified type.
        Type Parameters:
        E - The message handler's type
        Parameters:
        type - The message's type
        handler - The message handler
        Returns:
        the old handler if there is already a registered handler for the specified type. null otherwise.
      • removeSentMessageHandler

        public <E> MessageHandler<? super E> removeSentMessageHandler​(java.lang.Class<E> type)
        Deregisters a MessageHandler that handles the sent messages of the specified type.
        Type Parameters:
        E - The message handler's type
        Parameters:
        type - The message's type
        Returns:
        the removed handler if successfully removed. null otherwise.
      • addExceptionHandler

        public <E extends java.lang.Throwable> ExceptionHandler<? super E> addExceptionHandler​(java.lang.Class<E> type,
                                                                                               ExceptionHandler<? super E> handler)
        Registers a MessageHandler that receives the messages of the specified type.
        Type Parameters:
        E - The message handler's type
        Parameters:
        type - The message's type
        handler - The Exception handler
        Returns:
        the old handler if there is already a registered handler for the specified type. null otherwise.
      • removeExceptionHandler

        public <E extends java.lang.Throwable> ExceptionHandler<? super E> removeExceptionHandler​(java.lang.Class<E> type)
        Deregisters a MessageHandler that receives the messages of the specified type.
        Type Parameters:
        E - The Exception Handler's type
        Parameters:
        type - The message's type
        Returns:
        the removed handler if successfully removed. null otherwise.
      • getMessageHandler

        public <E> MessageHandler<? super E> getMessageHandler​(java.lang.Class<E> type)
        Type Parameters:
        E - The message handler's type
        Parameters:
        type - The message's type
        Returns:
        the MessageHandler which is registered to process the specified type.
      • getReceivedMessageHandlerMap

        public java.util.Map<java.lang.Class<?>,​MessageHandler<?>> getReceivedMessageHandlerMap()
        Returns:
        the Map which contains all messageType-MessageHandler pairs registered to this handler for received messages.
      • getSentMessageHandlerMap

        public java.util.Map<java.lang.Class<?>,​MessageHandler<?>> getSentMessageHandlerMap()
        Returns:
        the Map which contains all messageType-MessageHandler pairs registered to this handler for sent messages.
      • getExceptionHandlerMap

        public java.util.Map<java.lang.Class<?>,​ExceptionHandler<?>> getExceptionHandlerMap()
        Returns:
        the Map which contains all messageType-MessageHandler pairs registered to this handler.
      • messageReceived

        public void messageReceived​(IoSession session,
                                    java.lang.Object message)
                             throws java.lang.Exception
        Forwards the received events into the appropriate MessageHandler which is registered by addReceivedMessageHandler(Class, MessageHandler). Warning ! If you are to overload this method, be aware that you _must_ call the messageHandler in your own method, otherwise it won't be called. Invoked when a message is received.
        Specified by:
        messageReceived in interface IoHandler
        Overrides:
        messageReceived in class IoHandlerAdapter
        Parameters:
        session - The session that is receiving a message
        message - The received message
        Throws:
        java.lang.Exception - If we get an exception while processing the received message
      • messageSent

        public void messageSent​(IoSession session,
                                java.lang.Object message)
                         throws java.lang.Exception
        Invoked when a message written by IoSession.write(Object) is sent out. Warning ! If you are to overload this method, be aware that you _must_ call the messageHandler in your own method, otherwise it won't be called. Invoked when a message written by IoSession.write(Object) is sent out.
        Specified by:
        messageSent in interface IoHandler
        Overrides:
        messageSent in class IoHandlerAdapter
        Parameters:
        session - The session that has sent a full message
        message - The sent message
        Throws:
        java.lang.Exception - If we get an exception while processing the sent message
      • exceptionCaught

        public void exceptionCaught​(IoSession session,
                                    java.lang.Throwable cause)
                             throws java.lang.Exception
        Invoked when any exception is thrown by user IoHandler implementation or by MINA. If cause is an instance of IOException, MINA will close the connection automatically. Warning ! If you are to overload this method, be aware that you _must_ call the messageHandler in your own method, otherwise it won't be called. Invoked when any exception is thrown by user IoHandler implementation or by MINA. If cause is an instance of IOException, MINA will close the connection automatically.
        Specified by:
        exceptionCaught in interface IoHandler
        Overrides:
        exceptionCaught in class IoHandlerAdapter
        Parameters:
        session - The session for which we have got an exception
        cause - The exception that has been caught
        Throws:
        java.lang.Exception - If we get an exception while processing the caught exception
      • findReceivedMessageHandler

        protected MessageHandler<java.lang.Object> findReceivedMessageHandler​(java.lang.Class<?> type)
      • findSentMessageHandler

        protected MessageHandler<java.lang.Object> findSentMessageHandler​(java.lang.Class<?> type)
      • findExceptionHandler

        protected ExceptionHandler<java.lang.Throwable> findExceptionHandler​(java.lang.Class<? extends java.lang.Throwable> type)