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 final class ImmediateEventExecutor extends AbstractEventExecutor {
|
||||||
public static final ImmediateEventExecutor INSTANCE = new ImmediateEventExecutor();
|
public static final ImmediateEventExecutor INSTANCE = new ImmediateEventExecutor();
|
||||||
|
|
||||||
private ImmediateEventExecutor() {
|
private ImmediateEventExecutor() {
|
||||||
// use static instance
|
// use static instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import io.netty.channel.group.DefaultChannelGroup;
|
|||||||
import io.netty.handler.ssl.SslHandler;
|
import io.netty.handler.ssl.SslHandler;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.GenericFutureListener;
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -37,7 +38,7 @@ public class SecureChatServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
private static final Logger logger = Logger.getLogger(
|
private static final Logger logger = Logger.getLogger(
|
||||||
SecureChatServerHandler.class.getName());
|
SecureChatServerHandler.class.getName());
|
||||||
|
|
||||||
static final ChannelGroup channels = new DefaultChannelGroup();
|
static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
|
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.StringDecoder;
|
||||||
import io.netty.handler.codec.string.StringEncoder;
|
import io.netty.handler.codec.string.StringEncoder;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||||
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ public class UDTClientServerConnectionTest {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final Bootstrap boot = new Bootstrap();
|
final Bootstrap boot = new Bootstrap();
|
||||||
final ThreadFactory clientFactory = new ThreadFactory("client");
|
final ThreadFactory clientFactory = new DefaultThreadFactory("client");
|
||||||
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
|
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
|
||||||
clientFactory, NioUdtProvider.BYTE_PROVIDER);
|
clientFactory, NioUdtProvider.BYTE_PROVIDER);
|
||||||
try {
|
try {
|
||||||
@ -143,9 +145,6 @@ public class UDTClientServerConnectionTest {
|
|||||||
|
|
||||||
volatile boolean isActive;
|
volatile boolean isActive;
|
||||||
|
|
||||||
ClientHandler() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(final ChannelHandlerContext ctx)
|
public void channelActive(final ChannelHandlerContext ctx)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@ -182,7 +181,7 @@ public class UDTClientServerConnectionTest {
|
|||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(Server.class);
|
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 String host;
|
||||||
final int port;
|
final int port;
|
||||||
@ -199,8 +198,8 @@ public class UDTClientServerConnectionTest {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final ServerBootstrap boot = new ServerBootstrap();
|
final ServerBootstrap boot = new ServerBootstrap();
|
||||||
final ThreadFactory acceptFactory = new ThreadFactory("accept");
|
final ThreadFactory acceptFactory = new DefaultThreadFactory("accept");
|
||||||
final ThreadFactory serverFactory = new ThreadFactory("server");
|
final ThreadFactory serverFactory = new DefaultThreadFactory("server");
|
||||||
final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
|
final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
|
||||||
acceptFactory, NioUdtProvider.BYTE_PROVIDER);
|
acceptFactory, NioUdtProvider.BYTE_PROVIDER);
|
||||||
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
|
final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
|
||||||
@ -258,7 +257,7 @@ public class UDTClientServerConnectionTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (group.size() == 0) {
|
if (group.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,30 +329,13 @@ public class UDTClientServerConnectionTest {
|
|||||||
msgs.releaseAllAndRecycle();
|
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
|
static final Logger log = LoggerFactory
|
||||||
.getLogger(UDTClientServerConnectionTest.class);
|
.getLogger(UDTClientServerConnectionTest.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum wait time is 5 seconds.
|
* Maximum wait time is 5 seconds.
|
||||||
* <p>
|
* <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_COUNT = 50;
|
||||||
static final int WAIT_SLEEP = 100;
|
static final int WAIT_SLEEP = 100;
|
||||||
|
@ -22,7 +22,6 @@ import io.netty.channel.ChannelFutureListener;
|
|||||||
import io.netty.channel.MessageList;
|
import io.netty.channel.MessageList;
|
||||||
import io.netty.channel.ServerChannel;
|
import io.netty.channel.ServerChannel;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
|
||||||
import io.netty.util.internal.PlatformDependent;
|
import io.netty.util.internal.PlatformDependent;
|
||||||
|
|
||||||
import java.util.AbstractSet;
|
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
|
* Creates a new group with a generated name amd the provided {@link EventExecutor} to notify the
|
||||||
* {@link ChannelGroupFuture}s.
|
* {@link ChannelGroupFuture}s.
|
||||||
@ -66,15 +58,6 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
|
|||||||
this("group-0x" + Integer.toHexString(nextId.incrementAndGet()), executor);
|
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
|
* 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
|
* {@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
|
@Override
|
||||||
protected void checkDeadLock() {
|
protected void checkDeadLock() {
|
||||||
EventExecutor e = executor();
|
EventExecutor e = executor();
|
||||||
if (e != null && !(e instanceof ImmediateEventExecutor) && e.inEventLoop()) {
|
if (e != null && e != ImmediateEventExecutor.INSTANCE && e.inEventLoop()) {
|
||||||
throw new BlockingOperationException();
|
throw new BlockingOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
|
|||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class DefaultChannnelGroupTest {
|
public class DefaultChannnelGroupTest {
|
||||||
@ -32,7 +33,7 @@ public class DefaultChannnelGroupTest {
|
|||||||
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
|
|
||||||
final ChannelGroup allChannels = new DefaultChannelGroup();
|
final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||||
|
|
||||||
ServerBootstrap b = new ServerBootstrap();
|
ServerBootstrap b = new ServerBootstrap();
|
||||||
b.group(bossGroup, workerGroup);
|
b.group(bossGroup, workerGroup);
|
||||||
|
@ -23,6 +23,7 @@ import io.netty.channel.MessageList;
|
|||||||
import io.netty.channel.group.DefaultChannelGroup;
|
import io.netty.channel.group.DefaultChannelGroup;
|
||||||
import io.netty.channel.socket.DatagramChannel;
|
import io.netty.channel.socket.DatagramChannel;
|
||||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||||
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ public class NioDatagramChannelTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBindMultiple() {
|
public void testBindMultiple() {
|
||||||
DefaultChannelGroup channelGroup = new DefaultChannelGroup();
|
DefaultChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||||
NioEventLoopGroup group = new NioEventLoopGroup();
|
NioEventLoopGroup group = new NioEventLoopGroup();
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user