You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by 차민창 <mi...@naver.com> on 2008/02/25 17:59:51 UTC

blocked NioSocketAcceptor.unbind call

Hi,
I`m new to Mina 2.0.0M.
I`m writting a simple server with reading 'MINA v2.0 Quick Start Guide'.
Now it seems like working fine at least interacting packets.
But there is a problem with calling NioSocketAcceptor.unbind to terminate server.
When I was calling the method, my server application was blocked.
A blocking point, which is found though tracking Mina sources, is ...
 
IoServiceListener.disconnectSessions
 for (IoSession s : managedSessions) { // There was only one item when I was testing.
 s.close().addListener(listener);
 }
 try {
 synchronized (lock) {
 // Here was a blocking point.
 // managedSessions was not empty(have an item) so could`t exit below while statement.(like an infinite loop)
 while (!managedSessions.isEmpty()) { 
 lock.wait(500);
 }
 }
 ...
 
There is my miss? Any idea?
 
This is my source.
 
public class Collector extends IoHandlerAdapter {
 private static Log output = LogFactory.getLog("statlog");
 private static Log monitor = LogFactory.getLog("monitor");
 private static Log log = LogFactory.getLog(Collector.class);
 private static long connectionCount = 0;
 private static long receivedBytes = 0;
 private static long receivedMessageCount = 0;
 private static long errorCount = 0;
 private static NioSocketAcceptor acceptor = new NioSocketAcceptor();
 private static NioSocketAcceptor commander = new NioSocketAcceptor();
 
 static void shutdown() {
 acceptor.unbind();
 commander.unbind();
 System.exit(0);
 }
 public static void main(String[] args) throws IOException {
 Integer port;
 if (args.length > 0) {
 port = Integer.parseInt(args[0]);
 } else {
 final String PORT_KEY = "collector.port";
 System.out.println(Config.get(PORT_KEY));
 port = Integer.parseInt(Config.get(PORT_KEY));
 }
 
 acceptor.getFilterChain().addLast( "codec", CollectorResouces.CODEC);
 acceptor.setHandler(new Collector());
 acceptor.setDefaultLocalAddress(new InetSocketAddress(port));
 acceptor.setCloseOnDeactivation(true);
 acceptor.bind();
 commander.getFilterChain().addLast( "codec", CollectorResouces.CODEC);
 commander.setHandler(new CommanderIoHandler());
 commander.setDefaultLocalAddress(new InetSocketAddress(port + 100));
 commander.setCloseOnDeactivation(true);
 commander.bind();
 
 Thread t = new Thread(new StatusLogger());
 t.start();
 }
 @Override
 public void exceptionCaught(IoSession session, Throwable t) throws Exception {
 t.printStackTrace();
 session.close();
 errorCount++;
 }
 @Override
 public void messageReceived(IoSession session, Object msg) throws Exception {
 String str = msg.toString();
 output.info(str);
 receivedMessageCount++;
 receivedBytes = receivedBytes + str.getBytes().length;
 }
 @Override
 public void sessionCreated(IoSession session) throws Exception {
 log.info("Session created");
 connectionCount++;
 }
 @Override
 public void sessionClosed(IoSession arg0) throws Exception {
 log.info("Session closed");
 connectionCount--;
 }
 static class StatusLogger implements Runnable {
 final Integer SLEEP = 10000;
 public void run() {
 try {
 while (true) {
 monitor.info("Conn:"+connectionCount +
 " ReceivedMsgCount:" + receivedMessageCount +
 " ReceivedBytes:" + receivedBytes +
 " ErrorCount:" + errorCount);
 Thread.sleep(SLEEP);
 }
 } catch (Exception e) {
 log.error(e);
 }
 }
 }
}
 
 
민달군의 패스~!
단지 기도하며 걸어갈 뿐...