Class TaskContext

java.lang.Object
edu.cnu.mdi.sim.task.TaskContext

public final class TaskContext extends Object
Services made available to a BackgroundTask while it executes.

The context is owned by its TaskHandle and is valid for the lifetime of that handle. Its methods may be called from the task's worker thread. Progress, message, and refresh notifications are routed through the underlying simulation engine and therefore reach listeners on Swing's EDT. High-frequency progress, message, and refresh notifications retain the engine's coalescing behavior.

  • Method Details

    • isCancellationRequested

      public boolean isCancellationRequested()
      Tests whether cancellation has been requested.
      Returns:
      true after the first call to TaskHandle.cancel()
    • throwIfCancellationRequested

      public void throwIfCancellationRequested()
      Aborts the current task cooperatively if cancellation was requested.

      The resulting exception is intercepted by MDI and reported as cancellation, not failure.

      Throws:
      TaskCancelledException - if cancellation was requested
    • reportProgress

      public void reportProgress(double fraction, String message)
      Publishes determinate progress. Values outside [0,1] are clamped by ProgressInfo.determinate(double, String).
      Parameters:
      fraction - completed fraction
      message - optional user-facing status text
    • reportIndeterminateProgress

      public void reportIndeterminateProgress(String message)
      Publishes indeterminate progress.
      Parameters:
      message - optional user-facing status text
    • postMessage

      public void postMessage(String message)
      Publishes transient user-facing status text.
      Parameters:
      message - non-null message
      Throws:
      NullPointerException - if message is null
    • requestRefresh

      public void requestRefresh()
      Requests a coalesced UI refresh from registered listeners.
    • getElapsedSeconds

      public double getElapsedSeconds()
      Returns elapsed wall-clock time since the worker engine started.
      Returns:
      elapsed seconds, or zero before startup bookkeeping completes