You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by superandi <at...@diezwei.de> on 2007/11/22 12:00:48 UTC

How can I build a polling server with Mina?

Hi there Mina-Pros,

before discovering Mina I did the following:

I Started a Java ServerSocket to accept connections. I remembered the
accepted connection and waited for a new one. At server start i spawned a
number of Worker threads that:

- checked if data was available FROM each of the sockets FOR my application
logic.
- checked if data was available FOR one of the sockets FROM my application
logic.

Thus i put the worker thread in charge of getting data from the
socket->logic and vice versa.

Then i discovered MINA and I'd like to use it since its tested and stable
and works. But can I write a class (extending IoHandlerAdapter???) that not
only calls "messageReceived" when data is available from the Socket but also
periodically calls something like "shouldIsendSomeMessage" that can return
an Object to be processed by my protocolFilter or null if nothing is to be
sent out.

Of course i could start some threads to do exactly this, but i think it
might be wiser to use the worker threads that mina already provides for this
task. Is this possible at all? Does it make sense?

Thanks in advance...

Andi
-- 
View this message in context: http://www.nabble.com/How-can-I-build-a-polling-server-with-Mina--tf4855669s16868.html#a13894688
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: How can I build a polling server with Mina?

Posted by Trustin Lee <tr...@gmail.com>.
Hi Andi,

On Nov 22, 2007 8:00 PM, superandi <at...@diezwei.de> wrote:
>
> Hi there Mina-Pros,
>
> before discovering Mina I did the following:
>
> I Started a Java ServerSocket to accept connections. I remembered the
> accepted connection and waited for a new one. At server start i spawned a
> number of Worker threads that:
>
> - checked if data was available FROM each of the sockets FOR my application
> logic.
> - checked if data was available FOR one of the sockets FROM my application
> logic.
>
> Thus i put the worker thread in charge of getting data from the
> socket->logic and vice versa.
>
> Then i discovered MINA and I'd like to use it since its tested and stable
> and works. But can I write a class (extending IoHandlerAdapter???) that not
> only calls "messageReceived" when data is available from the Socket but also
> periodically calls something like "shouldIsendSomeMessage" that can return
> an Object to be processed by my protocolFilter or null if nothing is to be
> sent out.
>
> Of course i could start some threads to do exactly this, but i think it
> might be wiser to use the worker threads that mina already provides for this
> task. Is this possible at all? Does it make sense?

You might want to use sessionIdle event if the message is supposed to
be sent only when the session is idle (i.e. no data transmission for a
certain amount of time).  Otherwise, I'd recommend you to use
ScheduledExecutorService.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6