Class ProtocolCodecFilter

    • Constructor Detail

      • ProtocolCodecFilter

        public ProtocolCodecFilter​(ProtocolCodecFactory factory)
        Creates a new instance of ProtocolCodecFilter, associating a factory for the creation of the encoder and decoder.
        Parameters:
        factory - The associated factory
      • ProtocolCodecFilter

        public ProtocolCodecFilter​(ProtocolEncoder encoder,
                                   ProtocolDecoder decoder)
        Creates a new instance of ProtocolCodecFilter, without any factory. The encoder/decoder factory will be created as an inner class, using the two parameters (encoder and decoder).
        Parameters:
        encoder - The class responsible for encoding the message
        decoder - The class responsible for decoding the message
      • ProtocolCodecFilter

        public ProtocolCodecFilter​(java.lang.Class<? extends ProtocolEncoder> encoderClass,
                                   java.lang.Class<? extends ProtocolDecoder> decoderClass)
        Creates a new instance of ProtocolCodecFilter, without any factory. The encoder/decoder factory will be created as an inner class, using the two parameters (encoder and decoder), which are class names. Instances for those classes will be created in this constructor.
        Parameters:
        encoderClass - The class responsible for encoding the message
        decoderClass - The class responsible for decoding the message
    • Method Detail

      • getEncoder

        public ProtocolEncoder getEncoder​(IoSession session)
        Get the encoder instance from a given session.
        Parameters:
        session - The associated session we will get the encoder from
        Returns:
        The encoder instance, if any
      • onPreAdd

        public void onPreAdd​(IoFilterChain parent,
                             java.lang.String name,
                             IoFilter.NextFilter nextFilter)
                      throws java.lang.Exception
        Invoked before this filter is added to the specified parent. Please note that this method can be invoked more than once if this filter is added to more than one parents. This method is not invoked before IoFilter.init() is invoked.
        Specified by:
        onPreAdd in interface IoFilter
        Overrides:
        onPreAdd in class IoFilterAdapter
        Parameters:
        parent - the parent who called this method
        name - the name assigned to this filter
        nextFilter - the IoFilter.NextFilter for this filter. You can reuse this object until this filter is removed from the chain.
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • onPostRemove

        public void onPostRemove​(IoFilterChain parent,
                                 java.lang.String name,
                                 IoFilter.NextFilter nextFilter)
                          throws java.lang.Exception
        Invoked after this filter is removed from the specified parent. Please note that this method can be invoked more than once if this filter is removed from more than one parents. This method is always invoked before IoFilter.destroy() is invoked.
        Specified by:
        onPostRemove in interface IoFilter
        Overrides:
        onPostRemove in class IoFilterAdapter
        Parameters:
        parent - the parent who called this method
        name - the name assigned to this filter
        nextFilter - the IoFilter.NextFilter for this filter. You can reuse this object until this filter is removed from the chain.
        Throws:
        java.lang.Exception - If an error occurred while processing the event
      • messageReceived

        public void messageReceived​(IoFilter.NextFilter nextFilter,
                                    IoSession session,
                                    java.lang.Object message)
                             throws java.lang.Exception
        Process the incoming message, calling the session decoder. As the incoming buffer might contains more than one messages, we have to loop until the decoder throws an exception. while ( buffer not empty ) try decode ( buffer ) catch break;
        Specified by:
        messageReceived in interface IoFilter
        Overrides:
        messageReceived in class IoFilterAdapter
        Parameters:
        nextFilter - the IoFilter.NextFilter for this filter. You can reuse this object until this filter is removed from the chain.
        session - The IoSession which has received this event
        message - The received message
        Throws:
        java.lang.Exception - If an error occurred while processing the event