[#2797] Let EventExecutorGroup extend AutoCloseable

Motivation:

To make it more easy to shutdown an EventExecutorGroup / EventLoopGroup we should let both of them extend AutoCloseable.

Modifications:

Let EventExecutorGroup extend AutoCloseable and impement it.

Result:

Easier shutdown of EventExecutorGroup and EventLoopGroup
This commit is contained in:
Norman Maurer 2014-08-26 14:04:27 +02:00
parent 0381fa67a8
commit 0b5df22aec
4 changed files with 16 additions and 1 deletions

View File

@ -154,4 +154,9 @@ public abstract class AbstractEventExecutor extends AbstractExecutorService impl
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
throw new UnsupportedOperationException();
}
@Override
public void close() throws Exception {
shutdownGracefully().syncUninterruptibly();
}
}

View File

@ -114,4 +114,9 @@ public abstract class AbstractEventExecutorGroup implements EventExecutorGroup {
public void execute(Runnable command) {
next().execute(command);
}
@Override
public void close() throws Exception {
shutdownGracefully().syncUninterruptibly();
}
}

View File

@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
* to shut them down in a global fashion.
*
*/
public interface EventExecutorGroup extends ScheduledExecutorService {
public interface EventExecutorGroup extends ScheduledExecutorService, AutoCloseable {
/**
* Returns {@code true} if and only if all {@link EventExecutor}s managed by this {@link EventExecutorGroup}

View File

@ -326,6 +326,11 @@ abstract class PausableChannelEventExecutor implements PausableEventExecutor, Ch
unwrap().execute(command);
}
@Override
public void close() throws Exception {
unwrap().close();
}
private static final class ChannelCallableEventExecutor<V> implements CallableEventExecutorAdapter<V> {
final Channel channel;