[#1369] Move ImmediateEventExecutor to common and let it access via a static

* Also fix a bug there to return a correct implementation of ProgressivPRomi
  ImmediateEventExecutor
This commit is contained in:
Norman Maurer 2013-05-17 21:35:01 +02:00
parent a8830aee42
commit abb4e20d0b
4 changed files with 31 additions and 9 deletions

View File

@ -15,15 +15,17 @@
*/
package io.netty.util.concurrent;
import io.netty.util.concurrent.AbstractEventExecutor;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.concurrent.Promise;
import java.util.concurrent.TimeUnit;
final class ImmediateEventExecutor extends AbstractEventExecutor {
/**
* {@link AbstractEventExecutor} which execute tasks in the callers thread.
*/
public final class ImmediateEventExecutor extends AbstractEventExecutor {
public static final ImmediateEventExecutor INSTANCE = new ImmediateEventExecutor();
private ImmediateEventExecutor() {
// use static instance
}
@Override
public EventExecutorGroup parent() {
@ -80,6 +82,11 @@ final class ImmediateEventExecutor extends AbstractEventExecutor {
return new ImmediatePromise<V>(this);
}
@Override
public <V> ProgressivePromise<V> newProgressivePromise() {
return new ImmediateProgressivePromise<V>(this);
}
static class ImmediatePromise<V> extends DefaultPromise<V> {
ImmediatePromise(EventExecutor executor) {
super(executor);
@ -90,4 +97,15 @@ final class ImmediateEventExecutor extends AbstractEventExecutor {
// No check
}
}
static class ImmediateProgressivePromise<V> extends DefaultProgressivePromise<V> {
ImmediateProgressivePromise(EventExecutor executor) {
super(executor);
}
@Override
protected void checkDeadLock() {
// No check
}
}
}

View File

@ -29,6 +29,9 @@ public final class ImmediateExecutor implements Executor {
@Override
public void execute(Runnable command) {
if (command == null) {
throw new NullPointerException("command");
}
command.run();
}
}

View File

@ -22,6 +22,7 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.FileRegion;
import io.netty.channel.ServerChannel;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.internal.PlatformDependent;
import java.util.AbstractSet;
@ -39,7 +40,6 @@ import java.util.concurrent.atomic.AtomicInteger;
public class DefaultChannelGroup extends AbstractSet<Channel> implements ChannelGroup {
private static final AtomicInteger nextId = new AtomicInteger();
private static final ImmediateEventExecutor DEFAULT_EXECUTOR = new ImmediateEventExecutor();
private final String name;
private final EventExecutor executor;
private final ConcurrentMap<Integer, Channel> serverChannels = PlatformDependent.newConcurrentHashMap();
@ -72,7 +72,7 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
* is done against group names.
*/
public DefaultChannelGroup(String name) {
this(name, DEFAULT_EXECUTOR);
this(name, ImmediateEventExecutor.INSTANCE);
}
/**

View File

@ -23,6 +23,7 @@ import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor;
import java.util.ArrayList;
import java.util.Collection;