public final class NtpPoller extends Object
TimeIntake.The "simple" configuration points the poller at a single server; the "advanced" configuration gives it a list. Either way the poller just submits whatever readings it gets each cycle – the cross-checking and outlier rejection across servers is the aggregator's job (it consumes the TimeIntake), not this class's.
The server list, poll interval, query timeout, the SNTP SntpTuning (destination port and accuracy heuristics) and the enabled flag are held in volatile fields and may be changed at any time from any thread; the running loop reads the current values at the start of each cycle. A configuration surface (the admin-facing clock config) drives start(), stop() and restart() and the setters below; this class itself reads no INI and knows nothing about licensing.
The loop is stopped cooperatively: a volatile running flag, an interruptible sleep, and on stop() the flag is cleared, the thread interrupted, and joined. The interrupt status is restored where it is caught. There is no Thread.stop().
This class makes use of Virtual Threads in Java 21+.
The poller logs only notable transitions – when no configured server is reachable, and when reachability recovers – through SntpLog (which writes to the server EventManager). Individual failed queries are not logged, to avoid flooding the event log.
Pure JDK except for SntpLog (server event logging); Java 8 through 25+, no third-party dependencies.
(C) Copyright 2026 Mindus SARL. All rights reserved.
| Modifier and Type | Field and Description |
|---|---|
static long | DEFAULT_POLL_INTERVAL_MSDefault poll interval, in milliseconds (15 minutes). |
static int | DEFAULT_QUERY_TIMEOUT_MSDefault per-query socket timeout, in milliseconds. |
| Constructor and Description |
|---|
NtpPoller(TimeIntake intake, String[] servers)Creates a poller feeding the given intake. |
| Modifier and Type | Method and Description |
|---|---|
boolean | isEnabled()Whether polling is currently enabled. |
boolean | isRunning()Whether the poller thread is currently running. |
void | restart()Stops and starts the poller, so a configuration change takes effect promptly. |
void | setEnabled(boolean enabled)Enables or disables polling. |
void | setPollIntervalMs(long pollIntervalMs)Sets the poll interval. |
void | setQueryTimeoutMs(int queryTimeoutMs)Sets the per-query socket timeout. |
void | setServers(String[] servers)Sets the list of NTP servers to poll. |
void | setSntpTuning(SntpTuning tuning)Sets the SNTP tuning (destination port and accuracy heuristics). |
void | start()Starts the poller thread if it is enabled and not already running. |
void | stop()Stops the poller thread cooperatively and waits briefly for it to end. |
public static final long DEFAULT_POLL_INTERVAL_MS
public static final int DEFAULT_QUERY_TIMEOUT_MS
public NtpPoller(TimeIntake intake, String[] servers)
intake - The sink to submit readings to (must not be null).servers - Initial server list (may be null or empty; copied defensively).public void setServers(String[] servers)
servers - The servers (may be null or empty; copied defensively).public void setPollIntervalMs(long pollIntervalMs)
pollIntervalMs - Interval in milliseconds (must be > 0).public void setQueryTimeoutMs(int queryTimeoutMs)
queryTimeoutMs - Timeout in milliseconds (must be > 0).public void setSntpTuning(SntpTuning tuning)
SntpClient.tuning - The tuning (must not be null).public void setEnabled(boolean enabled)
stop() for that. A disabled poller refuses to start().enabled - Whether polling is enabled.public boolean isEnabled()
public boolean isRunning()
public void start()
public void stop()
public void restart()
Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.