mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rainer Poisel <tm031...@fh-stpoelten.ac.at>
Subject Graceful shutdown of a client application
Date Mon, 26 May 2008 08:10:43 GMT
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.


Mime
View raw message