Allow to handle only downstream events via the ExecutionHandler. See

#173
This commit is contained in:
norman 2012-03-02 09:28:43 +01:00
parent 5291560283
commit 0c46db317a

View File

@ -110,25 +110,40 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre
private final Executor executor; private final Executor executor;
private final boolean handleDownstream; private final boolean handleDownstream;
private final boolean handleUpstream;
/**
* Creates a new instance with the specified {@link Executor} which only handles upstream events.
* Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure.
*/
public ExecutionHandler(Executor executor) {
this(executor, false, true);
}
/**
* Use {@link #ExecutionHandler(Executor, boolean, boolean)}
*
* {@link Deprecated}
*/
@Deprecated
public ExecutionHandler(Executor executor, boolean handleDownstream) {
this(executor, handleDownstream, true);
}
/** /**
* Creates a new instance with the specified {@link Executor}. * Creates a new instance with the specified {@link Executor}.
* Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure. * Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure.
*/ */
public ExecutionHandler(Executor executor) { public ExecutionHandler(Executor executor, boolean handleDownstream, boolean handleUpstream) {
this(executor, false);
}
/**
* Creates a new instance with the specified {@link Executor}.
* Specify an {@link OrderedMemoryAwareThreadPoolExecutor} if unsure.
*/
public ExecutionHandler(Executor executor, boolean handleDownstream) {
if (executor == null) { if (executor == null) {
throw new NullPointerException("executor"); throw new NullPointerException("executor");
} }
if (!handleDownstream && !handleUpstream) {
throw new IllegalArgumentException("You must handle at least handle one event type");
}
this.executor = executor; this.executor = executor;
this.handleDownstream = handleDownstream; this.handleDownstream = handleDownstream;
this.handleUpstream = handleUpstream;
} }
/** /**
@ -154,7 +169,11 @@ public class ExecutionHandler implements ChannelUpstreamHandler, ChannelDownstre
@Override @Override
public void handleUpstream( public void handleUpstream(
ChannelHandlerContext context, ChannelEvent e) throws Exception { ChannelHandlerContext context, ChannelEvent e) throws Exception {
executor.execute(new ChannelUpstreamEventRunnable(context, e)); if (handleUpstream) {
executor.execute(new ChannelUpstreamEventRunnable(context, e));
} else {
context.sendUpstream(e);
}
} }
@Override @Override