BaseScriptContext
com.jsmacrosce.jsmacros.core.language.BaseScriptContext
Holds a language runtime context and tracks threads and event containers associated with its execution.
Closing releases bound event locks, interrupts bound threads, and removes this context from its runner.
Type Parameters
T: language-specific runtime context type
Nested types
Constructors
new BaseScriptContext
Fields
eventListeners
Live listener-to-event-name map used by event registration; its listener keys are weakly held.
hasMethodWrapperBeenInvoked
hasMethodWrapperBeenInvoked: boolean#Whether a context-associated
MethodWrapper has been constructed; this starts false and is used by shouldKeepAlive.runner
startTime
Construction timestamp in milliseconds since the Unix epoch, not the language-execution start time.
syncObject
Weak reference to this context's synchronization object; clearing its private strong reference permits collection.
triggeringEvent
Methods
bindEvent
Associates an event container with a thread, replacing any existing association.
Parameters:
th: thread to associateevent: event container to associate
bindThread
clearSyncObject
clearSyncObject(): void#Drops the context's strong reference to its sync object.
closeContext
closeContext(boolean preventLog): void#Closes this context and sets whether the execution wrapper suppresses its cancellation log.
Parameters:
preventLog: whether to suppress the cancellation log
closeContext(): void#Closes this context, releases bound event locks, interrupts bound threads, and unregisters it from the runner.
getBoundEvents
Returns the mutable map of threads to their bound event containers.
Returns: the backing map
getBoundThreads
getContainedFolder
Returns the absolute containing folder for the script file, or the absolute configured macro folder if no file was supplied.
Returns: the absolute folder; throws NullPointerException if the script file has no parent
getContext
getContext(): T#Returns the language-specific runtime context.
Returns: runtime context, or
null if unsetgetFile
getMainThread
getSyncObject
getTriggeringEvent
isContextClosed
isContextClosed(): boolean#Returns whether the context is closed; also closes it if its weakly held sync object was cleared.
Returns:
true if closedisMultiThreaded
isMultiThreaded(): boolean#Returns whether this language context supports concurrent execution on multiple threads.
Returns:
true if concurrent execution on multiple threads is supportedreleaseBoundEventIfPresent
setContext
setContext(T context): void#Sets the language runtime context once; a second assignment is rejected.
Parameters:
context: runtime context to store
setMainThread
shouldKeepAlive
shouldKeepAlive(): boolean#Returns whether the method-wrapper flag is set or a service requires this context to remain alive.
Returns:
true if either condition holdsunbindThread
Removes a bound thread and releases its associated event lock, if present.
Parameters:
t: bound thread; throws ScriptAssertionError if it is not bound
wrapSleep
wrapSleep(BaseScriptContext.SleepRunnable sleep): void#Runs an operation that may block; the default implementation runs it directly.
Parameters:
sleep: operation to run