Class ReferenceSignal<T>
- Type Parameters:
T- the signal value type
- All Implemented Interfaces:
Signal<T>,WritableSignal<T>
Changing the signal to reference another immutable value is an atomic operation. It is safe to concurrently read and write the signal value from multiple threads.
The signal can also be used with mutable values in which case no thread
safety is provided. Mutations must be done through modify(Consumer)
to ensure dependents are informed after the modification is applied.
Reference signals can't be used inside signal transactions.
All operation objects returned from methods on this class are resolved immediately.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRuns the given callback to apply changes to a mutable referenced value and then notifies dependents.peek()Reads the value without setting up any dependencies.Sets the value of this signal if and only if the signal has the expected value at the time when the operation is confirmed.update(UnaryOperator<T> updater) Updates the signal value based on the given callback.value()Gets the current value of this signal.Sets the value of this signal.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.signals.WritableSignal
asReadonly
-
Constructor Details
-
ReferenceSignal
-
ReferenceSignal
public ReferenceSignal()
-
-
Method Details
-
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(Runnable)orSignal.computed(Supplier)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. -
value
Description copied from interface:WritableSignalSets the value of this signal. The result of the returned operation will be resolved with the previous value at the time when this operation was confirmed.- Specified by:
valuein interfaceWritableSignal<T>- Parameters:
value- the value to set- Returns:
- an operation containing the eventual result
-
replace
Sets the value of this signal if and only if the signal has the expected value at the time when the operation is confirmed. This is the signal counterpart toAtomicReference.compareAndSet(Object, Object). The result of the returned operation will be resolved as successful if the expected value was present and resolved as unsuccessful if any other value was present when the operation is processed.Comparison between the expected value and the new value is performed using
Object.equals(Object).- Specified by:
replacein interfaceWritableSignal<T>- Parameters:
expectedValue- the expected valuenewValue- the new value- Returns:
- an operation containing the eventual result
-
update
Updates the signal value based on the given callback. The callback receives the current signal value and returns the new value to use. This implementation acquires a lock while running the updater which means that it's never necessary to run the callback again. This also means that canceling the returned operation will never have any effect.The result of the returned operation is resolved with the same value that was passed to the updater callback.
- Specified by:
updatein interfaceWritableSignal<T>- Parameters:
updater- the value update callback, notnull- Returns:
- an operation containing the result
-
modify
Runs the given callback to apply changes to a mutable referenced value and then notifies dependents.This method is only intended for cases where concurrency is limited through other means, such as Vaadin's session lock. Using this method concurrently with any other methods on the same instance may, but is not guaranteed to, cause an
ConcurrentModificationException. The exception can be thrown either from this method or from the other invoked method. This can happen even if the other method is safe for concurrent use.- Parameters:
modifier- a callback that receives the current value to modify, notnull
-