Class AbstractScript
- All Implemented Interfaces:
Sleepable
- Direct Known Subclasses:
TaskScript,TreeScript
The runtime creates one script instance, calls onStart(ScriptContext)
once, and then repeatedly calls onLoop(ScriptContext) on the dedicated
script thread until a stop is requested or a callback throws. It always attempts
to call onStop(ScriptContext) during teardown.
Callbacks should return promptly. Long waits should be expressed as the delay
returned by onLoop, or as short bounded waits from the SDK utilities, so
an external stop can be observed quickly.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a script with no runtime state initialized yet. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanReports whether this script has requested a cooperative stop.abstract longonLoop(ScriptContext context) Executes one unit of script work.voidonStart(ScriptContext context) Performs one-time initialization before the first loop.voidonStop(ScriptContext context) Releases script-owned resources during teardown.final voidRequests a cooperative stop after the current callback returns.final booleanAlias forisStopRequested()for use in polling loops.final voidstop()Alias forrequestStop().Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.valhalla.sdk.api.util.Sleepable
sleep, sleep, sleepUntil, sleepUntil, sleepUntil, sleepWhile, sleepWhile, sleepWhile
-
Constructor Details
-
AbstractScript
protected AbstractScript()Creates a script with no runtime state initialized yet.The Valhalla runtime supplies the
ScriptContextthrough lifecycle callbacks after construction.
-
-
Method Details
-
onStart
Performs one-time initialization before the first loop.- Parameters:
context- immutable runtime services and launch settings for this script
-
onLoop
Executes one unit of script work.The returned delay is clamped by the runtime to the supported range of 20 to 60,000 milliseconds. Returning a negative value does not stop a plain
AbstractScript; callrequestStop()explicitly. Structured bases such asTaskScriptinterpret negative task delays for you.- Parameters:
context- immutable runtime services and launch settings for this script- Returns:
- requested delay, in milliseconds, before the next loop callback
-
onStop
Releases script-owned resources during teardown.The runtime attempts this callback after normal stops, external stops, and callback failures. Implementations should avoid throwing and should tolerate partially initialized state.
- Parameters:
context- immutable runtime services and launch settings for this script
-
requestStop
public final void requestStop()Requests a cooperative stop after the current callback returns. -
stop
public final void stop()Alias forrequestStop(). -
isStopRequested
public final boolean isStopRequested()Reports whether this script has requested a cooperative stop.- Returns:
trueoncerequestStop()orstop()is called
-
shouldStop
public final boolean shouldStop()Alias forisStopRequested()for use in polling loops.- Returns:
truewhen callback work should end promptly
-