PromiseNotifier Class — netty Architecture
Architecture documentation for the PromiseNotifier class in PromiseNotifier.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD aeb78e16_b6f4_3ab4_4d65_5983ace8ae6f["PromiseNotifier"] a3e2fc68_6475_7b3f_bd19_e75f710bf338["PromiseNotifier.java"] aeb78e16_b6f4_3ab4_4d65_5983ace8ae6f -->|defined in| a3e2fc68_6475_7b3f_bd19_e75f710bf338 fe3f5942_f8d2_dfbf_a1a4_422ba2682fde["PromiseNotifier()"] aeb78e16_b6f4_3ab4_4d65_5983ace8ae6f -->|method| fe3f5942_f8d2_dfbf_a1a4_422ba2682fde 3885fe7c_1e11_c9a0_a965_102028a2c3e9["F()"] aeb78e16_b6f4_3ab4_4d65_5983ace8ae6f -->|method| 3885fe7c_1e11_c9a0_a965_102028a2c3e9 5afb16f7_3800_4d37_6240_586aedb10447["operationComplete()"] aeb78e16_b6f4_3ab4_4d65_5983ace8ae6f -->|method| 5afb16f7_3800_4d37_6240_586aedb10447
Relationship Graph
Source Code
common/src/main/java/io/netty/util/concurrent/PromiseNotifier.java lines 32–131
public class PromiseNotifier<V, F extends Future<V>> implements GenericFutureListener<F> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(PromiseNotifier.class);
private final Promise<? super V>[] promises;
private final boolean logNotifyFailure;
/**
* Create a new instance.
*
* @param promises the {@link Promise}s to notify once this {@link GenericFutureListener} is notified.
*/
@SafeVarargs
public PromiseNotifier(Promise<? super V>... promises) {
this(true, promises);
}
/**
* Create a new instance.
*
* @param logNotifyFailure {@code true} if logging should be done in case notification fails.
* @param promises the {@link Promise}s to notify once this {@link GenericFutureListener} is notified.
*/
@SafeVarargs
public PromiseNotifier(boolean logNotifyFailure, Promise<? super V>... promises) {
checkNotNull(promises, "promises");
for (Promise<? super V> promise: promises) {
checkNotNullWithIAE(promise, "promise");
}
this.promises = promises.clone();
this.logNotifyFailure = logNotifyFailure;
}
/**
* Link the {@link Future} and {@link Promise} such that if the {@link Future} completes the {@link Promise}
* will be notified. Cancellation is propagated both ways such that if the {@link Future} is cancelled
* the {@link Promise} is cancelled and vise-versa.
*
* @param future the {@link Future} which will be used to listen to for notifying the {@link Promise}.
* @param promise the {@link Promise} which will be notified
* @param <V> the type of the value.
* @param <F> the type of the {@link Future}
* @return the passed in {@link Future}
*/
public static <V, F extends Future<V>> F cascade(final F future, final Promise<? super V> promise) {
return cascade(true, future, promise);
}
/**
* Link the {@link Future} and {@link Promise} such that if the {@link Future} completes the {@link Promise}
* will be notified. Cancellation is propagated both ways such that if the {@link Future} is cancelled
* the {@link Promise} is cancelled and vise-versa.
*
* @param logNotifyFailure {@code true} if logging should be done in case notification fails.
* @param future the {@link Future} which will be used to listen to for notifying the {@link Promise}.
* @param promise the {@link Promise} which will be notified
* @param <V> the type of the value.
* @param <F> the type of the {@link Future}
* @return the passed in {@link Future}
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public static <V, F extends Future<V>> F cascade(boolean logNotifyFailure, final F future,
final Promise<? super V> promise) {
promise.addListener((FutureListener) f -> {
if (f.isCancelled()) {
future.cancel(false);
}
});
future.addListener(new PromiseNotifier(logNotifyFailure, promise) {
@Override
public void operationComplete(Future f) throws Exception {
if (promise.isCancelled() && f.isCancelled()) {
// Just return if we propagate a cancel from the promise to the future and both are notified already
return;
}
super.operationComplete(future);
}
});
return future;
}
@Override
Source
Frequently Asked Questions
What is the PromiseNotifier class?
PromiseNotifier is a class in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/PromiseNotifier.java.
Where is PromiseNotifier defined?
PromiseNotifier is defined in common/src/main/java/io/netty/util/concurrent/PromiseNotifier.java at line 32.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free