You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Austin Lee <au...@gmail.com> on 2006/07/07 19:30:37 UTC

Question regarding doing a "push" from the server side

Hi all.

I have a simple question for which there is probably a simple answer
that I just haven't stumbled upon in the documentation. If I am
running a server with say 1,000 clients, and I want to push a message
to one of the clients, say client#68, how would I go about doing this
using the MINA framework? For instance, if my server is the famous
chat server example, and I wish to send a private message to
client#68, based on an asyncronous request that is triggered by an
outside process (not having every client poll for PMs).

In traditional Java NIO server code, I would put the logic to check
for a PM (say waiting in a queue on another thread) in the PRIMARY
execution loop / dispatcher where the keys are read in, perhaps just
one line above the code that grabs in the keys for selecting and
sending to the handlers. Is there a built-in way to do this in MINA
that I could use? Am I going about this the wrong way?

Thanks in advance,
Austin

Re: Question regarding doing a "push" from the server side

Posted by Austin Lee <au...@gmail.com>.
That was exactly what I was looking for! very well put. thanks a ton
Pete; i'll try it out.

Austin

On 7/7/06, peter royal <pr...@apache.org> wrote:
> On Jul 7, 2006, at 1:30 PM, Austin Lee wrote:
> > I have a simple question for which there is probably a simple answer
> > that I just haven't stumbled upon in the documentation. If I am
> > running a server with say 1,000 clients, and I want to push a message
> > to one of the clients, say client#68, how would I go about doing this
> > using the MINA framework? For instance, if my server is the famous
> > chat server example, and I wish to send a private message to
> > client#68, based on an asyncronous request that is triggered by an
> > outside process (not having every client poll for PMs).
>
> You are going to want to maintain your own mapping of client identity
> -> IoSession's, then its just a matter of getting the IoSession for
> that client, and calling IoSession.write()
>
> ... alternately, you can leverage MINA's mapping that it keeps, using
> IoAcceptor.getManagedSession(), but you'll need the client's
> SocketAddress then to do the lookup.
>
> I'd implement it like this:
>
> * in your IoHandler register the client's IoSession once you have
> established the client's identity with your own registry
> * have a thread/task that monitor's a Queue for things-to-send-to-
> clients
> * the above will read off the thing to send, look up the client's
> IoSession based up on the identity that the message contains
> * IoSession.write() out the message to the client
>
> -pete
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>

Re: Question regarding doing a "push" from the server side

Posted by peter royal <pr...@apache.org>.
On Jul 7, 2006, at 1:30 PM, Austin Lee wrote:
> I have a simple question for which there is probably a simple answer
> that I just haven't stumbled upon in the documentation. If I am
> running a server with say 1,000 clients, and I want to push a message
> to one of the clients, say client#68, how would I go about doing this
> using the MINA framework? For instance, if my server is the famous
> chat server example, and I wish to send a private message to
> client#68, based on an asyncronous request that is triggered by an
> outside process (not having every client poll for PMs).

You are going to want to maintain your own mapping of client identity  
-> IoSession's, then its just a matter of getting the IoSession for  
that client, and calling IoSession.write()

... alternately, you can leverage MINA's mapping that it keeps, using  
IoAcceptor.getManagedSession(), but you'll need the client's  
SocketAddress then to do the lookup.

I'd implement it like this:

* in your IoHandler register the client's IoSession once you have  
established the client's identity with your own registry
* have a thread/task that monitor's a Queue for things-to-send-to- 
clients
* the above will read off the thing to send, look up the client's  
IoSession based up on the identity that the message contains
* IoSession.write() out the message to the client

-pete

-- 
proyal@apache.org - http://fotap.org/~osi