Author: elecharny Date: Tue Nov 11 12:46:13 2008 New Revision: 713157 URL: http://svn.apache.org/viewvc?rev=713157&view=rev Log: Removed more useless test. Added some Javadoc and moved a method down in the file (I have created a 'handler methods' section)
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=713157&r1=713156&r2=713157&view=diff ============================================================================== --- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (original) +++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java Tue Nov 11 12:46:13 2008 @@ -219,19 +219,6 @@ IoBuffer in = (IoBuffer) message; ProtocolDecoder decoder = getDecoder(session); - - if ( decoder == null) { - // The decoder must not be null. It's null if - // the sessionCreated message has not be called, for - // instance if the filter has been added after the - // first session is created. - ProtocolDecoderException pde = new ProtocolDecoderException( - "Cannot decode if the decoder is null. Add the filter in the chain" + - "before the first session is created" ); - nextFilter.exceptionCaught(session, pde); - return; - } - ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter); // Loop until we don't have anymore byte in the buffer, @@ -414,16 +401,6 @@ return new ProtocolEncoderOutputImpl(session, nextFilter, writeRequest); } - private ProtocolDecoderOutput getDecoderOut(IoSession session, - NextFilter nextFilter) { - ProtocolDecoderOutput out = (ProtocolDecoderOutput) session.getAttribute(DECODER_OUT); - if (out == null) { - out = new ProtocolDecoderOutputImpl(); - session.setAttribute(DECODER_OUT, out); - } - return out; - } - private static class EncodedWriteRequest extends DefaultWriteRequest { private EncodedWriteRequest(Object encodedMessage, WriteFuture future, SocketAddress destination) { @@ -518,6 +495,23 @@ //----------- Helper methods --------------------------------------------- /** + * Return a reference to the decoder callback. If it's not already created + * and stored into the session, we create a new instance. + */ + private ProtocolDecoderOutput getDecoderOut(IoSession session, + NextFilter nextFilter) { + ProtocolDecoderOutput out = (ProtocolDecoderOutput) session.getAttribute(DECODER_OUT); + + if (out == null) { + // Create a new instance, and stores it into the session + out = new ProtocolDecoderOutputImpl(); + session.setAttribute(DECODER_OUT, out); + } + + return out; + } + + /** * Initialize the encoder and the decoder, storing them in the * session attributes. */