Home / Class/ RejectedExecutionHandlers Class — netty Architecture

RejectedExecutionHandlers Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  616a3965_bf00_e0d4_d32d_47b588ade581["RejectedExecutionHandlers"]
  1291d915_0027_736c_f3c8_f71df38e2dd6["RejectedExecutionHandlers.java"]
  616a3965_bf00_e0d4_d32d_47b588ade581 -->|defined in| 1291d915_0027_736c_f3c8_f71df38e2dd6
  4c5e0a18_3146_3180_abbe_7a994fba1a22["RejectedExecutionHandlers()"]
  616a3965_bf00_e0d4_d32d_47b588ade581 -->|method| 4c5e0a18_3146_3180_abbe_7a994fba1a22
  626615c2_9224_f8e3_2e07_b7ed9d72c9e2["RejectedExecutionHandler()"]
  616a3965_bf00_e0d4_d32d_47b588ade581 -->|method| 626615c2_9224_f8e3_2e07_b7ed9d72c9e2

Relationship Graph

Source Code

common/src/main/java/io/netty/util/concurrent/RejectedExecutionHandlers.java lines 27–72

public final class RejectedExecutionHandlers {
    private static final RejectedExecutionHandler REJECT = new RejectedExecutionHandler() {
        @Override
        public void rejected(Runnable task, SingleThreadEventExecutor executor) {
            throw new RejectedExecutionException();
        }
    };

    private RejectedExecutionHandlers() { }

    /**
     * Returns a {@link RejectedExecutionHandler} that will always just throw a {@link RejectedExecutionException}.
     */
    public static RejectedExecutionHandler reject() {
        return REJECT;
    }

    /**
     * Tries to backoff when the task can not be added due restrictions for an configured amount of time. This
     * is only done if the task was added from outside of the event loop which means
     * {@link EventExecutor#inEventLoop()} returns {@code false}.
     */
    public static RejectedExecutionHandler backoff(final int retries, long backoffAmount, TimeUnit unit) {
        ObjectUtil.checkPositive(retries, "retries");
        final long backOffNanos = unit.toNanos(backoffAmount);
        return new RejectedExecutionHandler() {
            @Override
            public void rejected(Runnable task, SingleThreadEventExecutor executor) {
                if (!executor.inEventLoop()) {
                    for (int i = 0; i < retries; i++) {
                        // Try to wake up the executor so it will empty its task queue.
                        executor.wakeup(false);

                        LockSupport.parkNanos(backOffNanos);
                        if (executor.offerTask(task)) {
                            return;
                        }
                    }
                }
                // Either we tried to add the task from within the EventLoop or we was not able to add it even with
                // backoff.
                throw new RejectedExecutionException();
            }
        };
    }
}

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free