Skip to content

EventContainer ​

com.jsmacrosce.jsmacros.core.language.EventContainer

Since1.4.0

Tracks a joined event's lock and callbacks queued until its release.

Type Parameters ​

  • T: associated script-context type

Constructors ​

new EventContainer ​

new EventContainer(T extends BaseScriptContext<?> ctx)#
Stores the supplied context reference and starts locked with no lock thread or queued callbacks. A null context is accepted, but the first releaseLock() call then fails with NullPointerException.

Parameters:

  • ctx: context associated with this container; may be null

Methods ​

awaitLock ​

awaitLock(Runnable then): voidSince1.4.0#
Waits once while locked, queueing a non-null callback; the wait may return spuriously. If already released, runs the callback immediately. Callback failures are logged.

Parameters:

  • then: callback to run on release; when called from a thread bound to the context, a non-null callback must be a MethodWrapper. May be null while locked, but must be non-null if already released.

getCtx ​

getCtx(): T extends BaseScriptContext<?>#
Returns the associated script context, or null if none was supplied.
Returns: associated context, possibly null

getLockThread ​

getLockThread(): Thread#
Returns the associated thread, or null before assignment.
Returns: lock thread

isLocked ​

isLocked(): boolean#
Returns whether this container's event lock is still held.
Returns: true until the first release

releaseLock ​

releaseLock(): voidSince1.4.0#
Releases this lock once, runs queued callbacks, wakes waiters, and removes its thread association from the context. If still locked, a null context causes NullPointerException; an already released lock is a no-op. Callback failures are logged and do not prevent later callbacks from running.

setLockThread ​

setLockThread(Thread lockThread): void#
Sets the lock thread; while locked and when a context is present, registers this container in its event map. A non-null thread can be assigned only while no non-null thread has been assigned; assigning null leaves it assignable.

Parameters:

  • lockThread: thread associated with the lock; may be null

toString ​

toString(): String#
Returns a diagnostic string containing the current lock state and lock-thread name; it is not a serialization format. Thread names are not escaped. With no assigned thread, the name is "null"; for example, ContextContainer:{"locked": true, "lockThread": "null"}.
Returns: diagnostic text in the form ContextContainer:{"locked": boolean, "lockThread": "name"}