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 the threads the script owns, and removes this context from its runner. Engine threads that only call into the script for a callback are excluded from that interrupt wave, because interrupting a game or network thread mid-work corrupts state outside the script.

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 as a thread the script owns. Owned threads are interrupted when the context closes.

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. A call made after the context already closed still records the flag but performs no teardown.

Parameters:

  • preventLog: whether to suppress the cancellation log
closeContext(): void#
Closes this context once: releases bound event locks, interrupts the threads the script owns, gives the language a chance to close its runtime, and unregisters the context from the runner. Later calls do nothing. Threads bound only for callback dispatch through bindCallerThread() are not interrupted here; a language runtime may still apply its own cancellation while doSubclassClose() runs. The context monitor is released before event locks are released and before the language runtime closes, because an interrupted thread may need to unbind itself and closing a runtime may wait for those threads. Owned threads are selected and interrupted under the monitor so an unbind cannot finish between those two steps.

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. Closing is done outside this context's monitor so a language runtime close can wait for threads that need to unbind themselves.
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. The event is located under the context monitor but released after it is dropped, so this path and closeContext() acquire the event and context monitors in the same order.

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. If this context closed while the runtime was being built, the runtime is closed instead of published, so it cannot run after a stop.

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. The event is located under the context monitor but released after it is dropped, so this path and closeContext() acquire the event and context monitors in the same order.

Parameters:

wrapSleep ​

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

Parameters:

  • sleep: operation to run