Class AbstractLocalSignal<T extends @Nullable Object>
- Type Parameters:
T- the signal value type
- All Implemented Interfaces:
Signal<T>,Serializable
- Direct Known Subclasses:
ListSignal,ValueSignal
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractLocalSignal(T initialValue) Creates a new signal with the given initial value. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAsserts that the current thread holds the lock.protected voidHook for subclasses to perform precondition checks before accessing the value.get()Gets the current value of this signal.protected TGets the current signal value.protected TGets the current signal value without checking that the lock is held.protected voidlock()Acquires the lock.peek()Reads the value without setting up any dependencies.protected voidsetSignalValue(T value) Sets the signal value and notifies all registered listeners.protected booleantryLock()Attempts to acquire the lock without blocking.protected voidunlock()Releases the lock.
-
Constructor Details
-
AbstractLocalSignal
Creates a new signal with the given initial value.- Parameters:
initialValue- the initial value
-
-
Method Details
-
checkPreconditions
protected void checkPreconditions()Hook for subclasses to perform precondition checks before accessing the value. Called while holding the lock. The base implementation verifies that the signal is not accessed from a different session than the one that first used it. -
get
Description copied from interface:SignalGets the current value of this signal. The value is read in a way that takes the current transaction into account and in the case of clustering also changes that have been submitted to the cluster but not yet confirmed.If the signal implementation supports transactions, then reading the value in a regular (i.e.
Transaction.Type.STAGED) transaction makes the transaction depend on the value so that the transaction fails in case the signal value is changed concurrently.Reading the value inside an
Signal.unboundEffect(EffectAction)orSignal.computed(SignalComputation)callback sets up that effect or computed signal to depend on the signal.This method must only be called within a reactive context such as an effect, a computed signal, an explicit
Signal.untracked(ValueSupplier)block, or atransaction. Calling it outside such a context throws anIllegalStateException. UseSignal.peek()for one-time reads that do not need dependency tracking. -
peek
Description copied from interface:SignalReads the value without setting up any dependencies. This method returns the same value asSignal.get()but without creating a dependency when used inside a transaction, effect or computed signal.Unlike
Signal.get(), this method can be called outside a reactive context and is the recommended way to read a signal value for one-time use, such as logging, assertions, or initializing non-reactive UI. -
lock
protected void lock()Acquires the lock. Must be followed byunlock()in a finally block. -
unlock
protected void unlock()Releases the lock. -
tryLock
protected boolean tryLock()Attempts to acquire the lock without blocking.- Returns:
- true if the lock was acquired, false otherwise
-
assertLockHeld
protected void assertLockHeld()Asserts that the current thread holds the lock. -
getSignalValue
Gets the current signal value. Must be called while holding the lock.- Returns:
- the current value
-
getSignalValueUnsafe
Gets the current signal value without checking that the lock is held. Only use when the caller ensures thread-safety through other means.- Returns:
- the current value
-
setSignalValue
Sets the signal value and notifies all registered listeners. Must be called while holding the lock.- Parameters:
value- the new value
-