Implementation:Apache Kafka CoordinatorTimerImpl Schedule
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Systems, Scheduling |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for scheduling and cancelling timed operations provided by CoordinatorTimerImpl.
Description
The CoordinatorTimerImpl manages a map of TimerTask objects keyed by unique string identifiers. The schedule method creates a TimerTask that, when it expires, schedules a write operation through the runtime's scheduler. The cancel method removes and cancels a previously scheduled timer. Overriding a timer by scheduling with the same key automatically cancels the previous one.
Usage
Used internally by coordinator shards to schedule session timeouts, heartbeat deadlines, and delayed operations.
Code Reference
Source Location
- Repository: Apache Kafka
- File: coordinator-common/src/main/java/org/apache/kafka/coordinator/common/runtime/CoordinatorTimerImpl.java
- Lines: L58-89 (schedule), L152-155 (cancel)
Signature
public void schedule(
String key,
long delay,
TimeUnit unit,
boolean retry,
TimeoutOperation<U> operation
)
public void cancel(String key)
Import
import org.apache.kafka.coordinator.common.runtime.CoordinatorTimerImpl;
import java.util.concurrent.TimeUnit;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | String | Yes | Unique timer identifier |
| delay | long | Yes | Delay before execution |
| unit | TimeUnit | Yes | Time unit for the delay |
| retry | boolean | Yes | Retry on failure |
| operation | TimeoutOperation | Yes | Operation to execute on timeout |
Outputs
| Name | Type | Description |
|---|---|---|
| schedule | void | Timer registered; fires write operation on expiration |
| cancel | void | Timer cancelled if it exists |
Usage Examples
// Schedule a session timeout
timer.schedule(
"session-timeout-" + memberId,
30000, TimeUnit.MILLISECONDS,
true, // retry on failure
() -> coordinator.expireSession(memberId)
);
// Cancel when member heartbeats
timer.cancel("session-timeout-" + memberId);
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment