Package com.vaadin.signals.local
Class AbstractLocalSignal<T>
java.lang.Object
com.vaadin.signals.local.AbstractLocalSignal<T>
- Type Parameters:
T- the signal value type
- All Implemented Interfaces:
Signal<T>,Serializable
- Direct Known Subclasses:
ListSignal,ValueSignal
Base class for local signals providing shared listener notification, usage
tracking, and value access logic.
- 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.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.value()Gets the current value of this signal.
-
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. Default implementation does nothing. -
value
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.effect(EffectAction)orSignal.computed(SignalComputation)callback sets up that effect or computed signal to depend on the signal. -
peek
Description copied from interface:SignalReads the value without setting up any dependencies. This method returns the same value asSignal.value()but without creating a dependency when used inside a transaction, effect or computed signal. -
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
-