Class AbstractScript

java.lang.Object
com.valhalla.sdk.AbstractScript
All Implemented Interfaces:
Sleepable
Direct Known Subclasses:
TaskScript, TreeScript

public abstract class AbstractScript extends Object implements Sleepable
Base lifecycle for every Valhalla script.

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 Details

    • AbstractScript

      protected AbstractScript()
      Creates a script with no runtime state initialized yet.

      The Valhalla runtime supplies the ScriptContext through lifecycle callbacks after construction.

  • Method Details

    • onStart

      public void onStart(ScriptContext context)
      Performs one-time initialization before the first loop.
      Parameters:
      context - immutable runtime services and launch settings for this script
    • onLoop

      public abstract long onLoop(ScriptContext context)
      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; call requestStop() explicitly. Structured bases such as TaskScript interpret 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

      public void onStop(ScriptContext context)
      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 for requestStop().
    • isStopRequested

      public final boolean isStopRequested()
      Reports whether this script has requested a cooperative stop.
      Returns:
      true once requestStop() or stop() is called
    • shouldStop

      public final boolean shouldStop()
      Alias for isStopRequested() for use in polling loops.
      Returns:
      true when callback work should end promptly