Class ExitWatchdog
java.lang.Object
com.iizix.server.ExitWatchdog
The halt watchdog of a server exit: armed when the server begins to dispose for an exit, it halts the JVM with the exit code when the dispose has not ended within its time, so that a restart or an update the administrator asked for happens even when a module, the worker or the logger hangs on the way out (order CC-SERVER-RESTART-UPDATE-V5; NetPhantom's
inactivityKillServer is the idea). A dispose that ends disarms it.The halt is Runtime.halt(int): no shutdown hook runs, which is the point - the hooks are what may be hanging. What the halt costs is said on the standard error first.
The time is 90000L ms, or the system property "iizi.exit.watchdog.ms" in milliseconds (a rig shortens it). The halt itself is a parameter, so that a test proves the timing without ending its own JVM.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default time: 90 seconds.static final StringThe system property that sets the time in milliseconds:-Diizi.exit.watchdog.ms=.Method Summary
Modifier and TypeMethodDescriptionstatic ExitWatchdogarm(int exitCode) Arms a watchdog that halts the JVM with an exit code aftergetMillis().static ExitWatchdogarm(int exitCode, long millis, IntConsumer halt) Arms a watchdog with its time and its halt.booleandisarm()Disarms the watchdog: nothing fires after this call returns true.intGets the exit code of the halt.static longGets the time of the watchdog: the system propertyPROPERTY, or the default.booleanhasFired()Checks if the watchdog fired.
Field Details
PROPERTY
The system property that sets the time in milliseconds:-Diizi.exit.watchdog.ms=.- See Also:
DEFAULT_MILLIS
public static final long DEFAULT_MILLISThe default time: 90 seconds. The server's own dispose waits up to 60 seconds for the worker and up to 60 seconds for the logger, so a normal shutdown is well inside it.- See Also:
Method Details
getMillis
public static long getMillis()Gets the time of the watchdog: the system propertyPROPERTY, or the default.- Returns:
- The time in milliseconds, always positive.
arm
Arms a watchdog that halts the JVM with an exit code aftergetMillis().- Parameters:
exitCode- The exit code of the halt.- Returns:
- The watchdog, to disarm when the dispose has ended.
arm
Arms a watchdog with its time and its halt.- Parameters:
exitCode- The exit code handed to the halt.millis- The time in milliseconds.halt- What fires: in the serverRuntime.getRuntime()::halt.- Returns:
- The watchdog, to disarm when the dispose has ended.
- Throws:
IllegalArgumentException- If the time is not positive.NullPointerException- If the halt is null.
disarm
public boolean disarm()Disarms the watchdog: nothing fires after this call returns true.- Returns:
- true when it was armed and is now disarmed, false when it had fired already or was disarmed before.
hasFired
public boolean hasFired()Checks if the watchdog fired.- Returns:
- true when the halt was called.
getExitCode
public int getExitCode()Gets the exit code of the halt.- Returns:
- The exit code.