Remove UnaryPromiseNotifier and just use Future.cascadeTo(...) (#11650)
This commit is contained in:
parent
3a1a3de4e9
commit
06bc52f59e
@ -21,7 +21,6 @@ import io.netty.util.collection.IntObjectHashMap;
|
||||
import io.netty.util.collection.IntObjectMap;
|
||||
import io.netty.util.collection.IntObjectMap.PrimitiveEntry;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
import io.netty.util.concurrent.UnaryPromiseNotifier;
|
||||
import io.netty.util.internal.EmptyArrays;
|
||||
import io.netty.util.internal.UnstableApi;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
@ -123,7 +122,7 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
if (closePromise == promise) {
|
||||
// Do nothing
|
||||
} else {
|
||||
closePromise.asFuture().addListener(new UnaryPromiseNotifier<>(promise));
|
||||
closePromise.asFuture().cascadeTo(promise);
|
||||
}
|
||||
} else {
|
||||
closePromise = promise;
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.util.concurrent;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
|
||||
public final class UnaryPromiseNotifier<T> implements FutureListener<T> {
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(UnaryPromiseNotifier.class);
|
||||
private final Promise<? super T> promise;
|
||||
|
||||
public UnaryPromiseNotifier(Promise<? super T> promise) {
|
||||
this.promise = requireNonNull(promise, "promise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void operationComplete(Future<? extends T> future) throws Exception {
|
||||
cascadeTo(future, promise);
|
||||
}
|
||||
|
||||
public static <X> void cascadeTo(Future<X> completedFuture, Promise<? super X> promise) {
|
||||
if (completedFuture.isSuccess()) {
|
||||
if (!promise.trySuccess(completedFuture.getNow())) {
|
||||
logger.warn("Failed to mark a promise as success because it is done already: {}", promise);
|
||||
}
|
||||
} else if (completedFuture.isCancelled()) {
|
||||
if (!promise.cancel()) {
|
||||
logger.warn("Failed to cancel a promise because it is done already: {}", promise);
|
||||
}
|
||||
} else {
|
||||
if (!promise.tryFailure(completedFuture.cause())) {
|
||||
logger.warn("Failed to mark a promise as failure because it's done already: {}", promise,
|
||||
completedFuture.cause());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -43,7 +43,6 @@ import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
import io.netty.util.concurrent.UnaryPromiseNotifier;
|
||||
import io.netty.util.internal.EmptyArrays;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.ResourcesUtil;
|
||||
@ -1056,8 +1055,7 @@ public abstract class SSLEngineTest {
|
||||
// through we just want to verify the local failure condition. This way we don't have to worry
|
||||
// about verifying the payload and releasing the content on the server side.
|
||||
if (failureExpected) {
|
||||
ctx.write(ctx.alloc().buffer(1).writeByte(1))
|
||||
.addListener(new UnaryPromiseNotifier<Void>(clientWritePromise));
|
||||
ctx.write(ctx.alloc().buffer(1).writeByte(1)).cascadeTo(clientWritePromise);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user