Replace Channel.Unsafe.setEventLoop() with register()

- Added AbstractChannel.doRegister()
This commit is contained in:
Trustin Lee 2012-05-01 23:18:29 +09:00
parent a83b9704fa
commit 1356a0b61e
2 changed files with 16 additions and 12 deletions

View File

@ -349,17 +349,6 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
private class DefaultUnsafe implements Unsafe {
@Override
public void setEventLoop(EventLoop eventLoop) {
if (eventLoop == null) {
throw new NullPointerException("eventLoop");
}
if (AbstractChannel.this.eventLoop != null) {
throw new IllegalStateException("attached to an event loop already");
}
AbstractChannel.this.eventLoop = eventLoop;
}
@Override
public java.nio.channels.Channel ch() {
return javaChannel();
@ -370,6 +359,20 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
return firstOut();
}
@Override
public void register(EventLoop eventLoop, ChannelFuture future) {
if (eventLoop == null) {
throw new NullPointerException("eventLoop");
}
if (AbstractChannel.this.eventLoop != null) {
throw new IllegalStateException("registered to an event loop already");
}
AbstractChannel.this.eventLoop = eventLoop;
assert eventLoop().inEventLoop();
doRegister(future);
}
@Override
public void bind(final SocketAddress localAddress, final ChannelFuture future) {
if (eventLoop().inEventLoop()) {
@ -465,6 +468,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
protected abstract java.nio.channels.Channel javaChannel();
protected abstract ChannelBufferHolder<Object> firstOut();
protected abstract void doRegister(ChannelFuture future);
protected abstract void doBind(SocketAddress localAddress, ChannelFuture future);
protected abstract void doConnect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future);
protected abstract void doDisconnect(ChannelFuture future);

View File

@ -181,10 +181,10 @@ public interface Channel extends AttributeMap, ChannelFutureFactory, Comparable<
Unsafe unsafe();
public interface Unsafe {
void setEventLoop(EventLoop eventLoop);
java.nio.channels.Channel ch();
ChannelBufferHolder<Object> out();
void register(EventLoop eventLoop, ChannelFuture future);
void bind(SocketAddress localAddress, ChannelFuture future);
void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future);
void disconnect(ChannelFuture future);