Shutdown of Server Channel Factory
Michael McGrady
mmcgrady at topiatechnology.com
Wed Sep 9 16:09:59 EDT 2009
Hi, Thomas,
First, thanks for all this help. Most importantly it was immediate
and it does not get better than that.
Second, I used your suggestion of the ChannelGroup close and that is
working great. I will have to figure out later why that is. I have
done no more than the ChannelGroup javadocs recommends to make it
work, other than pass the object references around a bit.
Mike
On Sep 9, 2009, at 12:33 PM, Thomas Bocek wrote:
> Hi Michael,
>
> Hmm, it should work like this. I have attached a small app that
> opens a
> channel, closes it and releases resources. The last two lines are:
>
> server.close().awaitUninterruptibly();
> cfServer.releaseExternalResources();
>
> Can you try to see what the difference is between the attached and
> your
> code?
>
> Thomas
>
> Michael McGrady wrote:
>> Hi, Thomas,
>>
>> I tried a slight modification in logging and got the same result as
>> before. Also, I know the close operation finishes because it shows
>> as
>> finished and the channel connection as closed. At least I think I
>> know
>> that. Do you think otherwise? Thanks, again, for the help.
>>
>>
>>
>> public void stop() {
>> this.channel.close().awaitUninterruptibly();
>> logger.log(InternalLogLevel.INFO,
>> this.getClass().getSimpleName()
>> + " start stop");
>> NettyKarmaReceiver.this.factory.releaseExternalResources();
>> logger.log(InternalLogLevel.INFO,
>> this.getClass().getSimpleName()
>> + " end stop");
>> }
>>
>> On Sep 9, 2009, at 10:44 AM, Thomas Bocek wrote:
>>
>>> Michael, try this one:
>>>
>>> public void stop() {
>>> logger.log(InternalLogLevel.INFO, this.getClass().getSimpleName()
>>> + " start stop");
>>> this.channel.close().awaitUninterruptibly();
>>> NettyKarmaReceiver.this.factory.releaseExternalResources();
>>> logger.log(InternalLogLevel.INFO, this.getClass().getSimpleName()
>>> + " end stop");
>>> }
>>>
>>> If you block in the Netty thread, then the close operation is never
>>> finished, and the terminate() call is in an endless loop,
>>> resulting in a
>>> deadlock. Either you do it outside the Netty thread as above, or you
>>> create a new Thread and run it there.
>>>
>>> Thomas
>>>
>>> Michael McGrady wrote:
>>>> Thanks, Thomas. The following is the code I am using and in this
>>>> test
>>>> there is no other connection than the one.
>>>>
>>>>
>>>>
>>>> public void stop() {
>>>> logger.log(InternalLogLevel.INFO,
>>>> this.getClass().getSimpleName()
>>>> + " start stop");
>>>> ChannelFuture close = this.channel.close();
>>>>
>>>> close.addListener(new ChannelFutureListener() {
>>>>
>>>> public void operationComplete(ChannelFuture future)
>>>> throws Exception {
>>>>
>>>> NettyKarmaReceiver.this.factory.releaseExternalResources();
>>>>
>>>> logger.log(InternalLogLevel.INFO,
>>>> this.getClass().getSimpleName()
>>>> + " end stop");
>>>> }
>>>>
>>>> });
>>>> }
>>>>
>>>>
>>>>
>>>> On Sep 9, 2009, at 10:09 AM, Thomas Bocek wrote:
>>>>
>>>>> Michael McGrady wrote:
>>>>>> I am not getting a return from the
>>>>>> NeoServerSocketChannelFactory's
>>>>>> releaseExternalResources method. Is this something anyone else
>>>>>> has
>>>>>> seen? This is very surprising to me because this is just in
>>>>>> essence a
>>>>>> return from the ExecutorUtil terminate method which just copies
>>>>>> and
>>>>>> shuts down the copies as ExecutorServices shutdown method. There
>>>>>> should be only a 100 millisecond wait in that method.
>>>>>
>>>>> The awaitTermination() call may return false, so it will wait
>>>>> longer
>>>>> than 100msec.
>>>>>
>>>>>> Any ideas?
>>>>>
>>>>> Make sure you have closed all connections before calling
>>>>> releaseExternalResources. You can use the ChannelGroup to group
>>>>> channels
>>>>> and close them with ChannelGroup.close().
>>>>>
>>>>> Thomas
>>>>> _______________________________________________
>>>>> netty-users mailing list
>>>>> netty-users at lists.jboss.org
>>>>> https://lists.jboss.org/mailman/listinfo/netty-users
>>>>
>>>> Mike McGrady
>>>> Principal Investigator AF081-028 AFRL SBIR
>>>> Senior Engineer
>>>> Topia Technology, Inc
>>>> 1.253.720.3365
>>>> mmcgrady at topiatechnology.com
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>> _______________________________________________
>>>> netty-users mailing list
>>>> netty-users at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/netty-users
>>> _______________________________________________
>>> netty-users mailing list
>>> netty-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
>> Mike McGrady
>> Principal Investigator AF081-028 AFRL SBIR
>> Senior Engineer
>> Topia Technology, Inc
>> 1.253.720.3365
>> mmcgrady at topiatechnology.com
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
> import java.net.InetSocketAddress;
> import java.util.concurrent.Executors;
> import org.jboss.netty.bootstrap.ClientBootstrap;
> import org.jboss.netty.bootstrap.ServerBootstrap;
> import org.jboss.netty.channel.Channel;
> import org.jboss.netty.channel.ChannelFactory;
> import org.jboss.netty.channel.ChannelFuture;
> import org.jboss.netty.channel.ChannelFutureListener;
> import org.jboss.netty.channel.ChannelHandlerContext;
> import org.jboss.netty.channel.ChannelPipeline;
> import org.jboss.netty.channel.MessageEvent;
> import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
> import
> org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
> import
> org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
> import org.jboss.netty.handler.codec.string.StringDecoder;
> import org.jboss.netty.handler.codec.string.StringEncoder;
>
> public class TCPCloseTest
> {
> public static void main(String[] args) throws Exception
> {
> // /////////////////////// Server
> ChannelFactory cfServer = new NioServerSocketChannelFactory(
> Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
> ServerBootstrap sb = new ServerBootstrap(cfServer);
> ChannelPipeline pd = sb.getPipeline();
> pd.addLast("encoder", new StringEncoder("UTF-8"));
> pd.addLast("decoder", new StringDecoder("UTF-8"));
> pd.addLast("handler", new SimpleChannelUpstreamHandler()
> {
> @Override
> public void messageReceived(final ChannelHandlerContext ctx,
> MessageEvent e)
> throws Exception
> {
> e.getChannel().write("hello", e.getRemoteAddress()).addListener(
> new ChannelFutureListener()
> {
> @Override
> public void operationComplete(ChannelFuture future) throws
> Exception
> {
> ctx.getChannel().close();
> }
> });
> }
> });
> Channel server = sb.bind(new InetSocketAddress(9000));
> // /////////////////////// Client
> ChannelFactory cfClient = new NioClientSocketChannelFactory(
> Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
> ClientBootstrap cb = new ClientBootstrap(cfClient);
> ChannelPipeline p1 = cb.getPipeline();
> p1.addLast("encoder", new StringEncoder("UTF-8"));
> p1.addLast("decoder", new StringDecoder("UTF-8"));
> p1.addLast("handler", new SimpleChannelUpstreamHandler()
> {
> @Override
> public void messageReceived(ChannelHandlerContext ctx,
> MessageEvent e) throws Exception
> {
> System.out.println("got " + e.getMessage());
> }
> });
> ChannelFuture cfu = cb.connect(new InetSocketAddress("127.0.0.1",
> 9000));
> cfu.getChannel().write("ping");
> cfu.getChannel().getCloseFuture().awaitUninterruptibly();
> cfClient.releaseExternalResources();
> server.close().awaitUninterruptibly();
> cfServer.releaseExternalResources();
> }
> }
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
Mike McGrady
Principal Investigator AF081-028 AFRL SBIR
Senior Engineer
Topia Technology, Inc
1.253.720.3365
mmcgrady at topiatechnology.com
More information about the netty-users
mailing list