- Add EventExecutor and make EventLoop extend it - Add SingleThreadEventExecutor and MultithreadEventExecutor - Add EventExecutor's default implementation - Fixed an API design problem where there is no way to get non-bypass buffer of desired type
43 lines
1.1 KiB
Java
43 lines
1.1 KiB
Java
package io.netty.channel;
|
|
|
|
import java.util.concurrent.ThreadFactory;
|
|
|
|
public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop {
|
|
|
|
protected SingleThreadEventLoop(EventLoop parent) {
|
|
super(parent);
|
|
}
|
|
|
|
protected SingleThreadEventLoop(EventLoop parent, ThreadFactory threadFactory) {
|
|
super(parent, threadFactory);
|
|
}
|
|
|
|
@Override
|
|
public EventLoop parent() {
|
|
return (EventLoop) super.parent();
|
|
}
|
|
|
|
@Override
|
|
public ChannelFuture register(Channel channel) {
|
|
if (channel == null) {
|
|
throw new NullPointerException("channel");
|
|
}
|
|
return register(channel, channel.newFuture());
|
|
}
|
|
|
|
@Override
|
|
public ChannelFuture register(final Channel channel, final ChannelFuture future) {
|
|
if (inEventLoop()) {
|
|
channel.unsafe().register(this, future);
|
|
} else {
|
|
execute(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
channel.unsafe().register(SingleThreadEventLoop.this, future);
|
|
}
|
|
});
|
|
}
|
|
return future;
|
|
}
|
|
}
|