/** * 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. <code> * while ( buffer not empty ) * try * decode ( buffer ) * catch * break; * </code> */ @SuppressWarnings("unchecked") @Override public void messageReceived(IoSession session, Object in, ReadFilterChainController controller) { LOGGER.debug("Processing a MESSAGE_RECEIVED for session {}", session); DECODING_STATE state = getDecodingState(session); // Loop until the decoder cannot decode more MESSAGE msg; try { while (((msg = decoder.decode((ENCODED) in, state)) != null)) { super.messageReceived(session, msg, controller); } } catch (ProtocolDecoderException e) { LOGGER.debug("decoding exception : ", e); throw e; } }
/** * {@inheritDoc} */ @Override public void sessionClosed(IoSession session) { decoder.finishDecode(getDecodingState(session)); super.sessionClosed(session); }
/** * {@inheritDoc} */ @Override public void sessionOpened(IoSession session) { // Initialize the encoder and decoder state ENCODING_STATE encodingState = encoder.createEncoderState(); session.setAttribute(ENCODER, encodingState); DECODING_STATE decodingState = decoder.createDecoderState(); session.setAttribute(DECODER, decodingState); super.sessionOpened(session); }