Hello Paul,
How about adding this to ClientToProxyIoHandler ?
private Random random = new Random();
private Timer timer = new Timer();
public void messageReceived(final IoSession session, final Object
message) throws Exception {
final int c = counter.incrementAndGet();
ByteBuffer rb = (ByteBuffer) message;
final ByteBuffer wb = ByteBuffer.allocate(rb.remaining());
rb.mark();
wb.put(rb);
wb.flip();
rb.reset();
long delay = random.nextInt(500);
final IoSession proxySession = (IoSession) session.getAttachment();
timer.schedule(
new TimerTask() {
public void run() {
proxySession.write(wb);
}
}, delay);
}
Maarten
On 8/20/07, Paul Furbacher <[EMAIL PROTECTED]> wrote:
>
>
> I'm trying to modify the proxy server example to introduce a random delay
> to
> messages coming from the client before they are sent to the server. The
> reason for doing this is that I have to simulate scrambling the order of
> messages from client to server.
>
> At the moment, my idea is to wrap the incoming message (byte buffer) in an
> object which also has a single-shot timer task, and then putting those
> wrapper objects into a collection. As an individual message times out in
> the delay collection, it becomes "deliverable". It seems as though I need
> to create a "message needs sending" event, but I'm not sure how that could
> be done.
>
> I'm new to the mina framework, and would appreciate a few pointers -- not
> necessarily any code, just pointers as to what and how to think about this
> within the context of the framework.
>
> Thanks.
>
> --
>
> Paul Furbacher
>
>
> --
> View this message in context:
> http://www.nabble.com/Proxy-server-example----introduce-a-random-delay-from-client-to-proxied-server--tf4301103s16868.html#a12242579
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com
> .
>
>