Remove EventExecutor.parent(), which is of no use
This commit is contained in:
parent
4440386494
commit
61e169e53a
@ -625,17 +625,18 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
}
|
||||
|
||||
inFlushNow = true;
|
||||
final ChannelBufferHolder<Object> out = directOutbound;
|
||||
try {
|
||||
Throwable cause = null;
|
||||
ChannelBufferHolder<Object> out = directOutbound();
|
||||
int oldSize = out.size();
|
||||
try {
|
||||
doFlush(out);
|
||||
} catch (Throwable t) {
|
||||
cause = t;
|
||||
} finally {
|
||||
writeCounter += oldSize - out.size();
|
||||
if (out.isEmpty() && out.hasByteBuffer()) {
|
||||
final int newSize = out.size();
|
||||
writeCounter += oldSize - newSize;
|
||||
if (newSize == 0 && out.hasByteBuffer()) {
|
||||
out.byteBuffer().discardReadBytes();
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import java.util.concurrent.ThreadFactory;
|
||||
|
||||
class DefaultChildEventExecutor extends SingleThreadEventExecutor {
|
||||
|
||||
DefaultChildEventExecutor(EventExecutor parent, ThreadFactory threadFactory) {
|
||||
super(parent, threadFactory);
|
||||
DefaultChildEventExecutor(ThreadFactory threadFactory) {
|
||||
super(threadFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,6 @@ public class DefaultEventExecutor extends MultithreadEventExecutor {
|
||||
|
||||
@Override
|
||||
protected EventExecutor newChild(ThreadFactory threadFactory, Object... args) throws Exception {
|
||||
return new DefaultChildEventExecutor(this, threadFactory);
|
||||
return new DefaultChildEventExecutor(threadFactory);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.netty.channel;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public interface EventExecutor extends ScheduledExecutorService {
|
||||
EventExecutor parent();
|
||||
boolean inEventLoop();
|
||||
Unsafe unsafe();
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package io.netty.channel;
|
||||
|
||||
public interface EventLoop extends EventExecutor {
|
||||
@Override
|
||||
EventLoop parent();
|
||||
ChannelFuture register(Channel channel);
|
||||
ChannelFuture register(Channel channel, ChannelFuture future);
|
||||
}
|
||||
|
@ -64,11 +64,6 @@ public abstract class MultithreadEventExecutor implements EventExecutor {
|
||||
|
||||
protected abstract EventExecutor newChild(ThreadFactory threadFactory, Object... args) throws Exception;
|
||||
|
||||
@Override
|
||||
public EventExecutor parent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unsafe unsafe() {
|
||||
return unsafe;
|
||||
|
@ -21,11 +21,6 @@ public abstract class MultithreadEventLoop extends MultithreadEventExecutor impl
|
||||
@Override
|
||||
protected abstract EventExecutor newChild(ThreadFactory threadFactory, Object... args) throws Exception;
|
||||
|
||||
@Override
|
||||
public EventLoop parent() {
|
||||
return (EventLoop) super.parent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelFuture register(Channel channel) {
|
||||
return ((EventLoop) unsafe().nextChild()).register(channel);
|
||||
|
@ -49,7 +49,6 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService
|
||||
return nanoTime() + delay;
|
||||
}
|
||||
|
||||
private final EventExecutor parent;
|
||||
private final Unsafe unsafe = new Unsafe() {
|
||||
@Override
|
||||
public EventExecutor nextChild() {
|
||||
@ -69,12 +68,11 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService
|
||||
private long lastCheckTimeNanos;
|
||||
private long lastPurgeTimeNanos;
|
||||
|
||||
protected SingleThreadEventExecutor(EventExecutor parent) {
|
||||
this(parent, Executors.defaultThreadFactory());
|
||||
protected SingleThreadEventExecutor() {
|
||||
this(Executors.defaultThreadFactory());
|
||||
}
|
||||
|
||||
protected SingleThreadEventExecutor(EventExecutor parent, ThreadFactory threadFactory) {
|
||||
this.parent = parent;
|
||||
protected SingleThreadEventExecutor(ThreadFactory threadFactory) {
|
||||
thread = threadFactory.newThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -98,11 +96,6 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventExecutor parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unsafe unsafe() {
|
||||
return unsafe;
|
||||
|
@ -4,17 +4,10 @@ import java.util.concurrent.ThreadFactory;
|
||||
|
||||
public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop {
|
||||
|
||||
protected SingleThreadEventLoop(EventLoop parent) {
|
||||
super(parent);
|
||||
}
|
||||
protected SingleThreadEventLoop() {}
|
||||
|
||||
protected SingleThreadEventLoop(EventLoop parent, ThreadFactory threadFactory) {
|
||||
super(parent, threadFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventLoop parent() {
|
||||
return (EventLoop) super.parent();
|
||||
protected SingleThreadEventLoop(ThreadFactory threadFactory) {
|
||||
super(threadFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,15 +15,14 @@
|
||||
*/
|
||||
package io.netty.channel.local;
|
||||
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.SingleThreadEventLoop;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
final class LocalChildEventLoop extends SingleThreadEventLoop {
|
||||
|
||||
LocalChildEventLoop(EventLoop parent, ThreadFactory threadFactory) {
|
||||
super(parent, threadFactory);
|
||||
LocalChildEventLoop(ThreadFactory threadFactory) {
|
||||
super(threadFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,6 @@ public class LocalEventLoop extends MultithreadEventLoop {
|
||||
|
||||
@Override
|
||||
protected EventExecutor newChild(ThreadFactory threadFactory, Object... args) throws Exception {
|
||||
return new LocalChildEventLoop(this, threadFactory);
|
||||
return new LocalChildEventLoop(threadFactory);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,8 @@ public abstract class AbstractNioChannel extends AbstractChannel {
|
||||
|
||||
@Override
|
||||
protected boolean isFlushPending() {
|
||||
return (selectionKey.interestOps() & SelectionKey.OP_WRITE) != 0;
|
||||
SelectionKey selectionKey = this.selectionKey;
|
||||
return selectionKey.isValid() && (selectionKey.interestOps() & SelectionKey.OP_WRITE) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,8 +60,8 @@ final class NioChildEventLoop extends SingleThreadEventLoop {
|
||||
private int cancelledKeys;
|
||||
private boolean cleanedCancelledKeys;
|
||||
|
||||
NioChildEventLoop(NioEventLoop parent, ThreadFactory threadFactory, SelectorProvider selectorProvider) {
|
||||
super(parent, threadFactory);
|
||||
NioChildEventLoop(ThreadFactory threadFactory, SelectorProvider selectorProvider) {
|
||||
super(threadFactory);
|
||||
if (selectorProvider == null) {
|
||||
throw new NullPointerException("selectorProvider");
|
||||
}
|
||||
@ -168,39 +168,47 @@ final class NioChildEventLoop extends SingleThreadEventLoop {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<SelectionKey> i;
|
||||
cleanedCancelledKeys = false;
|
||||
for (i = selectedKeys.iterator(); i.hasNext();) {
|
||||
final SelectionKey k = i.next();
|
||||
i.remove();
|
||||
final AbstractNioChannel ch = (AbstractNioChannel) k.attachment();
|
||||
final NioUnsafe unsafe = ch.unsafe();
|
||||
try {
|
||||
int readyOps = k.readyOps();
|
||||
if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) {
|
||||
unsafe.read();
|
||||
if (!ch.isOpen()) {
|
||||
// Connection already closed - no need to handle write.
|
||||
continue;
|
||||
boolean clearSelectedKeys = true;
|
||||
try {
|
||||
for (i = selectedKeys.iterator(); i.hasNext();) {
|
||||
final SelectionKey k = i.next();
|
||||
final AbstractNioChannel ch = (AbstractNioChannel) k.attachment();
|
||||
final NioUnsafe unsafe = ch.unsafe();
|
||||
try {
|
||||
int readyOps = k.readyOps();
|
||||
if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) {
|
||||
unsafe.read();
|
||||
if (!ch.isOpen()) {
|
||||
// Connection already closed - no need to handle write.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ((readyOps & SelectionKey.OP_WRITE) != 0) {
|
||||
unsafe.flushNow();
|
||||
}
|
||||
if ((readyOps & SelectionKey.OP_CONNECT) != 0) {
|
||||
unsafe.finishConnect();
|
||||
}
|
||||
} catch (CancelledKeyException ignored) {
|
||||
unsafe.close(unsafe.voidFuture());
|
||||
}
|
||||
|
||||
if (cleanedCancelledKeys) {
|
||||
// Create the iterator again to avoid ConcurrentModificationException
|
||||
if (selectedKeys.isEmpty()) {
|
||||
clearSelectedKeys = false;
|
||||
break;
|
||||
} else {
|
||||
i = selectedKeys.iterator();
|
||||
}
|
||||
}
|
||||
if ((readyOps & SelectionKey.OP_WRITE) != 0) {
|
||||
unsafe.flushNow();
|
||||
}
|
||||
if ((readyOps & SelectionKey.OP_CONNECT) != 0) {
|
||||
unsafe.finishConnect();
|
||||
}
|
||||
} catch (CancelledKeyException ignored) {
|
||||
unsafe.close(unsafe.voidFuture());
|
||||
}
|
||||
|
||||
if (cleanedCancelledKeys) {
|
||||
// Create the iterator again to avoid ConcurrentModificationException
|
||||
if (selectedKeys.isEmpty()) {
|
||||
break;
|
||||
} else {
|
||||
i = selectedKeys.iterator();
|
||||
}
|
||||
} finally {
|
||||
if (clearSelectedKeys) {
|
||||
selectedKeys.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,6 @@ public class NioEventLoop extends MultithreadEventLoop {
|
||||
} else {
|
||||
selectorProvider = (SelectorProvider) args[0];
|
||||
}
|
||||
return new NioChildEventLoop(this, threadFactory, selectorProvider);
|
||||
return new NioChildEventLoop(threadFactory, selectorProvider);
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,12 @@ import io.netty.channel.SingleThreadEventLoop;
|
||||
|
||||
class OioChildEventLoop extends SingleThreadEventLoop {
|
||||
|
||||
private final OioEventLoop parent;
|
||||
private AbstractOioChannel ch;
|
||||
|
||||
OioChildEventLoop(OioEventLoop parent) {
|
||||
super(parent, parent.threadFactory);
|
||||
super(parent.threadFactory);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,7 +71,6 @@ class OioChildEventLoop extends SingleThreadEventLoop {
|
||||
|
||||
private void deregister() {
|
||||
ch = null;
|
||||
OioEventLoop parent = (OioEventLoop) parent();
|
||||
parent.activeChildren.remove(this);
|
||||
parent.idleChildren.add(this);
|
||||
}
|
||||
|
@ -63,11 +63,6 @@ public class OioEventLoop implements EventLoop {
|
||||
tooManyChannels.setStackTrace(new StackTraceElement[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventLoop parent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Unsafe unsafe() {
|
||||
return unsafe;
|
||||
|
Loading…
Reference in New Issue
Block a user