EventContainer
com.jsmacrosce.jsmacros.core.language.EventContainer
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 benull
Methods
awaitLock
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 benullwhile 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
nullgetLockThread
isLocked
isLocked(): boolean#Returns whether this container's event lock is still held.
Returns:
true until the first releasereleaseLock
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
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 benull
toString
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"}