Class ScriptContext
java.lang.Object
com.inductiveautomation.ignition.common.script.ScriptContext
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static final class
static final class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<ScriptContext.Context>
get()
static Optional<com.inductiveautomation.ignition.common.tags.config.model.TagReferenceLocation>
static ScriptContext.ContextBuilder
Constructs a newScriptContext.ContextBuilder
, automatically inheriting from the current thread's context.static Optional<ScriptContext.Context>
pop()
Pops the top script context off the thread-local stack.push
(@NotNull ScriptContext.Context context) Pushes a new, fully constructed script context onto the thread-local stack.push
(@NotNull Consumer<ScriptContext.ContextBuilder> context) Pushes a new script context onto the thread-local stack.
-
Constructor Details
-
ScriptContext
public ScriptContext()
-
-
Method Details
-
get
- Returns:
- the most local script context (the top element of the stack), or null if the stack is empty.
-
push
Pushes a new, fully constructed script context onto the thread-local stack. Usepush(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. Usepush(Context)
to push a fully constructed context. -
pop
Pops the top script context off the thread-local stack. If the stack is empty, returns null. -
getDefaultProject
- Returns:
- the default project for the current script context, if any.
-
getDefaultDatasource
- Returns:
- the default datasource name for the current script context, if any.
-
getDefaultTagProvider
- Returns:
- the default tag provider for the current script context, if any.
-
getRelativeTagPathRoot
- Returns:
- the relative tag path root for the current script context, if any.
-
getLocale
- Returns:
- the locale for the current script context.
-
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
Constructs a newScriptContext.ContextBuilder
, automatically inheriting from the current thread's context.- See Also:
-