Simplify the validation logic proposed in 25f96b1644

This commit is contained in:
Trustin Lee 2013-07-23 13:47:43 +09:00
parent 35802207e1
commit d4aa5b53d6
2 changed files with 8 additions and 25 deletions

View File

@ -812,7 +812,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
return new FailedChannelFuture(channel(), executor(), cause);
}
private void validatePromise(ChannelPromise promise, boolean allowUnsafe) {
private void validatePromise(ChannelPromise promise, boolean allowVoidPromise) {
if (promise == null) {
throw new NullPointerException("promise");
}
@ -821,32 +821,24 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
throw new IllegalArgumentException("promise already done: " + promise);
}
// check if the promise is of type DefaultChannelPromise and if so check if its validated already.
DefaultChannelPromise p = null;
if (promise instanceof DefaultChannelPromise) {
p = (DefaultChannelPromise) promise;
if (p.isValidated()) {
return;
}
}
if (promise.channel() != channel()) {
throw new IllegalArgumentException(String.format(
"promise.channel does not match: %s (expected: %s)", promise.channel(), channel()));
}
if (!allowUnsafe && promise instanceof VoidChannelPromise) {
if (promise.getClass() == DefaultChannelPromise.class) {
return;
}
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");
}
if (p != null) {
// mark as validated
p.validated();
}
}
private DefaultChannelHandlerContext findContextInbound() {

View File

@ -29,7 +29,6 @@ public class DefaultChannelPromise extends DefaultPromise<Void> implements Chann
private final Channel channel;
private long checkpoint;
private boolean validated;
/**
* Creates a new instance.
@ -158,12 +157,4 @@ public class DefaultChannelPromise extends DefaultPromise<Void> implements Chann
super.checkDeadLock();
}
}
final boolean isValidated() {
return validated;
}
final void validated() {
validated = true;
}
}