Skip to content

BaseScriptContext ​

com.jsmacrosce.jsmacros.core.language.BaseScriptContext

Since1.4.0

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 ​

new BaseScriptContext(Core<?, ?> runner, BaseEvent event, File file)#
Initializes a context with its runner and optional triggering event and script file.

Parameters:

  • runner: owning runner
  • event: triggering event, if any
  • file: script file, if any

Fields ​

eventListeners ​

eventListeners: WeakHashMap<IEventListener, String>read-only#
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 ​

runner: Core<?, ?>read-only#
The Core that owns this context; the reference is fixed, but the runner itself is not immutable.

startTime ​

startTime: longread-only#
Construction timestamp in milliseconds since the Unix epoch, not the language-execution start time.

syncObject ​

syncObject: WeakReference<Object>read-only#
Weak reference to this context's synchronization object; clearing its private strong reference permits collection.

triggeringEvent ​

triggeringEvent: BaseEventread-only#
Event supplied when this context was triggered, or null when none was supplied.

Methods ​

bindEvent ​

bindEvent(Thread th, EventContainer<BaseScriptContext<T>> event): voidSince1.6.0#
Associates an event container with a thread, replacing any existing association.

Parameters:

  • th: thread to associate
  • event: event container to associate

bindThread ​

bindThread(Thread t): booleanSince1.6.0#
Adds a thread to this context's bound-thread set.

Parameters:

  • t: thread to bind; null and binding after closure are rejected
Returns: true if the thread was not already bound

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 ​

getBoundEvents(): Map<Thread, EventContainer<? extends BaseScriptContext<T>>>Since1.6.0#
Returns the mutable map of threads to their bound event containers.
Returns: the backing map

getBoundThreads ​

getBoundThreads(): Set<Thread>Since1.6.0#
Returns the mutable backing set of threads bound to this context.
Returns: the live set of bound threads

getContainedFolder ​

getContainedFolder(): FileSince1.6.0#
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 unset

getFile ​

getFile(): FileSince1.6.0#
Returns the script file supplied when this context was created, if any.
Returns: the script file, or null if none was supplied

getMainThread ​

getMainThread(): ThreadSince1.5.0#
Returns the main execution thread, or null before it is assigned.
Returns: the main thread, or null before assignment

getSyncObject ​

getSyncObject(): Object#
Returns the sync object while it remains strongly referenced elsewhere, or null after collection.
Returns: sync object, or null if collected

getTriggeringEvent ​

getTriggeringEvent(): BaseEventSince1.5.0#
Returns the event that triggered this script, or null if none was supplied.
Returns: triggering event, or null

isContextClosed ​

isContextClosed(): boolean#
Returns whether the context is closed; also closes it if its weakly held sync object was cleared.
Returns: true if closed

isMultiThreaded ​

isMultiThreaded(): boolean#
Returns whether this language context supports concurrent execution on multiple threads.
Returns: true if concurrent execution on multiple threads is supported

releaseBoundEventIfPresent ​

releaseBoundEventIfPresent(Thread thread): booleanSince1.6.0#
Releases the event lock for the thread's bound event container, if present.

Parameters:

  • thread: thread whose event lock is released
Returns: true if an event container was present; otherwise false

setContext ​

setContext(T context): void#
Sets the language runtime context once; a second assignment is rejected.

Parameters:

  • context: runtime context to store

setMainThread ​

setMainThread(Thread t): voidSince1.5.0#
Assigns and binds the main thread; a second assignment is rejected.

Parameters:

  • t: thread to assign

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 holds

unbindThread ​

unbindThread(Thread t): voidSince1.6.0#
Removes a bound thread and releases its associated event lock, if present.

Parameters:

wrapSleep ​

wrapSleep(BaseScriptContext.SleepRunnable sleep): void#
Runs an operation that may block; the default implementation runs it directly.

Parameters:

  • sleep: operation to run