Hi all,

I need to use VMPipeTransport but I want the conversation to have delays because this would be much more similar to the real case.

I'd like to introduce a given delay between messages of the same session (without blocking other sessions).

This would also be useful in implementing Tarpit like services.

I tried adding a filter like this one:
---------------------
final class DelayFilter extends IoFilterAdapter {
private int delay;
public DelayFilter(int delay) {
        super();
        this.delay = delay;
}

private static class ThrottlingWriteTimerTask extends TimerTask {

    protected IoSession session;
    private Object message;
    private NextFilter filter;

    public ThrottlingWriteTimerTask(NextFilter filter, IoSession session,
            Object message) {
        this.session = session;
        this.message = message;
        this.filter = filter;
    }

    public void run() {
        filter.filterWrite(session, new DefaultWriteRequest(message));
    }
}

@Override
public void filterWrite(NextFilter arg0, IoSession arg1, WriteRequest arg2) throws Exception {
    String response = (String) arg2.getMessage();
new Timer(true).schedule(new ThrottlingWriteTimerTask(arg0, arg1,response), delay);
}
}
------------------

The issue with this filter is that the event are rescheduled using a Timer and this sometimes break ordering and I need to mantain strict ordering for messages.

Do you have any suggestion?

Stefano

Reply via email to