Replace LocalEventLoopGroup with DefaultEventLoopGroup
Motivation: LocalEventLoopGroup and LocalEventLoop are not really special for LocalChannels. It can be used for other channel implementations as long as they don't require special handling. Modifications: - Add DefaultEventLoopGroup and DefaultEventLoop - Deprecate LocalEventLoopGroup and make it extend DefaultEventLoopGroup - Add DefaultEventLoop and remove LocalEventLoop - Fix inspector warnings Result: - Better class names.
This commit is contained in:
parent
924113ce8c
commit
1e3b7d8273
@ -20,10 +20,10 @@ import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.local.LocalAddress;
|
||||
import io.netty.channel.local.LocalChannel;
|
||||
import io.netty.channel.local.LocalEventLoopGroup;
|
||||
import io.netty.channel.local.LocalServerChannel;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.handler.logging.LogLevel;
|
||||
@ -44,7 +44,7 @@ public class LocalEcho {
|
||||
// Address to bind on / connect to.
|
||||
final LocalAddress addr = new LocalAddress(port);
|
||||
|
||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||
EventLoopGroup clientGroup = new NioEventLoopGroup(); // NIO event loops are also OK
|
||||
try {
|
||||
// Note that we can use any event loop to ensure certain local channels
|
||||
|
@ -13,15 +13,36 @@
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel.local;
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.channel.SingleThreadEventLoop;
|
||||
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
final class LocalEventLoop extends SingleThreadEventLoop {
|
||||
public class DefaultEventLoop extends SingleThreadEventLoop {
|
||||
|
||||
LocalEventLoop(LocalEventLoopGroup parent, Executor executor) {
|
||||
public DefaultEventLoop() {
|
||||
this((EventLoopGroup) null);
|
||||
}
|
||||
|
||||
public DefaultEventLoop(ThreadFactory threadFactory) {
|
||||
this(null, threadFactory);
|
||||
}
|
||||
|
||||
public DefaultEventLoop(Executor executor) {
|
||||
this(null, executor);
|
||||
}
|
||||
|
||||
public DefaultEventLoop(EventLoopGroup parent) {
|
||||
this(parent, new DefaultThreadFactory(DefaultEventLoop.class));
|
||||
}
|
||||
|
||||
public DefaultEventLoop(EventLoopGroup parent, ThreadFactory threadFactory) {
|
||||
super(parent, threadFactory, true);
|
||||
}
|
||||
|
||||
public DefaultEventLoop(EventLoopGroup parent, Executor executor) {
|
||||
super(parent, executor, true);
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2012 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/**
|
||||
* {@link MultithreadEventLoopGroup} which must be used for the local transport.
|
||||
*/
|
||||
public class DefaultEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
|
||||
/**
|
||||
* Create a new instance with the default number of threads.
|
||||
*/
|
||||
public DefaultEventLoopGroup() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param nThreads the number of threads to use
|
||||
*/
|
||||
public DefaultEventLoopGroup(int nThreads) {
|
||||
this(nThreads, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
*
|
||||
* @param nThreads the number of threads to use
|
||||
* @param threadFactory the {@link ThreadFactory} or {@code null} to use the default
|
||||
*/
|
||||
public DefaultEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
||||
super(nThreads, threadFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
|
||||
return new DefaultEventLoop(this, executor);
|
||||
}
|
||||
}
|
@ -15,23 +15,20 @@
|
||||
*/
|
||||
package io.netty.channel.local;
|
||||
|
||||
import io.netty.channel.MultithreadEventLoopGroup;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/**
|
||||
* {@link MultithreadEventLoopGroup} which must be used for the local transport.
|
||||
* @deprecated Use {@link DefaultEventLoopGroup} instead.
|
||||
*/
|
||||
public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
@Deprecated
|
||||
public class LocalEventLoopGroup extends DefaultEventLoopGroup {
|
||||
|
||||
/**
|
||||
* Create a new instance with the default number of threads.
|
||||
*/
|
||||
public LocalEventLoopGroup() {
|
||||
this(0);
|
||||
}
|
||||
public LocalEventLoopGroup() { }
|
||||
|
||||
/**
|
||||
* Create a new instance
|
||||
@ -39,7 +36,7 @@ public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
* @param nThreads the number of threads to use
|
||||
*/
|
||||
public LocalEventLoopGroup(int nThreads) {
|
||||
this(nThreads, null);
|
||||
super(nThreads);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,10 +48,4 @@ public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
public LocalEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
||||
super(nThreads, threadFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventExecutor newChild(
|
||||
Executor executor, Object... args) throws Exception {
|
||||
return new LocalEventLoop(this, executor);
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ package io.netty.bootstrap;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.local.LocalAddress;
|
||||
import io.netty.channel.local.LocalChannel;
|
||||
import io.netty.channel.local.LocalEventLoopGroup;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -33,8 +33,8 @@ public class BootstrapTest {
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testBindDeadLock() throws Exception {
|
||||
EventLoopGroup groupA = new LocalEventLoopGroup(1);
|
||||
EventLoopGroup groupB = new LocalEventLoopGroup(1);
|
||||
EventLoopGroup groupA = new DefaultEventLoopGroup(1);
|
||||
EventLoopGroup groupB = new DefaultEventLoopGroup(1);
|
||||
|
||||
try {
|
||||
ChannelInboundHandler dummyHandler = new DummyHandler();
|
||||
@ -81,8 +81,8 @@ public class BootstrapTest {
|
||||
|
||||
@Test(timeout = 10000)
|
||||
public void testConnectDeadLock() throws Exception {
|
||||
EventLoopGroup groupA = new LocalEventLoopGroup(1);
|
||||
EventLoopGroup groupB = new LocalEventLoopGroup(1);
|
||||
EventLoopGroup groupA = new DefaultEventLoopGroup(1);
|
||||
EventLoopGroup groupB = new DefaultEventLoopGroup(1);
|
||||
|
||||
try {
|
||||
ChannelInboundHandler dummyHandler = new DummyHandler();
|
||||
|
@ -16,25 +16,25 @@
|
||||
package io.netty.channel;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.local.LocalChannel;
|
||||
import io.netty.channel.local.LocalEventLoopGroup;
|
||||
import io.netty.channel.local.LocalServerChannel;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
class BaseChannelTest {
|
||||
|
||||
private final LoggingHandler loggingHandler;
|
||||
|
||||
BaseChannelTest() {
|
||||
this.loggingHandler = new LoggingHandler();
|
||||
loggingHandler = new LoggingHandler();
|
||||
}
|
||||
|
||||
ServerBootstrap getLocalServerBootstrap() {
|
||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||
ServerBootstrap sb = new ServerBootstrap();
|
||||
sb.group(serverGroup);
|
||||
sb.channel(LocalServerChannel.class);
|
||||
@ -48,12 +48,12 @@ class BaseChannelTest {
|
||||
}
|
||||
|
||||
Bootstrap getLocalClientBootstrap() {
|
||||
EventLoopGroup clientGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup clientGroup = new DefaultEventLoopGroup();
|
||||
Bootstrap cb = new Bootstrap();
|
||||
cb.channel(LocalChannel.class);
|
||||
cb.group(clientGroup);
|
||||
|
||||
cb.handler(this.loggingHandler);
|
||||
cb.handler(loggingHandler);
|
||||
|
||||
return cb;
|
||||
}
|
||||
@ -65,16 +65,16 @@ class BaseChannelTest {
|
||||
}
|
||||
|
||||
void assertLog(String expected) {
|
||||
String actual = this.loggingHandler.getLog();
|
||||
String actual = loggingHandler.getLog();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
void clearLog() {
|
||||
this.loggingHandler.clear();
|
||||
loggingHandler.clear();
|
||||
}
|
||||
|
||||
void setInterest(LoggingHandler.Event... events) {
|
||||
this.loggingHandler.setInterest(events);
|
||||
loggingHandler.setInterest(events);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.local.LocalAddress;
|
||||
import io.netty.channel.local.LocalChannel;
|
||||
import io.netty.channel.local.LocalEventLoopGroup;
|
||||
import io.netty.channel.local.LocalServerChannel;
|
||||
import io.netty.util.AbstractReferenceCounted;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
@ -43,7 +42,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class DefaultChannelPipelineTest {
|
||||
|
||||
private static final EventLoopGroup group = new LocalEventLoopGroup(1);
|
||||
private static final EventLoopGroup group = new DefaultEventLoopGroup(1);
|
||||
|
||||
private Channel self;
|
||||
private Channel peer;
|
||||
|
@ -22,6 +22,7 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
@ -43,8 +44,8 @@ public class LocalChannelTest {
|
||||
@Test
|
||||
public void testLocalAddressReuse() throws Exception {
|
||||
for (int i = 0; i < 2; i ++) {
|
||||
EventLoopGroup clientGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup clientGroup = new DefaultEventLoopGroup();
|
||||
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||
Bootstrap cb = new Bootstrap();
|
||||
ServerBootstrap sb = new ServerBootstrap();
|
||||
@ -97,8 +98,8 @@ public class LocalChannelTest {
|
||||
|
||||
@Test
|
||||
public void testWriteFailsFastOnClosedChannel() throws Exception {
|
||||
EventLoopGroup clientGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup serverGroup = new LocalEventLoopGroup();
|
||||
EventLoopGroup clientGroup = new DefaultEventLoopGroup();
|
||||
EventLoopGroup serverGroup = new DefaultEventLoopGroup();
|
||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||
Bootstrap cb = new Bootstrap();
|
||||
ServerBootstrap sb = new ServerBootstrap();
|
||||
@ -147,7 +148,7 @@ public class LocalChannelTest {
|
||||
@Test
|
||||
public void testServerCloseChannelSameEventLoop() throws Exception {
|
||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||
LocalEventLoopGroup group = new LocalEventLoopGroup(1);
|
||||
EventLoopGroup group = new DefaultEventLoopGroup(1);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
ServerBootstrap sb = new ServerBootstrap()
|
||||
.group(group)
|
||||
|
@ -24,6 +24,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||
@ -49,7 +50,7 @@ public class LocalTransportThreadModelTest {
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
// Configure a test server
|
||||
group = new LocalEventLoopGroup();
|
||||
group = new DefaultEventLoopGroup();
|
||||
ServerBootstrap sb = new ServerBootstrap();
|
||||
sb.group(group)
|
||||
.channel(LocalServerChannel.class)
|
||||
@ -84,7 +85,7 @@ public class LocalTransportThreadModelTest {
|
||||
|
||||
@Test(timeout = 5000)
|
||||
public void testStagedExecution() throws Throwable {
|
||||
EventLoopGroup l = new LocalEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
||||
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
||||
ThreadNameAuditor h1 = new ThreadNameAuditor();
|
||||
@ -227,7 +228,7 @@ public class LocalTransportThreadModelTest {
|
||||
@Test(timeout = 30000)
|
||||
@Ignore
|
||||
public void testConcurrentMessageBufferAccess() throws Throwable {
|
||||
EventLoopGroup l = new LocalEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
||||
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
||||
EventExecutorGroup e3 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e3"));
|
||||
|
@ -22,6 +22,7 @@ import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -40,14 +41,14 @@ public class LocalTransportThreadModelTest2 {
|
||||
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||
LocalHander serverHandler = new LocalHander("SERVER");
|
||||
serverBootstrap
|
||||
.group(new LocalEventLoopGroup(), new LocalEventLoopGroup())
|
||||
.group(new DefaultEventLoopGroup(), new DefaultEventLoopGroup())
|
||||
.channel(LocalServerChannel.class)
|
||||
.childHandler(serverHandler);
|
||||
|
||||
Bootstrap clientBootstrap = new Bootstrap();
|
||||
LocalHander clientHandler = new LocalHander("CLIENT");
|
||||
clientBootstrap
|
||||
.group(new LocalEventLoopGroup())
|
||||
.group(new DefaultEventLoopGroup())
|
||||
.channel(LocalChannel.class)
|
||||
.remoteAddress(new LocalAddress(LOCAL_CHANNEL)).handler(clientHandler);
|
||||
|
||||
@ -100,7 +101,7 @@ public class LocalTransportThreadModelTest2 {
|
||||
|
||||
public final AtomicInteger count = new AtomicInteger(0);
|
||||
|
||||
public LocalHander(String name) {
|
||||
LocalHander(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.DefaultEventLoopGroup;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||
@ -62,7 +63,7 @@ public class LocalTransportThreadModelTest3 {
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
// Configure a test server
|
||||
group = new LocalEventLoopGroup();
|
||||
group = new DefaultEventLoopGroup();
|
||||
ServerBootstrap sb = new ServerBootstrap();
|
||||
sb.group(group)
|
||||
.channel(LocalServerChannel.class)
|
||||
@ -116,7 +117,7 @@ public class LocalTransportThreadModelTest3 {
|
||||
}
|
||||
|
||||
private static void testConcurrentAddRemove(boolean inbound) throws Exception {
|
||||
EventLoopGroup l = new LocalEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||
EventLoopGroup l = new DefaultEventLoopGroup(4, new DefaultThreadFactory("l"));
|
||||
EventExecutorGroup e1 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e1"));
|
||||
EventExecutorGroup e2 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e2"));
|
||||
EventExecutorGroup e3 = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("e3"));
|
||||
@ -210,7 +211,7 @@ public class LocalTransportThreadModelTest3 {
|
||||
for (;;) {
|
||||
EventType event = events.poll();
|
||||
if (event == null) {
|
||||
Assert.assertTrue("Missing events:" + expectedEvents.toString(), expectedEvents.isEmpty());
|
||||
Assert.assertTrue("Missing events:" + expectedEvents, expectedEvents.isEmpty());
|
||||
break;
|
||||
}
|
||||
Assert.assertEquals(event, expectedEvents.poll());
|
||||
@ -258,7 +259,7 @@ public class LocalTransportThreadModelTest3 {
|
||||
private final Queue<EventType> events;
|
||||
private final boolean inbound;
|
||||
|
||||
public EventRecorder(Queue<EventType> events, boolean inbound) {
|
||||
EventRecorder(Queue<EventType> events, boolean inbound) {
|
||||
this.events = events;
|
||||
this.inbound = inbound;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user