Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-767

Move encoder/decoder out of the session Attributes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 2.0.0-RC1
    • 2.0.8
    • None
    • None

    Description

      When we initialize a new session with a ProrocolCodecFilter in the chain, the filter is storing the encoder and decoder into the session's Attribute :

          private void initCodec(IoSession session) throws Exception {
              // Creates the decoder and stores it into the newly created session 
              ProtocolDecoder decoder = factory.getDecoder(session);
              session.setAttribute(DECODER, decoder);
      
              // Creates the encoder and stores it into the newly created session 
              ProtocolEncoder encoder = factory.getEncoder(session);
              session.setAttribute(ENCODER, encoder);
          }
      

      Assuming that the codec is stateless, there is no reason to do that. If we have thousands of sessions, that would store thousands of references to the encoder and the decoder in the session hashmap, forever.

      The factory used to get those elements can efficiently provide references to those elements to the codec when needed.

      One could think that two sessions could use two different codec for an application, but this is a non-sense, as the codec is stored in the attributes at the beginning, and the encoder/decoder selection does not use any context, so they will always be the same.

      Attachments

        Activity

          People

            Unassigned Unassigned
            elecharny Emmanuel Lécharny
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: