mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trustin Lee" <trus...@gmail.com>
Subject Re: Managing large number of Connectors
Date Fri, 07 Dec 2007 02:18:08 GMT
Hi Luc,

On Dec 7, 2007 3:30 AM, Luc Willems <willems.luc@pandora.be> wrote:
> On Thursday 06 December 2007 07:27:17 Trustin Lee wrote:
> > Hi Vishal,
> >
> > On Dec 6, 2007 2:53 PM, Vishal_Jain <pingvishal@gmail.com> wrote:
> > > Hi Trustin,
> > >
> > > Yes i did try to follow the Thread model tutorial. As is evident, its not
> > > clear to me :)
> > >
> > > I seem to have missed to understand, One Connector tied with one I/O
> > > handler. Thanks for clearing that up for me.
> > > now, for every session that  is created by calling connector.connect(), i
> > > need to attach some application specific data.
> > > Would it be ok to wait on the ConnectFuture object to join() and then add
> > > the data to the session attachment ?
> > > (i ask because, connection setup may take a while and in the meantime i
> > > would have received more requests to forward)
> >
> > ConnectFuture completes after sessionOpened event is processed.
> > Therefore, sessionCreated and sessionOpened event handlers will not
> > see the attachment.  You could attach in your IoHandler, or you could
> > try org.apache.mina.handler.multiton package which helps you to create
> > a handler in a per-session manner.
> >
>                         hello all ,
>
> i have a same kind of problem when converting 1.1.x mina based code to
>
> 2.0.0.M1 codebase.
>
> I have some code that simulates a user. This user has a  1 instance of a Connection 
agent class that implements IoHandler interface
>  and keeps track of communcation over 1 TCP connection. when de user need to send/connect
to a remote server,
>  it ask the agent to setup a connection.
>
> this agent class would do
>
>         public void connect() {
>                 cf=connector.connect(address, null,  this, config)  --> where this
is the Agent class
>                 cf.await();
>         }
>
>         public void sessionCreated(..) {
>                 this.session=session;
>         }
>
>         public void send() {
>                 this.session.write(message);
>         }
>
> this way the agent class gets all the notification events and could handle the TCP
> communication from "just before" creation until the end.
> the user keeps a reference to the agent to delegate the IO requests.
> any message send before connection is finished can be buffered until the session is created.
> this way we don't have to wait until connection is finished ,or not.
>
> in MINA 2.0.0 i can't do this any more because connect() method has been simplified.
> in 2.0.0. i have to wait until connection is finished and after that a can attach my
handler to
> the session and use a delegating IoHandler to delegate al events.
>
> i looked at the 2.0.0 org.apache.mina.handler.multiton classes but they don't implement
what i need .
> it uses the SingleSessionIoHandlerFactory to link a just created IoSession with a SingleSessionIoHandler
instance.
>
> the problem with this aproche is that the Factory doesn't know about my Agent class.
we could implement
> a factory that keeps track of all Agents but how do we link agent.connect() with the
just created IoSession in a
> multi thread save way without blocking ?
>
> it would be nice that connector.connect() would have a implementation that we
> could attach a object to this connection before IoSession is created or even better ,
like the 1.1.x example.
> this would make the SingleSessionIoHandler implementation simple by
> doing :
>
>         - create custom class that extends/implements SingleSessionIoHandler/SingleSessionIo
interface
>         - use connector.connect(address,userIoHandler)
>
> after that all events should be deligated to userIoHandler.

I am not sure I understood your question correctly, but you might want
to create your own IoFilter and insert it to get notified before the
ConnectFuture is complete.  If your custom IoFilter, you can relate
your Agent and IoSession easily.

Moreover, I think you can still do the same by calling the following
statement assuming you are using the same handler instance:

connector.setHandler(this);

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

Mime
View raw message