mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Furbacher <pfurbac...@mac.com>
Subject Re: Proxy server example -- introduce a random delay from client to proxied server?
Date Tue, 21 Aug 2007 06:14:01 GMT

Maarten,

Thanks for the suggestion.  At first read, it seemed so obvious, so simple.

But besides a lot of debug error statements like the following

  [...] ServerToProxyIoHandler - [localhost/127.0.0.1:9001]
java.lang.IllegalStateException: Timer already cancelled.

and 

  [...] ClientToProxyIoHandler - [/127.0.0.1:60974]
java.lang.IllegalStateException: Timer already cancelled. ...


the messages arrive in the same order they were dispatched by the client.  

The desired effect of having the randomized delay is to scramble the message
order, something like the following:

Client send order   1 2 3 4 5 . . .

Client receive order   3 1 4 5 2 . . .

Perhaps an IoHandler is not the right place to do this? Would an IoFilter be
more appropriate?  

-- 

Paul Furbacher



Maarten Bosteels-4 wrote:
> 
> 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
> 
>> --
>> 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
> 

-- 
View this message in context: http://www.nabble.com/Proxy-server-example----introduce-a-random-delay-from-client-to-proxied-server--tf4301103s16868.html#a12248916
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Mime
View raw message