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

This commit is contained in:
Norman Maurer 2012-04-09 20:06:20 +02:00
parent 403fdb2035
commit ef530698c5
2 changed files with 12 additions and 14 deletions

View File

@ -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();
}
}

View File

@ -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();