You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Rainer Poisel <tm...@fh-stpoelten.ac.at> on 2008/05/26 10:10:43 UTC
Graceful shutdown of a client application
Hej,
I am writing a client application with MINA, Version 2.0.0-M1 and JAVA 1.5 on
Linux. It seems that one of the MINA internal threads keeps running after
closing the one and only session. My application does not shutdown after
invoking the connect() method of the NioSocketConnector object at least once.
Here is the code for connection establishment:
8<============================
public boolean collect()
{
mSocketConnector = new NioSocketConnector();
mIoHandler = new CSensorHandler();
mSocketConnector.setHandler(mIoHandler);
ConnectFuture lConnectFuture = mSocketConnector.connect(mAddress);
lConnectFuture.awaitUninterruptibly();
mSession = lConnectFuture.getSession();
return lConnectFuture.isConnected();
}
8<============================
A CSensorHandler object does the following:
8<============================
public void sessionCreated(IoSession pSession) throws Exception
{
pSession.getFilterChain().addLast("codec", new ProtocolCodecFilter(
new TextLineCodecFactory()));
}
public void sessionOpened(IoSession pSession) throws Exception
{
pSession.write("GET / HTTP/1.1\nHost: localhost\n\n");
}
8<============================
All the other methods are only stubs. They don't do anything except maybe
tracing some stuff.
Closing a connection looks like this:
8<============================
public void stop()
{
if (mSession != null)
{
if (mSession.isConnected() == true)
{
// the following line is just copied from the example
mSession.close().awaitUninterruptibly();
}
}
}
8<============================
mSession.isConnected() seems always to be false, when the stop() method is
called. Did I forget to adjust the NioSocketConnector, the mSession or the
ConnectFuture object itself by invoking some methods?
Thx in advance and regards,
Rainer
--
Rainer Poisel, Project "Location Based Services", FH St. Pölten
--
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Re: Graceful shutdown of a client application
Posted by Rainer Poisel <tm...@fh-stpoelten.ac.at>.
Hej Christian,
On Monday 26 May 2008 10:18:11 you wrote:
> I stumbled over this as well, you need to call dispose() on the
> SocketConnector - after it is returning your app should quit fine.
that's it. Thx a lot! :)
Rainer
> 2008/5/26, Rainer Poisel <tm...@fh-stpoelten.ac.at>:
> > Hej,
> >
> > I am writing a client application with MINA, Version 2.0.0-M1 and JAVA
> > 1.5 on
> > Linux. It seems that one of the MINA internal threads keeps running after
> > closing the one and only session. My application does not shutdown after
> > invoking the connect() method of the NioSocketConnector object at least
> > once.
> >
> > Here is the code for connection establishment:
> > 8<============================
> > public boolean collect()
> > {
> > mSocketConnector = new NioSocketConnector();
> > mIoHandler = new CSensorHandler();
> >
> > mSocketConnector.setHandler(mIoHandler);
> > ConnectFuture lConnectFuture = mSocketConnector.connect(mAddress);
> > lConnectFuture.awaitUninterruptibly();
> > mSession = lConnectFuture.getSession();
> >
> > return lConnectFuture.isConnected();
> > }
> > 8<============================
> >
> > A CSensorHandler object does the following:
> > 8<============================
> > public void sessionCreated(IoSession pSession) throws Exception
> > {
> > pSession.getFilterChain().addLast("codec", new
> > ProtocolCodecFilter( new TextLineCodecFactory()));
> > }
> >
> > public void sessionOpened(IoSession pSession) throws Exception
> > {
> > pSession.write("GET / HTTP/1.1\nHost: localhost\n\n");
> > }
> > 8<============================
> > All the other methods are only stubs. They don't do anything except maybe
> > tracing some stuff.
> >
> > Closing a connection looks like this:
> > 8<============================
> > public void stop()
> > {
> > if (mSession != null)
> > {
> > if (mSession.isConnected() == true)
> > {
> > // the following line is just copied from the
> > example
> > mSession.close().awaitUninterruptibly();
> > }
> > }
> > }
> > 8<============================
> >
> > mSession.isConnected() seems always to be false, when the stop() method
> > is called. Did I forget to adjust the NioSocketConnector, the mSession or
> > the ConnectFuture object itself by invoking some methods?
> >
> > Thx in advance and regards,
> > Rainer
> >
> > --
> > Rainer Poisel, Project "Location Based Services", FH St. Pölten
> > --
> >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Re: Graceful shutdown of a client application
Posted by Christian Migowski <ch...@gmail.com>.
Hello Rainer,
I stumbled over this as well, you need to call dispose() on the
SocketConnector - after it is returning your app should quit fine.
hth,
regards,
christian!
2008/5/26, Rainer Poisel <tm...@fh-stpoelten.ac.at>:
>
> Hej,
>
> I am writing a client application with MINA, Version 2.0.0-M1 and JAVA 1.5
> on
> Linux. It seems that one of the MINA internal threads keeps running after
> closing the one and only session. My application does not shutdown after
> invoking the connect() method of the NioSocketConnector object at least
> once.
>
> Here is the code for connection establishment:
> 8<============================
> public boolean collect()
> {
> mSocketConnector = new NioSocketConnector();
> mIoHandler = new CSensorHandler();
>
> mSocketConnector.setHandler(mIoHandler);
> ConnectFuture lConnectFuture = mSocketConnector.connect(mAddress);
> lConnectFuture.awaitUninterruptibly();
> mSession = lConnectFuture.getSession();
>
> return lConnectFuture.isConnected();
> }
> 8<============================
>
> A CSensorHandler object does the following:
> 8<============================
> public void sessionCreated(IoSession pSession) throws Exception
> {
> pSession.getFilterChain().addLast("codec", new ProtocolCodecFilter(
> new TextLineCodecFactory()));
> }
>
> public void sessionOpened(IoSession pSession) throws Exception
> {
> pSession.write("GET / HTTP/1.1\nHost: localhost\n\n");
> }
> 8<============================
> All the other methods are only stubs. They don't do anything except maybe
> tracing some stuff.
>
> Closing a connection looks like this:
> 8<============================
> public void stop()
> {
> if (mSession != null)
> {
> if (mSession.isConnected() == true)
> {
> // the following line is just copied from the
> example
> mSession.close().awaitUninterruptibly();
> }
> }
> }
> 8<============================
>
> mSession.isConnected() seems always to be false, when the stop() method is
> called. Did I forget to adjust the NioSocketConnector, the mSession or the
> ConnectFuture object itself by invoking some methods?
>
> Thx in advance and regards,
> Rainer
>
> --
> Rainer Poisel, Project "Location Based Services", FH St. Pölten
> --
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>