diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerInvokerUtil.java b/transport/src/main/java/io/netty/channel/ChannelHandlerInvokerUtil.java index 2b9df27eef..7cfb0bb2c4 100644 --- a/transport/src/main/java/io/netty/channel/ChannelHandlerInvokerUtil.java +++ b/transport/src/main/java/io/netty/channel/ChannelHandlerInvokerUtil.java @@ -16,6 +16,8 @@ package io.netty.channel; +import io.netty.util.internal.StringUtil; + import java.net.SocketAddress; import static io.netty.channel.DefaultChannelPipeline.*; @@ -174,6 +176,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()) { diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerInvoker.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerInvoker.java index 71fd7b9e7c..1e024d7e2e 100644 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerInvoker.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerInvoker.java @@ -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; @@ -397,44 +396,6 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker { invokeWrite(ctx, msg, true, promise); } - 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 {