HashedWheelBucket Class — netty Architecture
Architecture documentation for the HashedWheelBucket class in HashedWheelTimer.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD fe86e935_6fee_92f9_eeb5_11302b3b45a5["HashedWheelBucket"] 8be6e914_922c_a17c_9e45_cdcc72002795["HashedWheelTimer.java"] fe86e935_6fee_92f9_eeb5_11302b3b45a5 -->|defined in| 8be6e914_922c_a17c_9e45_cdcc72002795 78938a23_b7a7_64b9_dae3_04a0c9ec0b4b["addTimeout()"] fe86e935_6fee_92f9_eeb5_11302b3b45a5 -->|method| 78938a23_b7a7_64b9_dae3_04a0c9ec0b4b 3d9ffcbb_3ea5_25ee_4523_6b747b12dc26["expireTimeouts()"] fe86e935_6fee_92f9_eeb5_11302b3b45a5 -->|method| 3d9ffcbb_3ea5_25ee_4523_6b747b12dc26 6c51ec0f_8f2d_9485_8cda_182a3bd31508["HashedWheelTimeout()"] fe86e935_6fee_92f9_eeb5_11302b3b45a5 -->|method| 6c51ec0f_8f2d_9485_8cda_182a3bd31508 62a2ff61_68bd_e1a0_10db_cd640e0d9647["clearTimeouts()"] fe86e935_6fee_92f9_eeb5_11302b3b45a5 -->|method| 62a2ff61_68bd_e1a0_10db_cd640e0d9647
Relationship Graph
Source Code
common/src/main/java/io/netty/util/HashedWheelTimer.java lines 760–864
private static final class HashedWheelBucket {
// Used for the linked-list datastructure
private HashedWheelTimeout head;
private HashedWheelTimeout tail;
/**
* Add {@link HashedWheelTimeout} to this bucket.
*/
public void addTimeout(HashedWheelTimeout timeout) {
assert timeout.bucket == null;
timeout.bucket = this;
if (head == null) {
head = tail = timeout;
} else {
tail.next = timeout;
timeout.prev = tail;
tail = timeout;
}
}
/**
* Expire all {@link HashedWheelTimeout}s for the given {@code deadline}.
*/
public void expireTimeouts(long deadline) {
HashedWheelTimeout timeout = head;
// process all timeouts
while (timeout != null) {
HashedWheelTimeout next = timeout.next;
if (timeout.remainingRounds <= 0) {
if (timeout.deadline <= deadline) {
timeout.expire();
} else {
// The timeout was placed into a wrong slot. This should never happen.
throw new IllegalStateException(String.format(
"timeout.deadline (%d) > deadline (%d)", timeout.deadline, deadline));
}
} else if (!timeout.isCancelled()) {
timeout.remainingRounds --;
}
timeout = next;
}
}
public HashedWheelTimeout remove(HashedWheelTimeout timeout) {
HashedWheelTimeout prev = timeout.prev;
HashedWheelTimeout next = timeout.next;
// remove timeout that was either processed or cancelled by updating the linked-list
if (prev != null) {
prev.next = next;
}
if (next != null) {
next.prev = prev;
}
if (timeout == head) {
head = next;
}
if (timeout == tail) {
tail = prev;
}
// null out prev, next and bucket to allow for GC.
timeout.prev = null;
timeout.next = null;
timeout.bucket = null;
return next;
}
/**
* Clear this bucket and return all not expired / cancelled {@link Timeout}s.
*/
public void clearTimeouts(Set<Timeout> set) {
for (;;) {
HashedWheelTimeout timeout = pollTimeout();
if (timeout == null) {
return;
}
if (timeout.isExpired() || timeout.isCancelled()) {
continue;
}
Source
Frequently Asked Questions
What is the HashedWheelBucket class?
HashedWheelBucket is a class in the netty codebase, defined in common/src/main/java/io/netty/util/HashedWheelTimer.java.
Where is HashedWheelBucket defined?
HashedWheelBucket is defined in common/src/main/java/io/netty/util/HashedWheelTimer.java at line 760.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free