Take care of releasing the local channel when releaseExternalResources() is called. See #235
This commit is contained in:
parent
a847ec1d88
commit
7eaf635059
@ -17,6 +17,7 @@ package io.netty.channel.local;
|
|||||||
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.ChannelSink;
|
import io.netty.channel.ChannelSink;
|
||||||
|
import io.netty.channel.group.DefaultChannelGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default {@link LocalServerChannelFactory} implementation.
|
* The default {@link LocalServerChannelFactory} implementation.
|
||||||
@ -24,11 +25,15 @@ import io.netty.channel.ChannelSink;
|
|||||||
*/
|
*/
|
||||||
public class DefaultLocalServerChannelFactory implements LocalServerChannelFactory {
|
public class DefaultLocalServerChannelFactory implements LocalServerChannelFactory {
|
||||||
|
|
||||||
|
private final DefaultChannelGroup group = new DefaultChannelGroup();
|
||||||
|
|
||||||
private final ChannelSink sink = new LocalServerChannelSink();
|
private final ChannelSink sink = new LocalServerChannelSink();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalServerChannel newChannel(ChannelPipeline pipeline) {
|
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
|
@Override
|
||||||
public void releaseExternalResources() {
|
public void releaseExternalResources() {
|
||||||
// Unused
|
group.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class LocalAddressTest {
|
|||||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
Channel channel = sb.bind(addr);
|
sb.bind(addr);
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
ChannelFuture connectFuture = cb.connect(addr);
|
ChannelFuture connectFuture = cb.connect(addr);
|
||||||
@ -84,9 +84,6 @@ public class LocalAddressTest {
|
|||||||
// Wait until the connection is closed, or the connection attempt fails
|
// Wait until the connection is closed, or the connection attempt fails
|
||||||
connectFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
connectFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
||||||
|
|
||||||
// close the server channel
|
|
||||||
channel.close().awaitUninterruptibly();
|
|
||||||
|
|
||||||
sb.releaseExternalResources();
|
sb.releaseExternalResources();
|
||||||
cb.releaseExternalResources();
|
cb.releaseExternalResources();
|
||||||
|
|
||||||
@ -127,7 +124,7 @@ public class LocalAddressTest {
|
|||||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
Channel channel = sb.bind(addr);
|
sb.bind(addr);
|
||||||
|
|
||||||
// Connect to the server
|
// Connect to the server
|
||||||
ChannelFuture connectFuture = cb.connect(addr);
|
ChannelFuture connectFuture = cb.connect(addr);
|
||||||
@ -142,8 +139,6 @@ public class LocalAddressTest {
|
|||||||
// Wait until the connection is closed, or the connection attempt fails
|
// Wait until the connection is closed, or the connection attempt fails
|
||||||
connectFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
connectFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
||||||
|
|
||||||
// close the server channel
|
|
||||||
channel.close().awaitUninterruptibly();
|
|
||||||
|
|
||||||
sb.releaseExternalResources();
|
sb.releaseExternalResources();
|
||||||
cb.releaseExternalResources();
|
cb.releaseExternalResources();
|
||||||
|
Loading…
Reference in New Issue
Block a user