mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maarten Bosteels" <mbosteels....@gmail.com>
Subject Re: Proxy server example -- introduce a random delay from client to proxied server?
Date Tue, 21 Aug 2007 07:45:35 GMT
On 8/21/07, Paul Furbacher <pfurbacher@mac.com> wrote:
>
>
> 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. ...


seems  like you  added the  TimerTask to both ClientToProxy and
ServerToProxy.
I only added  it to ClientToProxy and didn't get these errors.
But it is always possible that the proxied server closes the connection
before you could forward the request.

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


That's odd, maybe you need higher variation in the delay ?
Do you have control over the server ? I mean, can you ensure that it does
not close the connections too early ?

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?


I guess you only want to randomize the messages to test the server ?
Wouldn't it be simpler then to write a test-case that sends a hard-coded
list of messages (randomized by hand) ?

Maarten

--
>
> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message