Home / Class/ DefaultPromise Class — netty Architecture

DefaultPromise Class — netty Architecture

Architecture documentation for the DefaultPromise class in DefaultPromise.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  a0080a71_f091_42e0_8a20_424f0bf9d34a["DefaultPromise"]
  553612e1_e4b2_c7bc_4236_cde2274ee7aa["DefaultPromise.java"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|defined in| 553612e1_e4b2_c7bc_4236_cde2274ee7aa
  b72a7370_cf21_ba8a_d9ce_14b4dea42a1a["DefaultPromise()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| b72a7370_cf21_ba8a_d9ce_14b4dea42a1a
  51bcb3b8_e5bf_fd8d_5ba3_672fa6ea712b["setSuccess()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| 51bcb3b8_e5bf_fd8d_5ba3_672fa6ea712b
  5a200db3_8bd9_91dc_829d_af8105e5c170["trySuccess()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| 5a200db3_8bd9_91dc_829d_af8105e5c170
  1348a6c9_87d2_63a0_ba97_90d0cfbc4bee["setFailure()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| 1348a6c9_87d2_63a0_ba97_90d0cfbc4bee
  ce560fc3_ef97_4c9f_0e5b_c3c3af66885a["tryFailure()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| ce560fc3_ef97_4c9f_0e5b_c3c3af66885a
  a75001a6_bcd4_1943_d692_b3f9089a48d5["setUncancellable()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| a75001a6_bcd4_1943_d692_b3f9089a48d5
  ed12a3a6_e939_f9c9_037c_15656447cc95["isSuccess()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| ed12a3a6_e939_f9c9_037c_15656447cc95
  ba0fd620_1e4a_dc27_295c_a613f7c537f5["isCancellable()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| ba0fd620_1e4a_dc27_295c_a613f7c537f5
  829905c5_c5d6_72e0_13b1_4251cbdf2e8e["Throwable()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| 829905c5_c5d6_72e0_13b1_4251cbdf2e8e
  9c9d5e6f_6ff4_2673_f553_713895ee985f["addListener()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| 9c9d5e6f_6ff4_2673_f553_713895ee985f
  e23e9563_7378_d834_4886_924c663bd962["addListeners()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| e23e9563_7378_d834_4886_924c663bd962
  af548b4b_71d8_f294_9de6_e59b86eb09b7["removeListener()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| af548b4b_71d8_f294_9de6_e59b86eb09b7
  471ba2c6_b5b3_c6ba_e96b_4a13040fc2bc["removeListeners()"]
  a0080a71_f091_42e0_8a20_424f0bf9d34a -->|method| 471ba2c6_b5b3_c6ba_e96b_4a13040fc2bc

Relationship Graph

Source Code

common/src/main/java/io/netty/util/concurrent/DefaultPromise.java lines 37–902

public class DefaultPromise<V> extends AbstractFuture<V> implements Promise<V> {
    /**
     * System property with integer type value, that determine the max reentrancy/recursion level for when
     * listener notifications prompt other listeners to be notified.
     * <p>
     * When the reentrancy/recursion level becomes greater than this number, a new task will instead be scheduled
     * on the event loop, to finish notifying any subsequent listners.
     * <p>
     * The default value is {@code 8}.
     */
    public static final String PROPERTY_MAX_LISTENER_STACK_DEPTH = "io.netty.defaultPromise.maxListenerStackDepth";

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultPromise.class);
    private static final InternalLogger rejectedExecutionLogger =
            InternalLoggerFactory.getInstance(DefaultPromise.class.getName() + ".rejectedExecution");
    private static final int MAX_LISTENER_STACK_DEPTH = Math.min(8,
            SystemPropertyUtil.getInt(PROPERTY_MAX_LISTENER_STACK_DEPTH, 8));
    @SuppressWarnings("rawtypes")
    private static final AtomicReferenceFieldUpdater<DefaultPromise, Object> RESULT_UPDATER =
            AtomicReferenceFieldUpdater.newUpdater(DefaultPromise.class, Object.class, "result");
    private static final Object SUCCESS = new Object();
    private static final Object UNCANCELLABLE = new Object();
    private static final CauseHolder CANCELLATION_CAUSE_HOLDER = new CauseHolder(
            StacklessCancellationException.newInstance(DefaultPromise.class, "cancel(...)"));
    private static final StackTraceElement[] CANCELLATION_STACK = CANCELLATION_CAUSE_HOLDER.cause.getStackTrace();

    private volatile Object result;
    private final EventExecutor executor;

    /**
     * One or more listeners. Can be a {@link GenericFutureListener} or a {@link DefaultFutureListeners}.
     * If {@code null}, it means either 1) no listeners were added yet or 2) all listeners were notified.
     * <p>
     * Threading - synchronized(this). We must support adding listeners when there is no EventExecutor.
     */
    private GenericFutureListener<? extends Future<?>> listener;
    private DefaultFutureListeners listeners;
    /**
     * Threading - synchronized(this). We are required to hold the monitor to use Java's underlying wait()/notifyAll().
     */
    private short waiters;

    /**
     * Threading - synchronized(this). We must prevent concurrent notification and FIFO listener notification if the
     * executor changes.
     */
    private boolean notifyingListeners;

    /**
     * Creates a new instance.
     * <p>
     * It is preferable to use {@link EventExecutor#newPromise()} to create a new promise
     *
     * @param executor
     *        the {@link EventExecutor} which is used to notify the promise once it is complete.
     *        It is assumed this executor will protect against {@link StackOverflowError} exceptions.
     *        The executor may be used to avoid {@link StackOverflowError} by executing a {@link Runnable} if the stack
     *        depth exceeds a threshold.
     *
     */
    public DefaultPromise(EventExecutor executor) {
        this.executor = checkNotNull(executor, "executor");
    }

    /**
     * See {@link #executor()} for expectations of the executor.
     */
    protected DefaultPromise() {
        // only for subclasses
        executor = null;
    }

    @Override
    public Promise<V> setSuccess(V result) {
        if (setSuccess0(result)) {
            return this;
        }
        throw new IllegalStateException("complete already: " + this);
    }

    @Override

Frequently Asked Questions

What is the DefaultPromise class?
DefaultPromise is a class in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/DefaultPromise.java.
Where is DefaultPromise defined?
DefaultPromise is defined in common/src/main/java/io/netty/util/concurrent/DefaultPromise.java at line 37.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free