Move validatePromise(...) to ChannelHandlerInvokerUtil. Related to [#2398]
Motivation: Once a user implement a custom ChannelHandlerInvoker it is needed to validate the ChannelPromise. We should expose a utility method for this. Modifications: Move validatePromise(...) from DefaultChannelHandlerInvoker to ChannelHandlerInvokerUtil and make it public. Result: User is able to reuse code
This commit is contained in:
parent
cc320a4be6
commit
bb063a9fdd
@ -16,6 +16,8 @@
|
||||
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import static io.netty.channel.DefaultChannelPipeline.*;
|
||||
@ -156,6 +158,44 @@ public final class ChannelHandlerInvokerUtil {
|
||||
invokeFlushNow(ctx);
|
||||
}
|
||||
|
||||
public static boolean validatePromise(
|
||||
ChannelHandlerContext ctx, ChannelPromise promise, boolean allowVoidPromise) {
|
||||
if (ctx == null) {
|
||||
throw new NullPointerException("ctx");
|
||||
}
|
||||
|
||||
if (promise == null) {
|
||||
throw new NullPointerException("promise");
|
||||
}
|
||||
|
||||
if (promise.isDone()) {
|
||||
if (promise.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
throw new IllegalArgumentException("promise already done: " + promise);
|
||||
}
|
||||
|
||||
if (promise.channel() != ctx.channel()) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"promise.channel does not match: %s (expected: %s)", promise.channel(), ctx.channel()));
|
||||
}
|
||||
|
||||
if (promise.getClass() == DefaultChannelPromise.class) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!allowVoidPromise && promise instanceof VoidChannelPromise) {
|
||||
throw new IllegalArgumentException(
|
||||
StringUtil.simpleClassName(VoidChannelPromise.class) + " not allowed for this operation");
|
||||
}
|
||||
|
||||
if (promise instanceof AbstractChannel.CloseFuture) {
|
||||
throw new IllegalArgumentException(
|
||||
StringUtil.simpleClassName(AbstractChannel.CloseFuture.class) + " not allowed in a pipeline");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void notifyHandlerException(ChannelHandlerContext ctx, Throwable cause) {
|
||||
if (inExceptionCaught(cause)) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
|
@ -20,7 +20,6 @@ import io.netty.util.Recycler;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.internal.OneTimeTask;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
@ -335,44 +334,6 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean validatePromise(
|
||||
ChannelHandlerContext ctx, ChannelPromise promise, boolean allowVoidPromise) {
|
||||
if (ctx == null) {
|
||||
throw new NullPointerException("ctx");
|
||||
}
|
||||
|
||||
if (promise == null) {
|
||||
throw new NullPointerException("promise");
|
||||
}
|
||||
|
||||
if (promise.isDone()) {
|
||||
if (promise.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
throw new IllegalArgumentException("promise already done: " + promise);
|
||||
}
|
||||
|
||||
if (promise.channel() != ctx.channel()) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"promise.channel does not match: %s (expected: %s)", promise.channel(), ctx.channel()));
|
||||
}
|
||||
|
||||
if (promise.getClass() == DefaultChannelPromise.class) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!allowVoidPromise && promise instanceof VoidChannelPromise) {
|
||||
throw new IllegalArgumentException(
|
||||
StringUtil.simpleClassName(VoidChannelPromise.class) + " not allowed for this operation");
|
||||
}
|
||||
|
||||
if (promise instanceof AbstractChannel.CloseFuture) {
|
||||
throw new IllegalArgumentException(
|
||||
StringUtil.simpleClassName(AbstractChannel.CloseFuture.class) + " not allowed in a pipeline");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void safeExecuteInbound(Runnable task, Object msg) {
|
||||
boolean success = false;
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user