Remove the constructors that uses ImmediateEventExecutor from DefaultChannelGroup
.. which is incorrect in my opinion. + minor cleanup
This commit is contained in:
parent
1749210985
commit
fd0084ecfa
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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;
|
||||
|
@ -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<Channel> 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<Channel> 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
|
||||
|
@ -236,7 +236,7 @@ final class DefaultChannelGroupFuture extends DefaultPromise<Void> 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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user