HashedWheelTimer Class — netty Architecture
Architecture documentation for the HashedWheelTimer class in HashedWheelTimer.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 0a75019c_ba28_3729_1e96_e0724c6ddc24["HashedWheelTimer"] 8be6e914_922c_a17c_9e45_cdcc72002795["HashedWheelTimer.java"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|defined in| 8be6e914_922c_a17c_9e45_cdcc72002795 fa8fd23b_8f91_6574_968e_772c307cdc19["HashedWheelTimer()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| fa8fd23b_8f91_6574_968e_772c307cdc19 2887997e_69bc_6d87_5c4a_0b332570fab4["finalize()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| 2887997e_69bc_6d87_5c4a_0b332570fab4 49014abb_5553_8fe8_42ba_8b8198dcc344["createWheel()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| 49014abb_5553_8fe8_42ba_8b8198dcc344 e9d21410_9c1d_0eec_d368_c04bdb308bdb["start()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| e9d21410_9c1d_0eec_d368_c04bdb308bdb bd4bf731_7996_ea82_2640_1afb233683ee["stop()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| bd4bf731_7996_ea82_2640_1afb233683ee 7215ccab_c52a_80a7_3797_88ce5715a703["Timeout()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| 7215ccab_c52a_80a7_3797_88ce5715a703 0d4f1260_34a4_58e3_6b82_3fb3bbb516c5["pendingTimeouts()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| 0d4f1260_34a4_58e3_6b82_3fb3bbb516c5 b05d0e90_3dd2_9840_f6fd_508e63a96f2f["reportTooManyInstances()"] 0a75019c_ba28_3729_1e96_e0724c6ddc24 -->|method| b05d0e90_3dd2_9840_f6fd_508e63a96f2f
Relationship Graph
Source Code
common/src/main/java/io/netty/util/HashedWheelTimer.java lines 85–865
public class HashedWheelTimer implements Timer {
static final InternalLogger logger =
InternalLoggerFactory.getInstance(HashedWheelTimer.class);
private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger();
private static final AtomicBoolean WARNED_TOO_MANY_INSTANCES = new AtomicBoolean();
private static final int INSTANCE_COUNT_LIMIT = 64;
private static final long MILLISECOND_NANOS = TimeUnit.MILLISECONDS.toNanos(1);
private static final ResourceLeakDetector<HashedWheelTimer> leakDetector = ResourceLeakDetectorFactory.instance()
.newResourceLeakDetector(HashedWheelTimer.class, 1);
private static final AtomicIntegerFieldUpdater<HashedWheelTimer> WORKER_STATE_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(HashedWheelTimer.class, "workerState");
private final ResourceLeakTracker<HashedWheelTimer> leak;
private final Worker worker = new Worker();
private final Thread workerThread;
public static final int WORKER_STATE_INIT = 0;
public static final int WORKER_STATE_STARTED = 1;
public static final int WORKER_STATE_SHUTDOWN = 2;
@SuppressWarnings({"unused", "FieldMayBeFinal"})
private volatile int workerState; // 0 - init, 1 - started, 2 - shut down
private final long tickDuration;
private final HashedWheelBucket[] wheel;
private final int mask;
private final CountDownLatch startTimeInitialized = new CountDownLatch(1);
private final Queue<HashedWheelTimeout> timeouts = PlatformDependent.newMpscQueue();
private final Queue<HashedWheelTimeout> cancelledTimeouts = PlatformDependent.newMpscQueue();
private final AtomicLong pendingTimeouts = new AtomicLong(0);
private final long maxPendingTimeouts;
private final Executor taskExecutor;
private volatile long startTime;
/**
* Creates a new timer with the default thread factory
* ({@link Executors#defaultThreadFactory()}), default tick duration, and
* default number of ticks per wheel.
*/
public HashedWheelTimer() {
this(Executors.defaultThreadFactory());
}
/**
* Creates a new timer with the default thread factory
* ({@link Executors#defaultThreadFactory()}) and default number of ticks
* per wheel.
*
* @param tickDuration the duration between tick
* @param unit the time unit of the {@code tickDuration}
* @throws NullPointerException if {@code unit} is {@code null}
* @throws IllegalArgumentException if {@code tickDuration} is <= 0
*/
public HashedWheelTimer(long tickDuration, TimeUnit unit) {
this(Executors.defaultThreadFactory(), tickDuration, unit);
}
/**
* Creates a new timer with the default thread factory
* ({@link Executors#defaultThreadFactory()}).
*
* @param tickDuration the duration between tick
* @param unit the time unit of the {@code tickDuration}
* @param ticksPerWheel the size of the wheel
* @throws NullPointerException if {@code unit} is {@code null}
* @throws IllegalArgumentException if either of {@code tickDuration} and {@code ticksPerWheel} is <= 0
*/
public HashedWheelTimer(long tickDuration, TimeUnit unit, int ticksPerWheel) {
this(Executors.defaultThreadFactory(), tickDuration, unit, ticksPerWheel);
}
/**
* Creates a new timer with the default tick duration and default number of
* ticks per wheel.
*
* @param threadFactory a {@link ThreadFactory} that creates a
* background {@link Thread} which is dedicated to
* {@link TimerTask} execution.
Source
Frequently Asked Questions
What is the HashedWheelTimer class?
HashedWheelTimer is a class in the netty codebase, defined in common/src/main/java/io/netty/util/HashedWheelTimer.java.
Where is HashedWheelTimer defined?
HashedWheelTimer is defined in common/src/main/java/io/netty/util/HashedWheelTimer.java at line 85.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free