If there's no message terminator whatsoever, you have to work
time-based (can't think of any other way, but maybe that's just me).
In that case you're looking at is basically a two-state state machine
with a "wait for first data" state and an "accumulate until timeout
then reset" state. If I understand your problem correctly, I think
something along these lines might do the trick. The pseudocode is a
bit nasty, but you get the idea.

// used instead of CumulativeProtocolDecoder, not alongside it
public class MyFilter extends IoFilterAdapter {


/** Helper class for MyFilter, an instance of this class is bound to
every IoSession */
private static class Accumulator {

// synchronize all access to these fields, as we'll be using two threads!
private final IoBuffer accumulator = newBuffer();
private boolean setTimeout = true;

private static IoBuffer newBuffer() {
  // return a new IoBuffer of reasonable size and maybe setAutoExpand(true)
}

public synchronized boolean receive(IoBuffer message) {
      accumulator.put(message);
      if (setTimeout) {
         setTimeout = false;
         return true;
      }
      return false;
 }

public synchronized IoBuffer flush() {
    setTimeout = true;
    IoBuffer returnval = accumulator;
    accumulator = newBuffer();
    returnval.flip();
    return returnval;
}
}

private final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool();

private final static long TIMEOUT = 250L; //Whatever is reasonable


@Override public void sessionCreated() {
   // insert a new Accumulator into the session
}

@Override public void messageReceived(final NextFilter nf, final
Session ssn, Object msg) {
   final Accumulator accu = // retrieve accumulator from session

   if (accu.receive( (IoBuffer)msg )) {

     scheduler.schedule( new Runnable() {
       public void run() {
           nf.messageReceived(ssn, accu.flush());
       }
     }, TIMEOUT, TimeUnit.MILLISECONDS);

   }

   // done
}

// override sessionClosed() to cancel any scheduled tasks

}


HTH,

Barend



On Tue, Aug 5, 2008 at 1:32 PM, lnaber <[EMAIL PROTECTED]> wrote:
>>>>Are there *any* rules that allow detection of message boundaries? For
>>>>example, is there a time interval between messages?
>>
>> The application is conversational in that a request-response is expected
>> so yes, there is timing available.
>>

Reply via email to