Skip to content

GraalScriptContext ​

com.jsmacrosce.jsmacros.graal.language.impl.GraalScriptContext

Holds the runtime context and task queue for a Graal script. Scripts obtain it from the context global:

js
const ctx = context.getCtx();  
Chat.log(ctx.isMultiThreaded());

Constructors ​

new GraalScriptContext ​

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

Parameters:

  • runner: owning core
  • event: triggering event, or null if none
  • file: script file, or null if none

Fields ​

tasks ​

Live per-context queue of wrapped threads, ordered using their stored priorities.

Methods ​

closeContext ​

closeContext(): void#
Releases bound event locks, interrupts bound threads and unregisters this context through base cleanup, then calls close(true) on the assigned Graal runtime if present.
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

getThreadPriority ​

static getThreadPriority(Object thread): int#
Selects a queue priority from a wrapped thread's stored priority.

Parameters:

  • thread: wrapped thread whose queue priority to inspect
Returns: the negated stored priority; negating Integer.MIN_VALUE leaves it unchanged

isMultiThreaded ​

isMultiThreaded(): boolean#
Reports that this context does not advertise concurrent execution on multiple threads.
Returns: false because this context does not advertise concurrent execution

setMainThread ​

setMainThread(Thread t): void#
Assigns and binds the main thread through the base context, then enqueues it with stored priority 5. This does not start the thread or change its Java thread priority.

Parameters:

  • t: thread to assign and bind

wrapSleep ​

wrapSleep(BaseScriptContext.SleepRunnable sleep): void#
Runs a potentially blocking operation through the task-queue scheduling path without changing its priority.

Parameters:

  • sleep: operation that may block and throw InterruptedException
wrapSleep(int changePriority, BaseScriptContext.SleepRunnable sleep): void#
Leaves the Graal runtime, polls the queue head and signals the next entry, if present, before running the operation. After the operation, a new wrapper for the calling thread is enqueued with the polled entry's stored priority plus changePriority, using Java integer arithmetic. It waits if the queue head then belongs to another thread. Runtime re-entry is attempted in the outer finally block after a successful leave. This requires an assigned, entered runtime and a suitable queue head; the method does not verify that the polled entry belongs to the caller. If the operation or wait is interrupted, this method does not remove the newly enqueued entry.

Parameters:

  • changePriority: adjustment added to the polled entry's stored priority for the new entry
  • sleep: operation to run while the runtime is left; it may block and throw InterruptedException