Take care of releasing the local channel when releaseExternalResources() is called. See #235

This commit is contained in:
Norman Maurer 2012-04-09 20:00:20 +02:00 committed by norman
parent a847ec1d88
commit 7eaf635059
2 changed files with 9 additions and 9 deletions

View File

@ -17,6 +17,7 @@ package io.netty.channel.local;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelSink;
import io.netty.channel.group.DefaultChannelGroup;
/**
* The default {@link LocalServerChannelFactory} implementation.
@ -24,11 +25,15 @@ import io.netty.channel.ChannelSink;
*/
public class DefaultLocalServerChannelFactory implements LocalServerChannelFactory {
private final DefaultChannelGroup group = new DefaultChannelGroup();
private final ChannelSink sink = new LocalServerChannelSink();
@Override
public LocalServerChannel newChannel(ChannelPipeline pipeline) {
return DefaultLocalServerChannel.create(this, pipeline, sink);
LocalServerChannel channel = DefaultLocalServerChannel.create(this, pipeline, sink);
group.add(channel);
return channel;
}
/**
@ -37,6 +42,6 @@ public class DefaultLocalServerChannelFactory implements LocalServerChannelFacto
*/
@Override
public void releaseExternalResources() {
// Unused
group.close();
}
}

View File

@ -69,7 +69,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);
@ -84,9 +84,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();
@ -127,7 +124,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);
@ -142,8 +139,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();