[#1606] Reduce overhead during writes because of ChannelPromise validation
This commit is contained in:
parent
81612f8e9b
commit
25f96b1644
@ -812,17 +812,28 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
||||
return new FailedChannelFuture(channel(), executor(), cause);
|
||||
}
|
||||
|
||||
private void validatePromise(ChannelFuture promise, boolean allowUnsafe) {
|
||||
private void validatePromise(ChannelPromise promise, boolean allowUnsafe) {
|
||||
if (promise == null) {
|
||||
throw new NullPointerException("promise");
|
||||
}
|
||||
|
||||
if (promise.isDone()) {
|
||||
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 (promise.isDone()) {
|
||||
throw new IllegalArgumentException("promise already done: " + promise);
|
||||
}
|
||||
if (!allowUnsafe && promise instanceof VoidChannelPromise) {
|
||||
throw new IllegalArgumentException(
|
||||
StringUtil.simpleClassName(VoidChannelPromise.class) + " not allowed for this operation");
|
||||
@ -831,6 +842,11 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
||||
throw new IllegalArgumentException(
|
||||
StringUtil.simpleClassName(AbstractChannel.CloseFuture.class) + " not allowed in a pipeline");
|
||||
}
|
||||
|
||||
if (p != null) {
|
||||
// mark as validated
|
||||
p.validated();
|
||||
}
|
||||
}
|
||||
|
||||
private DefaultChannelHandlerContext findContextInbound() {
|
||||
|
@ -29,6 +29,7 @@ public class DefaultChannelPromise extends DefaultPromise<Void> implements Chann
|
||||
|
||||
private final Channel channel;
|
||||
private long checkpoint;
|
||||
private boolean validated;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
@ -157,4 +158,12 @@ public class DefaultChannelPromise extends DefaultPromise<Void> implements Chann
|
||||
super.checkDeadLock();
|
||||
}
|
||||
}
|
||||
|
||||
final boolean isValidated() {
|
||||
return validated;
|
||||
}
|
||||
|
||||
final void validated() {
|
||||
validated = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user