Cleaner impl of AbstractNioChannelSink and AbstractOioChannelSink. See

#140 and #187
This commit is contained in:
Norman Maurer 2012-02-25 17:11:14 +01:00
parent 68066c5e4b
commit cfe7b49594
4 changed files with 9 additions and 6 deletions

View File

@ -29,7 +29,7 @@ public abstract class AbstractNioChannelSink extends AbstractChannelSink {
if (ch instanceof AbstractNioChannel<?>) {
AbstractNioChannel<?> channel = (AbstractNioChannel<?>) ch;
// check if the current thread is a worker thread if so we can send the event now
if (channel.worker.thread != Thread.currentThread()) {
if (!AbstractNioWorker.isIoThread(channel)) {
channel.worker.executeInIoThread(new Runnable() {
@Override

View File

@ -504,7 +504,7 @@ abstract class AbstractNioWorker implements Worker {
}
static boolean isIoThread(AbstractNioChannel<?> channel) {
return channel.worker.thread == null || Thread.currentThread() == channel.worker.thread;
return Thread.currentThread() == channel.worker.thread;
}
private void setOpWrite(AbstractNioChannel<?> channel) {

View File

@ -30,7 +30,7 @@ public abstract class AbstractOioChannelSink extends AbstractChannelSink {
if (ch instanceof AbstractOioChannel) {
AbstractOioChannel channel = (AbstractOioChannel) ch;
Worker worker = channel.worker;
if (worker != null && channel.workerThread != Thread.currentThread()) {
if (worker != null && !AbstractOioWorker.isIoThead(channel)) {
channel.worker.executeInIoThread(new Runnable() {
@Override

View File

@ -81,11 +81,11 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
channel.workerThread = null;
// Clean up.
close(channel, succeededFuture(channel));
close(channel, succeededFuture(channel), true);
}
static boolean isIoThead(AbstractOioChannel channel) {
return channel.workerThread == null || Thread.currentThread() == channel.workerThread;
return Thread.currentThread() == channel.workerThread;
}
@Override
@ -164,9 +164,12 @@ abstract class AbstractOioWorker<C extends AbstractOioChannel> implements Worker
}
static void close(AbstractOioChannel channel, ChannelFuture future) {
close(channel, future, isIoThead(channel));
}
private static void close(AbstractOioChannel channel, ChannelFuture future, boolean iothread) {
boolean connected = channel.isConnected();
boolean bound = channel.isBound();
boolean iothread = isIoThead(channel);
try {
channel.closeSocket();