diff --git a/common/src/main/java/io/netty/util/concurrent/ImmediateEventExecutor.java b/common/src/main/java/io/netty/util/concurrent/ImmediateEventExecutor.java index c64761edd3..48b399ca12 100644 --- a/common/src/main/java/io/netty/util/concurrent/ImmediateEventExecutor.java +++ b/common/src/main/java/io/netty/util/concurrent/ImmediateEventExecutor.java @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit; public final class ImmediateEventExecutor extends AbstractEventExecutor { public static final ImmediateEventExecutor INSTANCE = new ImmediateEventExecutor(); - private ImmediateEventExecutor() { + private ImmediateEventExecutor() { // use static instance } diff --git a/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java b/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java index 882fae8e04..2c2b28ece0 100644 --- a/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java +++ b/example/src/main/java/io/netty/example/securechat/SecureChatServerHandler.java @@ -24,6 +24,7 @@ import io.netty.channel.group.DefaultChannelGroup; import io.netty.handler.ssl.SslHandler; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; +import io.netty.util.concurrent.GlobalEventExecutor; import java.net.InetAddress; import java.util.logging.Level; @@ -37,7 +38,7 @@ public class SecureChatServerHandler extends ChannelInboundHandlerAdapter { private static final Logger logger = Logger.getLogger( SecureChatServerHandler.class.getName()); - static final ChannelGroup channels = new DefaultChannelGroup(); + static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); @Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java index dcfcc59424..51e23dd29a 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/udt/UDTClientServerConnectionTest.java @@ -33,11 +33,13 @@ import io.netty.handler.codec.Delimiters; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import io.netty.util.CharsetUtil; +import io.netty.util.concurrent.DefaultThreadFactory; +import io.netty.util.concurrent.GlobalEventExecutor; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.ThreadFactory; import static org.junit.Assert.*; @@ -65,7 +67,7 @@ public class UDTClientServerConnectionTest { @Override public void run() { final Bootstrap boot = new Bootstrap(); - final ThreadFactory clientFactory = new ThreadFactory("client"); + final ThreadFactory clientFactory = new DefaultThreadFactory("client"); final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, clientFactory, NioUdtProvider.BYTE_PROVIDER); try { @@ -143,9 +145,6 @@ public class UDTClientServerConnectionTest { volatile boolean isActive; - ClientHandler() { - } - @Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { @@ -182,7 +181,7 @@ public class UDTClientServerConnectionTest { static final Logger log = LoggerFactory.getLogger(Server.class); - final ChannelGroup group = new DefaultChannelGroup("server group"); + final ChannelGroup group = new DefaultChannelGroup("server group", GlobalEventExecutor.INSTANCE); final String host; final int port; @@ -199,8 +198,8 @@ public class UDTClientServerConnectionTest { @Override public void run() { final ServerBootstrap boot = new ServerBootstrap(); - final ThreadFactory acceptFactory = new ThreadFactory("accept"); - final ThreadFactory serverFactory = new ThreadFactory("server"); + final ThreadFactory acceptFactory = new DefaultThreadFactory("accept"); + final ThreadFactory serverFactory = new DefaultThreadFactory("server"); final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory, NioUdtProvider.BYTE_PROVIDER); final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, @@ -258,7 +257,7 @@ public class UDTClientServerConnectionTest { } } } else { - if (group.size() == 0) { + if (group.isEmpty()) { return; } } @@ -330,30 +329,13 @@ public class UDTClientServerConnectionTest { msgs.releaseAllAndRecycle(); } } - - static class ThreadFactory implements java.util.concurrent.ThreadFactory { - - static final AtomicInteger counter = new AtomicInteger(); - - final String name; - - ThreadFactory(final String name) { - this.name = name; - } - - @Override - public Thread newThread(final Runnable runnable) { - return new Thread(runnable, name + '-' + counter.getAndIncrement()); - } - } - static final Logger log = LoggerFactory .getLogger(UDTClientServerConnectionTest.class); /** * Maximum wait time is 5 seconds. *

- * wait-time = {@link #WAIT_COUNT} * {@value #WAIT_SLEEP} + * wait-time = {@code WAIT_COUNT} * {@value #WAIT_SLEEP} */ static final int WAIT_COUNT = 50; static final int WAIT_SLEEP = 100; diff --git a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java index 036ef3cf4c..66bc90e801 100644 --- a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java +++ b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroup.java @@ -22,7 +22,6 @@ import io.netty.channel.ChannelFutureListener; import io.netty.channel.MessageList; import io.netty.channel.ServerChannel; import io.netty.util.concurrent.EventExecutor; -import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.internal.PlatformDependent; import java.util.AbstractSet; @@ -51,13 +50,6 @@ public class DefaultChannelGroup extends AbstractSet implements Channel } }; - /** - * Creates a new group with a generated name. - */ - public DefaultChannelGroup() { - this("group-0x" + Integer.toHexString(nextId.incrementAndGet())); - } - /** * Creates a new group with a generated name amd the provided {@link EventExecutor} to notify the * {@link ChannelGroupFuture}s. @@ -66,15 +58,6 @@ public class DefaultChannelGroup extends AbstractSet implements Channel this("group-0x" + Integer.toHexString(nextId.incrementAndGet()), executor); } - /** - * Creates a new group with the specified {@code name}. Please note that - * different groups can have the same name, which means no duplicate check - * is done against group names. - */ - public DefaultChannelGroup(String name) { - this(name, ImmediateEventExecutor.INSTANCE); - } - /** * Creates a new group with the specified {@code name} and {@link EventExecutor} to notify the * {@link ChannelGroupFuture}s. Please note that different groups can have the same name, which means no diff --git a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java index 1b3dbb2bb5..06bf3246b7 100644 --- a/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java +++ b/transport/src/main/java/io/netty/channel/group/DefaultChannelGroupFuture.java @@ -236,7 +236,7 @@ final class DefaultChannelGroupFuture extends DefaultPromise implements Ch @Override protected void checkDeadLock() { EventExecutor e = executor(); - if (e != null && !(e instanceof ImmediateEventExecutor) && e.inEventLoop()) { + if (e != null && e != ImmediateEventExecutor.INSTANCE && e.inEventLoop()) { throw new BlockingOperationException(); } } diff --git a/transport/src/test/java/io/netty/channel/group/DefaultChannnelGroupTest.java b/transport/src/test/java/io/netty/channel/group/DefaultChannnelGroupTest.java index 43af68aa77..13a60fbc3b 100644 --- a/transport/src/test/java/io/netty/channel/group/DefaultChannnelGroupTest.java +++ b/transport/src/test/java/io/netty/channel/group/DefaultChannnelGroupTest.java @@ -22,6 +22,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.util.concurrent.GlobalEventExecutor; import org.junit.Test; public class DefaultChannnelGroupTest { @@ -32,7 +33,7 @@ public class DefaultChannnelGroupTest { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); - final ChannelGroup allChannels = new DefaultChannelGroup(); + final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); diff --git a/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java b/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java index fc35c993bc..831556242a 100644 --- a/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java +++ b/transport/src/test/java/io/netty/channel/nio/NioDatagramChannelTest.java @@ -23,6 +23,7 @@ import io.netty.channel.MessageList; import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel; +import io.netty.util.concurrent.GlobalEventExecutor; import org.junit.Assert; import org.junit.Test; @@ -36,7 +37,7 @@ public class NioDatagramChannelTest { */ @Test public void testBindMultiple() { - DefaultChannelGroup channelGroup = new DefaultChannelGroup(); + DefaultChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); NioEventLoopGroup group = new NioEventLoopGroup(); try { for (int i = 0; i < 100; i++) {