SignalContext
final class SignalContext
Package: dev.joid.lib.signal · Module: core · Source: SignalContext.java
Per-thread state of the signal engine: batches, silence, read tracking and the queue of notifications.
Description
Section titled “Description”Each thread has its own SignalContext, which Signal and ComputedSignal use to record reads, group notifications and defer writes made outside the render thread.
Application code uses Signal.batch(...) and Signal.silent(...) instead.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
SignalContext | current() factory | Returns the context of the calling thread. |
Methods
Section titled “Methods”Lifecycle
Section titled “Lifecycle”| Returns | Signature | Summary |
|---|---|---|
void | open() | Opens a batch: notifications wait until the matching close(). |
void | close() | Closes a batch; at the outermost level, it sends the deferred writes to the render thread and delivers the notifications. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
long | getEpoch() static | Returns the global change counter, which grows on every change of any signal. |
int | countWriteBack(Signal<?> signal) | Counts the writes back to signal during the delivery in progress and returns the count; it returns 0 outside a delivery. |
Object | getWriteBackOrigin(Signal<?> signal) | Returns the value signal had before its first write back in the delivery in progress. |
boolean | hasReads() | If true, reads are waiting for the replay of an expression. |
long | getReadTotal() | Returns the number of reads recorded on this thread since it started. |
boolean | isSilent() | If true, the changes on this thread notify no listener. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
long | nextEpoch() static | Increases the global change counter and returns its value. |
void | defer(Runnable task) | Queues a write for the render thread: at the end of the batch inside a batch, otherwise at once. |
void | settle(Runnable task) | Runs task after the notifications being delivered, or at once when none are. |
Runnable | keepSilence(Runnable task) | Returns a task that runs task with the silence that holds now. |
void | read(Signal<?> signal) | Records a read of signal for the computation or the read tracking in progress. |
boolean | tracing(boolean tracing) | Sets whether reads outside a computation are recorded for the replay of expressions, and returns the previous setting. |
T | untracked(Supplier<? extends T> supplier) | Returns the result of supplier without recording any of its reads. |
ComputedSignal<?> | observe(ComputedSignal<?> observer) | Sets the derived signal that receives the reads, and returns the previous one; null stops the recording. |
void | schedule(Signal<?> signal) | Queues the notification of signal, once per delivery. |
List<Signal<?>> | takeReads() | Returns the reads recorded for the replay, oldest first, and forgets them. |
void | putBackReads(List<Signal<?>> readList) | Puts back reads that a replay did not use, before the reads recorded since. |
void | clearReads() | Forgets the reads recorded for the replay. |
boolean | silent(boolean silent) | Sets whether the changes on this thread notify listeners, and returns the previous setting. |
Creation details
Section titled “Creation details”current
Section titled “current”SignalContext current() factory
Returns the context of the calling thread.
Method details
Section titled “Method details”void open()
Opens a batch: notifications wait until the matching close().
void close()
Thread: runs on the render thread.
Closes a batch; at the outermost level, it sends the deferred writes to the render thread and delivers the notifications. When listeners throw, the others still run and the first exception is thrown at the end.
getEpoch
Section titled “getEpoch”long getEpoch() static
Returns the global change counter, which grows on every change of any signal.
countWriteBack
Section titled “countWriteBack”int countWriteBack(Signal<?> signal)
Counts the writes back to signal during the delivery in progress and returns the count; it returns 0 outside a delivery.
Bound controls use it to stop two controls that keep correcting each other.
getWriteBackOrigin
Section titled “getWriteBackOrigin”Object getWriteBackOrigin(Signal<?> signal)
Returns the value signal had before its first write back in the delivery in progress.
hasReads
Section titled “hasReads”boolean hasReads()
If true, reads are waiting for the replay of an expression.
getReadTotal
Section titled “getReadTotal”long getReadTotal()
Returns the number of reads recorded on this thread since it started.
isSilent
Section titled “isSilent”boolean isSilent()
If true, the changes on this thread notify no listener.
nextEpoch
Section titled “nextEpoch”long nextEpoch() static
Increases the global change counter and returns its value.
void defer(Runnable task)
Thread: runs on the render thread.
Queues a write for the render thread: at the end of the batch inside a batch, otherwise at once. The write keeps the silence of the code that queued it.
settle
Section titled “settle”void settle(Runnable task)
Runs task after the notifications being delivered, or at once when none are.
keepSilence
Section titled “keepSilence”Runnable keepSilence(Runnable task)
Returns a task that runs task with the silence that holds now.
void read(Signal<?> signal)
Records a read of signal for the computation or the read tracking in progress.
tracing
Section titled “tracing”boolean tracing(boolean tracing)
Sets whether reads outside a computation are recorded for the replay of expressions, and returns the previous setting.
untracked
Section titled “untracked”<T> T untracked(Supplier<? extends T> supplier)
Returns the result of supplier without recording any of its reads.
observe
Section titled “observe”ComputedSignal<?> observe(ComputedSignal<?> observer)
Sets the derived signal that receives the reads, and returns the previous one; null stops the recording.
schedule
Section titled “schedule”void schedule(Signal<?> signal)
Queues the notification of signal, once per delivery.
takeReads
Section titled “takeReads”List<Signal<?>> takeReads()
Returns the reads recorded for the replay, oldest first, and forgets them.
putBackReads
Section titled “putBackReads”void putBackReads(List<Signal<?>> readList)
Puts back reads that a replay did not use, before the reads recorded since.
clearReads
Section titled “clearReads”void clearReads()
Forgets the reads recorded for the replay.
silent
Section titled “silent”boolean silent(boolean silent)
Sets whether the changes on this thread notify listeners, and returns the previous setting.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
