Add ServerBootstrap.group() that takes a single group

This commit is contained in:
Trustin Lee 2012-08-10 20:26:04 +09:00
parent d298707198
commit d3a2835503
5 changed files with 17 additions and 5 deletions

View File

@ -49,7 +49,7 @@ public class LocalEcho {
// Note that we can use any event loop to ensure certain local channels
// are handled by the same event loop thread which drives a certain socket channel
// to reduce the communication latency between socket channels and local channels.
sb.group(new LocalEventLoopGroup(), new LocalEventLoopGroup())
sb.group(new LocalEventLoopGroup())
.channel(new LocalServerChannel())
.localAddress(addr)
.handler(new ChannelInitializer<LocalServerChannel>() {
@ -67,7 +67,7 @@ public class LocalEcho {
}
});
cb.group(new NioEventLoopGroup())
cb.group(new NioEventLoopGroup()) // NIO event loops are also OK
.channel(new LocalChannel())
.remoteAddress(addr)
.handler(new ChannelInitializer<LocalChannel>() {

View File

@ -56,7 +56,7 @@ final class SocketTestPermutation {
public ServerBootstrap newInstance() {
AioEventLoopGroup loop = new AioEventLoopGroup();
return new ServerBootstrap().
group(loop, loop).
group(loop).
channel(new AioServerSocketChannel(loop));
}
});

View File

@ -63,6 +63,18 @@ public class ServerBootstrap {
private ChannelHandler childHandler;
private SocketAddress localAddress;
public ServerBootstrap group(EventLoopGroup group) {
if (group == null) {
throw new NullPointerException("group");
}
if (parentGroup != null) {
throw new IllegalStateException("parentGroup set already");
}
parentGroup = group;
childGroup = group;
return this;
}
public ServerBootstrap group(EventLoopGroup parentGroup, EventLoopGroup childGroup) {
if (parentGroup == null) {
throw new NullPointerException("parentGroup");

View File

@ -47,7 +47,7 @@ public class LocalChannelRegistryTest {
.remoteAddress(addr)
.handler(new TestHandler());
sb.group(new LocalEventLoopGroup(), new LocalEventLoopGroup())
sb.group(new LocalEventLoopGroup())
.channel(new LocalServerChannel())
.localAddress(addr)
.childHandler(new ChannelInitializer<LocalChannel>() {

View File

@ -57,7 +57,7 @@ public class LocalTransportThreadModelTest {
public static void init() {
// Configure a test server
sb = new ServerBootstrap();
sb.group(new LocalEventLoopGroup(), new LocalEventLoopGroup())
sb.group(new LocalEventLoopGroup())
.channel(new LocalServerChannel())
.localAddress(LocalAddress.ANY)
.childHandler(new ChannelInitializer<LocalChannel>() {