From 06bc52f59eb943a7097a6917933bfb77d4d998ac Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 3 Sep 2021 09:35:20 +0200 Subject: [PATCH] Remove UnaryPromiseNotifier and just use Future.cascadeTo(...) (#11650) --- .../codec/http2/DefaultHttp2Connection.java | 3 +- .../util/concurrent/UnaryPromiseNotifier.java | 52 ------------------- .../io/netty/handler/ssl/SSLEngineTest.java | 4 +- 3 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 common/src/main/java/io/netty/util/concurrent/UnaryPromiseNotifier.java diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java index 20a204e4d8..5f599a369c 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2Connection.java @@ -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; diff --git a/common/src/main/java/io/netty/util/concurrent/UnaryPromiseNotifier.java b/common/src/main/java/io/netty/util/concurrent/UnaryPromiseNotifier.java deleted file mode 100644 index 9b5e12d66f..0000000000 --- a/common/src/main/java/io/netty/util/concurrent/UnaryPromiseNotifier.java +++ /dev/null @@ -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 implements FutureListener { - private static final InternalLogger logger = InternalLoggerFactory.getInstance(UnaryPromiseNotifier.class); - private final Promise promise; - - public UnaryPromiseNotifier(Promise promise) { - this.promise = requireNonNull(promise, "promise"); - } - - @Override - public void operationComplete(Future future) throws Exception { - cascadeTo(future, promise); - } - - public static void cascadeTo(Future completedFuture, Promise 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()); - } - } - } -} diff --git a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java index f1163ac806..fbdc2f4314 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java @@ -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(clientWritePromise)); + ctx.write(ctx.alloc().buffer(1).writeByte(1)).cascadeTo(clientWritePromise); } }