A few comments inline...

Le 5/13/13 10:29 PM, Whitener, Winona T. a écrit :
> Please forgive wonky capitals.  I'm having to type this from computer to 
> computer.  No exceptions are being recorded.  No exceptions are being caught.
>
> It's definitely not the prettiest code and needs cleaning, but I am unable to 
> track down why the connection is closing here.
>
> Thank you for your help.
>
> public class CodecFactory extends TextLineEncoder implements 
> ProtocolCodecFactory {
>       public static String EOM = "//endmsg//";
>       public static String BOM = "//stmsg//";
>
>       public ProtocolEncoder getEncoder(IoSession ioSession) {
>               return (ProtocolEncoder) new CustomEncoder();
>               }
>
>       public ProtocolDecoder getDecoder(IoSession ioSession) {
>               return (ProtocolDecoder) new CustomDecoder();
>       }
> }
>
> Public class CustomDecoder extends CumulativeProtocolDecoder {
> ///
> Public Boolean doDecode(<args>) throws Exception {
>       Try { 
>               Int startPosition = ioBuffer.position();
>               Boolean receivedEndSequence = false;
>               
>               StringBuffer buffer = new StringBuffer();

Here, I would simply convert the full buffer to a String, instead of
accumulating the bytes one by one.
>               while (ioBuffer.hasRemaining()) {
>                       byte by = ioBuffer.get();
>                       buffer.append((char)b);
>                       if (buffer.toString().endWith(CodecFactory.EOM)) {
>                               receivedEndSequence = true;
>                       }
>               }
// Now, check if you found the end sequence

One question : why are you testing if you still have some bytes in your
buffer ?
>               if (receivedEndSequence && ioBuffer.hasRemaining()) {
>                       //logging
>                       out.write(fullMessage);
>                       return true;
>               }
>       }
>       Catch (Exception e) {
>               //logging
>       }
> }
> }

All in all, I don't think that usng a CummulativeProtocolDecoder is
helpful. I would rather process the data as they come, dealing with
fragmentation by hand. You have more control.



-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to