Class ScriptContext

java.lang.Object
com.inductiveautomation.ignition.common.script.ScriptContext

public class ScriptContext extends Object
The ScriptContext class is used to provide implicit values to scripts, based on the context of the call. For example, it allows us to provide the default database connection name to gateway side scripts, which can differ based on where the call is coming from.

Each subsystem that's actually executing the scripts (e.g. the timer script manager on the gateway) should push a new context onto the thread-local stack before executing the script, and then pop it off after. A stack is used to ensure that a script that itself calls another script in a different subsystem will get the correct context.

Note: Since 8.3.0, arbitrary properties cannot be set on ScriptContext. If you need to store additional context, you'll have to set up your own ThreadLocal.

  • Constructor Details

    • ScriptContext

      public ScriptContext()
  • Method Details

    • get

      public static Optional<ScriptContext.Context> get()
      Returns:
      the most local script context (the top element of the stack), or null if the stack is empty.
    • push

      public static ScriptContext.ContextCloseable push(@NotNull @NotNull ScriptContext.Context context)
      Pushes a new, fully constructed script context onto the thread-local stack. Use push(Consumer) to push a context with only specific properties overridden.
    • push

      public static ScriptContext.ContextCloseable push(@NotNull @NotNull Consumer<ScriptContext.ContextBuilder> context)
      Pushes a new script context onto the thread-local stack. The context is initially inherited from the current context, but can be modified via the consumer to override specific properties. Use push(Context) to push a fully constructed context.
    • pop

      public static Optional<ScriptContext.Context> pop()
      Pops the top script context off the thread-local stack. If the stack is empty, returns null.
    • getDefaultProject

      public static Optional<String> getDefaultProject()
      Returns:
      the default project for the current script context, if any.
    • getDefaultDatasource

      public static Optional<String> getDefaultDatasource()
      Returns:
      the default datasource name for the current script context, if any.
    • getDefaultTagProvider

      public static Optional<String> getDefaultTagProvider()
      Returns:
      the default tag provider for the current script context, if any.
    • getRelativeTagPathRoot

      public static Optional<TagPath> getRelativeTagPathRoot()
      Returns:
      the relative tag path root for the current script context, if any.
    • getLocale

      public static Optional<Locale> getLocale()
      Returns:
      the locale for the current script context.
    • getDescription

      public static Optional<String> getDescription()
      Returns:
      the description for the current script context, if any.
    • getTagReferenceLocation

      public static Optional<com.inductiveautomation.ignition.common.tags.config.model.TagReferenceLocation> getTagReferenceLocation()
      Returns:
      the tag reference location for the current script context, if any.
    • newBuilder

      public static ScriptContext.ContextBuilder newBuilder()
      Constructs a new ScriptContext.ContextBuilder, automatically inheriting from the current thread's context.
      See Also: