Prevent unsafe ChannelFutures from being passed to a pipeline

This commit is contained in:
Trustin Lee 2012-05-13 01:35:43 +09:00
parent 91c02c2823
commit 175acb7899
3 changed files with 15 additions and 7 deletions

View File

@ -322,4 +322,12 @@ public interface ChannelFuture {
* the specified time limit * the specified time limit
*/ */
boolean awaitUninterruptibly(long timeoutMillis); boolean awaitUninterruptibly(long timeoutMillis);
/**
* A {@link ChannelFuture} which is not allowed to be sent to {@link ChannelPipeline} due to
* implementation details.
*/
interface Unsafe extends ChannelFuture {
// Tag interface
}
} }

View File

@ -858,6 +858,12 @@ public class DefaultChannelPipeline implements ChannelPipeline {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"future.channel does not match: %s (expected: %s)", future.channel(), channel())); "future.channel does not match: %s (expected: %s)", future.channel(), channel()));
} }
if (future.isDone()) {
throw new IllegalArgumentException("future already done");
}
if (future instanceof ChannelFuture.Unsafe) {
throw new IllegalArgumentException("internal use only future not allowed");
}
} }
private DefaultChannelHandlerContext firstInboundContext() { private DefaultChannelHandlerContext firstInboundContext() {

View File

@ -1,14 +1,8 @@
package io.netty.channel; package io.netty.channel;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class VoidChannelFuture implements ChannelFuture { public class VoidChannelFuture implements ChannelFuture.Unsafe {
private static final InternalLogger logger =
InternalLoggerFactory.getInstance(VoidChannelFuture.class);
private final Channel channel; private final Channel channel;