You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by th...@accenture.com on 2008/05/02 17:50:27 UTC
attempting a clean shutdown ends hung
Using MINA 2.0.0-M1, I am trying a simple application that binds tcpAcceptor then attempts to cleanly shutdown the app. The application is hung after the last line. I'm looking for what else I would need to do. Any suggestions?
package com;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import java.net.InetSocketAddress;
import java.util.logging.Logger;
public class MinaTest {
private static final Logger LOG = Logger.getLogger("MinaTest");
public static void main(String[] args) throws Exception {
int port = 8282;
IoAcceptor tcpAcceptor = null;
try {
tcpAcceptor = new NioSocketAcceptor();
tcpAcceptor.setHandler(new TimeServerHandler());
tcpAcceptor.setDefaultLocalAddress(new InetSocketAddress(port));
tcpAcceptor.bind();
} catch (Exception e) {
LOG.warning("exception creating acceptor");
e.printStackTrace();
}
Thread.sleep(10000);
try {
tcpAcceptor.unbind();
tcpAcceptor=null;
} catch (Exception e) {
LOG.warning("exception unbinding");
e.printStackTrace();
}
LOG.info("done"); // I get this, put the java process does not terminate
}
}
====================
package com;
import java.util.Date;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
public class TimeServerHandler extends IoHandlerAdapter {
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
cause.printStackTrace();
}
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
String str = message.toString();
if (str.trim().equalsIgnoreCase("quit")) {
session.close();
return;
}
Date date = new Date();
session.write(date.toString());
System.out.println("Message written...");
}
@Override
public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
System.out.println("IDLE " + session.getIdleCount(status));
}
}
Jeff
This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.
Re: attempting a clean shutdown ends hung
Posted by jblack4 <th...@accenture.com>.
That worked. Thank you for your help.
Alex Stumpfl wrote:
>
> hi, simply dispose() your acceptor (unbind() will be called implicitly):
> rgds, alex ;)
>
> thomas.black@accenture.com schrieb:
>> Using MINA 2.0.0-M1, I am trying a simple application that binds
>> tcpAcceptor then attempts to cleanly shutdown the app. The application
>> is hung after the last line. I'm looking for what else I would need to
>> do. Any suggestions?
>>
>> package com;
>> import org.apache.mina.common.IoAcceptor;
>> import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
>> import java.net.InetSocketAddress;
>> import java.util.logging.Logger;
>> public class MinaTest {
>> private static final Logger LOG = Logger.getLogger("MinaTest");
>> public static void main(String[] args) throws Exception {
>> int port = 8282;
>> IoAcceptor tcpAcceptor = null;
>> try {
>> tcpAcceptor = new NioSocketAcceptor();
>> tcpAcceptor.setHandler(new TimeServerHandler());
>> tcpAcceptor.setDefaultLocalAddress(new
>> InetSocketAddress(port));
>> tcpAcceptor.bind();
>> } catch (Exception e) {
>> LOG.warning("exception creating acceptor");
>> e.printStackTrace();
>> }
>> Thread.sleep(10000);
>> try {
>> tcpAcceptor.unbind();
>> tcpAcceptor=null;
>> } catch (Exception e) {
>> LOG.warning("exception unbinding");
>> e.printStackTrace();
>> }
>> LOG.info("done"); // I get this, put the java process does not
>> terminate
>> }
>> }
>>
>> ====================
>>
>> package com;
>> import java.util.Date;
>> import org.apache.mina.common.IdleStatus;
>> import org.apache.mina.common.IoHandlerAdapter;
>> import org.apache.mina.common.IoSession;
>> public class TimeServerHandler extends IoHandlerAdapter {
>> @Override
>> public void exceptionCaught(IoSession session, Throwable cause)
>> throws Exception {
>> cause.printStackTrace();
>> }
>> @Override
>> public void messageReceived(IoSession session, Object message) throws
>> Exception {
>> String str = message.toString();
>> if (str.trim().equalsIgnoreCase("quit")) {
>> session.close();
>> return;
>> }
>> Date date = new Date();
>> session.write(date.toString());
>> System.out.println("Message written...");
>> }
>> @Override
>> public void sessionIdle(IoSession session, IdleStatus status) throws
>> Exception {
>> System.out.println("IDLE " + session.getIdleCount(status));
>> }
>> }
>>
>>
>>
>>
>> Jeff
>>
>>
>> This message is for the designated recipient only and may contain
>> privileged, proprietary, or otherwise private information. If you have
>> received it in error, please notify the sender immediately and delete the
>> original. Any other use of the email by you is prohibited.
>>
>
> --
> Mit freundlichen Grüßen,
> Alex Stumpfl
>
> Jazzey GmbH - Hellbrunnerstraße 11a - A-5020 Salzburg
> Tel: +43-662-840841-0
> Fax: +43-662-840841-200
> Web: www.jazzey.com
> Firmenbuch-Nr: FN 201708 f
> Firmenbuchgericht: Landesgericht Salzburg
> UID-Nr: ATU 50652805
>
>
--
View this message in context: http://www.nabble.com/attempting-a-clean-shutdown-ends-hung-tp17022312p17063101.html
Sent from the Apache MINA User Forum mailing list archive at Nabble.com.
Re: attempting a clean shutdown ends hung
Posted by Alex Stumpfl <al...@jazzey.com>.
hi, simply dispose() your acceptor (unbind() will be called implicitly):
rgds, alex ;)
thomas.black@accenture.com schrieb:
> Using MINA 2.0.0-M1, I am trying a simple application that binds tcpAcceptor then attempts to cleanly shutdown the app. The application is hung after the last line. I'm looking for what else I would need to do. Any suggestions?
>
> package com;
> import org.apache.mina.common.IoAcceptor;
> import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
> import java.net.InetSocketAddress;
> import java.util.logging.Logger;
> public class MinaTest {
> private static final Logger LOG = Logger.getLogger("MinaTest");
> public static void main(String[] args) throws Exception {
> int port = 8282;
> IoAcceptor tcpAcceptor = null;
> try {
> tcpAcceptor = new NioSocketAcceptor();
> tcpAcceptor.setHandler(new TimeServerHandler());
> tcpAcceptor.setDefaultLocalAddress(new InetSocketAddress(port));
> tcpAcceptor.bind();
> } catch (Exception e) {
> LOG.warning("exception creating acceptor");
> e.printStackTrace();
> }
> Thread.sleep(10000);
> try {
> tcpAcceptor.unbind();
> tcpAcceptor=null;
> } catch (Exception e) {
> LOG.warning("exception unbinding");
> e.printStackTrace();
> }
> LOG.info("done"); // I get this, put the java process does not terminate
> }
> }
>
> ====================
>
> package com;
> import java.util.Date;
> import org.apache.mina.common.IdleStatus;
> import org.apache.mina.common.IoHandlerAdapter;
> import org.apache.mina.common.IoSession;
> public class TimeServerHandler extends IoHandlerAdapter {
> @Override
> public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
> cause.printStackTrace();
> }
> @Override
> public void messageReceived(IoSession session, Object message) throws Exception {
> String str = message.toString();
> if (str.trim().equalsIgnoreCase("quit")) {
> session.close();
> return;
> }
> Date date = new Date();
> session.write(date.toString());
> System.out.println("Message written...");
> }
> @Override
> public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
> System.out.println("IDLE " + session.getIdleCount(status));
> }
> }
>
>
>
>
> Jeff
>
>
> This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.
>
--
Mit freundlichen Grüßen,
Alex Stumpfl
Jazzey GmbH - Hellbrunnerstraße 11a - A-5020 Salzburg
Tel: +43-662-840841-0
Fax: +43-662-840841-200
Web: www.jazzey.com
Firmenbuch-Nr: FN 201708 f
Firmenbuchgericht: Landesgericht Salzburg
UID-Nr: ATU 50652805