You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Bogdan Ciprian Pistol <bo...@gmail.com> on 2007/11/12 14:08:15 UTC

Asynchronous close( ) after write( )

Hello,

In a IoHandler if I do:

session.write(something);
session.close( );

Is it OK? It is possible that session.close( ) will be called in the
middle of session.write(something)?

Or I should do it like this:

session.write(something).join( );
session.close( );

Thanks,

Bogdan

Re: Asynchronous close( ) after write( )

Posted by Bogdan Ciprian Pistol <bo...@gmail.com>.
> IoSession should be thread-safem which means you can call IoSession
> whereever and whenever.  Sounds good?  :)

Great, thanks :)

Re: Asynchronous close( ) after write( )

Posted by Trustin Lee <tr...@gmail.com>.
On Nov 13, 2007 7:02 PM, Bogdan Ciprian Pistol <bo...@gmail.com> wrote:
> > The best way is:
> >
> > session.write(something).addListener(IoFutureListener.CLOSE);
>
> Thanks Trustin,
>
> One more question...
>
> I store the IoSession in a custom Object and when data is available I
> call session.write( ) from another thread to send the data out.
> Can I use IoSession outside of IoHandler or it's thread? I should be
> aware of some synchronization issues, is IoSession thread safe?

IoSession should be thread-safem which means you can call IoSession
whereever and whenever.  Sounds good?  :)

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

Re: Asynchronous close( ) after write( )

Posted by Bogdan Ciprian Pistol <bo...@gmail.com>.
> The best way is:
>
> session.write(something).addListener(IoFutureListener.CLOSE);

Thanks Trustin,

One more question...

I store the IoSession in a custom Object and when data is available I
call session.write( ) from another thread to send the data out.
Can I use IoSession outside of IoHandler or it's thread? I should be
aware of some synchronization issues, is IoSession thread safe?

Bogdan

Re: Asynchronous close( ) after write( )

Posted by Trustin Lee <tr...@gmail.com>.
On Nov 12, 2007 10:08 PM, Bogdan Ciprian Pistol <bo...@gmail.com> wrote:
> Hello,
>
> In a IoHandler if I do:
>
> session.write(something);
> session.close( );
>
> Is it OK? It is possible that session.close( ) will be called in the
> middle of session.write(something)?

Not OK.

> Or I should do it like this:
>
> session.write(something).join( );
> session.close( );

The best way is:

session.write(something).addListener(IoFutureListener.CLOSE);

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