Class DecodingStateMachine

java.lang.Object
org.apache.mina.filter.codec.statemachine.DecodingStateMachine
All Implemented Interfaces:
DecodingState

public abstract class DecodingStateMachine extends Object implements DecodingState
Abstract base class for decoder state machines. Calls init() to get the start DecodingState of the state machine. Calls destroy() when the state machine has reached its end state or when the session is closed.

NOTE: The ProtocolDecoderOutput used by this class when calling DecodingState.decode(IoBuffer, ProtocolDecoderOutput) buffers decoded messages in a List. Once the state machine has reached its end state this class will call finishDecode(List, ProtocolDecoderOutput). The implementation will have to take care of writing the decoded messages to the real ProtocolDecoderOutput used by the configured ProtocolCodecFilter.

  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • childProducts

      private final List<Object> childProducts
    • childOutput

      private final ProtocolDecoderOutput childOutput
    • currentState

      private DecodingState currentState
    • initialized

      private boolean initialized
  • Constructor Details

    • DecodingStateMachine

      public DecodingStateMachine()
  • Method Details

    • init

      protected abstract DecodingState init() throws Exception
      Invoked to initialize this state machine.
      Returns:
      the start DecodingState.
      Throws:
      Exception - if the initialization failed
    • finishDecode

      protected abstract DecodingState finishDecode(List<Object> childProducts, ProtocolDecoderOutput out) throws Exception
      Called once the state machine has reached its end.
      Parameters:
      childProducts - contains the messages generated by each of the DecodingStates which were exposed to the received data during the life time of this state machine.
      out - the real ProtocolDecoderOutput used by the ProtocolCodecFilter.
      Returns:
      the next state if the state machine should resume.
      Throws:
      Exception - if the decoding end failed
    • destroy

      protected abstract void destroy() throws Exception
      Invoked to destroy this state machine once the end state has been reached or the session has been closed.
      Throws:
      Exception - if the destruction failed
    • decode

      public DecodingState decode(IoBuffer in, ProtocolDecoderOutput out) throws Exception
      Invoked when data is available for this state.
      Specified by:
      decode in interface DecodingState
      Parameters:
      in - the data to be decoded.
      out - used to write decoded objects.
      Returns:
      the next state if a state transition was triggered (use this for loop transitions) or null if the state machine has reached its end.
      Throws:
      Exception - if the read data violated protocol specification.
    • finishDecode

      public DecodingState finishDecode(ProtocolDecoderOutput out) throws Exception
      Invoked when the associated IoSession is closed. This method is useful when you deal with protocols which don't specify the length of a message (e.g. HTTP responses without content-length header). Implement this method to process the remaining data that DecodingState.decode(IoBuffer, ProtocolDecoderOutput) method didn't process completely.
      Specified by:
      finishDecode in interface DecodingState
      Parameters:
      out - used to write decoded objects.
      Returns:
      the next state if a state transition was triggered (use this for loop transitions) or null if the state machine has reached its end.
      Throws:
      Exception - if the read data violated protocol specification.
    • cleanup

      private void cleanup()
    • getCurrentState

      private DecodingState getCurrentState() throws Exception
      Throws:
      Exception