diff --git a/src/main/java/org/jboss/netty/channel/local/DefaultLocalServerChannelFactory.java b/src/main/java/org/jboss/netty/channel/local/DefaultLocalServerChannelFactory.java index 8a5107b865..fc0da0fb3a 100644 --- a/src/main/java/org/jboss/netty/channel/local/DefaultLocalServerChannelFactory.java +++ b/src/main/java/org/jboss/netty/channel/local/DefaultLocalServerChannelFactory.java @@ -17,6 +17,7 @@ package org.jboss.netty.channel.local; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelSink; +import org.jboss.netty.channel.group.DefaultChannelGroup; /** * The default {@link LocalServerChannelFactory} implementation. @@ -24,6 +25,7 @@ import org.jboss.netty.channel.ChannelSink; */ public class DefaultLocalServerChannelFactory implements LocalServerChannelFactory { + private final DefaultChannelGroup group = new DefaultChannelGroup(); private final ChannelSink sink = new LocalServerChannelSink(); /** @@ -34,14 +36,17 @@ public class DefaultLocalServerChannelFactory implements LocalServerChannelFacto } public LocalServerChannel newChannel(ChannelPipeline pipeline) { - return new DefaultLocalServerChannel(this, pipeline, sink); + LocalServerChannel channel = new DefaultLocalServerChannel(this, pipeline, sink); + group.add(channel); + return channel; } + /** - * Does nothing because this implementation does not require any external - * resources. + * Release all the previous created channels. This takes care of calling {@link LocalChannelRegistry#unregister(LocalAddress)} + * for each if them. */ public void releaseExternalResources() { - // Unused + group.close().awaitUninterruptibly(); } } diff --git a/src/test/java/org/jboss/netty/channel/local/LocalAddressTest.java b/src/test/java/org/jboss/netty/channel/local/LocalAddressTest.java index 4734a8877d..5f0a35529d 100644 --- a/src/test/java/org/jboss/netty/channel/local/LocalAddressTest.java +++ b/src/test/java/org/jboss/netty/channel/local/LocalAddressTest.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.ChannelEvent; import org.jboss.netty.channel.ChannelFuture; @@ -67,7 +66,7 @@ public class LocalAddressTest { LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID); // Start server - Channel channel = sb.bind(addr); + sb.bind(addr); // Connect to the server ChannelFuture connectFuture = cb.connect(addr); @@ -81,10 +80,7 @@ public class LocalAddressTest { // Wait until the connection is closed, or the connection attempt fails connectFuture.getChannel().getCloseFuture().awaitUninterruptibly(); - - // close the server channel - channel.close().awaitUninterruptibly(); - + sb.releaseExternalResources(); cb.releaseExternalResources(); @@ -123,7 +119,7 @@ public class LocalAddressTest { LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID); // Start server - Channel channel = sb.bind(addr); + sb.bind(addr); // Connect to the server ChannelFuture connectFuture = cb.connect(addr); @@ -138,9 +134,6 @@ public class LocalAddressTest { // Wait until the connection is closed, or the connection attempt fails connectFuture.getChannel().getCloseFuture().awaitUninterruptibly(); - // close the server channel - channel.close().awaitUninterruptibly(); - sb.releaseExternalResources(); cb.releaseExternalResources();