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

Move encoder/decoder out of the session Attributes

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 2.0.0-RC1
    • Fix Version/s: 2.0.8
    • Component/s: None
    • Labels:
      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.

        Activity

        Hide
        elecharny Emmanuel Lecharny added a comment -

        Not really a big deal in 2.0.

        Will most certainly proceed differently in 3.0

        Show
        elecharny Emmanuel Lecharny added a comment - Not really a big deal in 2.0. Will most certainly proceed differently in 3.0

          People

          • Assignee:
            Unassigned
            Reporter:
            elecharny Emmanuel Lecharny
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development