Package com.vaadin.signals.impl
Class SignalTree
java.lang.Object
com.vaadin.signals.impl.SignalTree
- Direct Known Subclasses:
 AsynchronousSignalTree,SynchronousSignalTree
Provides thread-safe access to a tree of signal nodes and a way of listening
 for changes to those nodes. There are two primary types of signal trees:
 synchronous trees have their changes applied immediately whereas asynchronous
 trees make a differences between submitted changes and changes that have been
 asynchronously confirmed.
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCollection of callbacks representing the possible stages when committing a transaction.static enumThe tree type, used to determine how different tree instances can be combined in a transaction. - 
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSignalTree(SignalTree.Type type) Creates a new signal tree with the given type. - 
Method Summary
Modifier and TypeMethodDescriptionvoidcommitSingleCommand(SignalCommand command) Applies a single command to this tree without listening for the result.voidcommitSingleCommand(SignalCommand command, Consumer<CommandResult> resultHandler) Applies a single command to this tree.abstract SnapshotGets the current snapshot based on all confirmed commands.getLock()Gets the lock that is used for protecting the integrity of this signal tree.protected <T> TgetWithLock(Supplier<T> action) Runs a supplier while holding the lock and returns the provided value.protected booleanhasLock()Checks whether the tree lock is currently held.id()Gets the id of this signal tree.protected voidnotifyObservers(Snapshot oldSnapshot, Snapshot newSnapshot) Notify all observers that are affected by changes between two snapshots.protected voidnotifyProcessedCommandSubscribers(List<SignalCommand> commands, Map<Id, CommandResult> results) Notifies all subscribers after a command is processed.observeNextChange(Id nodeId, TransientListener observer) Registers an observer for a node in this tree.abstract SignalTree.PendingCommitprepareCommit(CommandsAndHandlers changes) Starts the process of committing a set of changes.protected voidrunWithLock(Runnable action) Runs an action while holding the lock.abstract SnapshotGets the current snapshot based on all confirmed and submitted commands.subscribeToProcessed(BiConsumer<SignalCommand, CommandResult> subscriber) Registers a callback that is executed after commands are processed (regardless of acceptance or rejection).type()Gets the type of this signal tree.protected RunnablewrapWithLock(Runnable action) Wraps the provided action to run it while holding the lock. 
- 
Constructor Details
- 
SignalTree
Creates a new signal tree with the given type.- Parameters:
 type- the signal tree type, notnull
 
 - 
 - 
Method Details
- 
id
Gets the id of this signal tree. The id is a randomly generated unique value. The id is mainly used for identifying node ownership.- Returns:
 - the tree id, not 
null - See Also:
 
 - 
getLock
Gets the lock that is used for protecting the integrity of this signal tree. Locking is in general handled automatically by the tree but needs to be handled externally when applying transactions so that all trees participating in a transaction are locked before starting to evaluate the transaction.- Returns:
 - the tree lock instance, not 
null 
 - 
hasLock
protected boolean hasLock()Checks whether the tree lock is currently held.- Returns:
 trueif the lock is held by the current thread
 - 
getWithLock
Runs a supplier while holding the lock and returns the provided value.- Type Parameters:
 T- the supplier type- Parameters:
 action- the supplier to run, notnull- Returns:
 - the value returned by the supplier
 
 - 
runWithLock
Runs an action while holding the lock.- Parameters:
 action- the action to run, notnull
 - 
wrapWithLock
Wraps the provided action to run it while holding the lock.- Parameters:
 action- the action to wrap, notnull- Returns:
 - a runnable that runs the provided action while holding the lock,
         not 
null 
 - 
observeNextChange
Registers an observer for a node in this tree. The observer will be invoked the next time the corresponding node is updated in the submitted snapshot. The observer is removed when invoked and needs to be registered again if it's still relevant unless it returnstrue. It is safe to register the observer again from within the callback.- Parameters:
 nodeId- the id of the node to observe, notnullobserver- the callback to run when the node has changed, notnull- Returns:
 - a callback that can be used to remove the observer before it's
         triggered, not 
null 
 - 
notifyObservers
Notify all observers that are affected by changes between two snapshots. All notified observers are removed. It is safe for an observer to register itself again when it is invoked.- Parameters:
 oldSnapshot- the old snapshot, notnullnewSnapshot- the new snapshot, notnull- See Also:
 
 - 
submitted
Gets the current snapshot based on all confirmed and submitted commands.- Returns:
 - the submitted snapshot, not 
null 
 - 
confirmed
Gets the current snapshot based on all confirmed commands. This snapshot does not contain changes from commands that have been submitted but not yet confirmed.- Returns:
 - the confirmed snapshot, not 
null 
 - 
commitSingleCommand
Applies a single command to this tree. This is a shorthand for committing only a single command.- Parameters:
 command- the command to apply, notnullresultHandler- a result handler that will be notified when the command is confirmed, notnullto ignore the result
 - 
commitSingleCommand
Applies a single command to this tree without listening for the result.- Parameters:
 command- the command to apply, notnull- See Also:
 
 - 
prepareCommit
Starts the process of committing a set of changes. The returned instance defines callbacks for continuing the commit procedure.Note that this method expects that the caller has acquired the tree lock prior to calling the method and that the lock will remain acquired while interacting with the returned object.
- Parameters:
 changes- the changes to commit, notnull- Returns:
 - callbacks for coordinating the rest of the commit sequence, not
         
null 
 - 
type
Gets the type of this signal tree.- Returns:
 - the signal tree type, not 
null 
 - 
subscribeToProcessed
Registers a callback that is executed after commands are processed (regardless of acceptance or rejection). It is guaranteed that the callback is invoked in the order the commands are processed. Contrary to the observers that are attached to a specific node by callingobserveNextChange(com.vaadin.signals.Id, com.vaadin.signals.impl.TransientListener), thesubscriberremains active indefinitely until it is removed by executing the returned callback.- Parameters:
 subscriber- the callback to run when a command is confirmed, notnull- Returns:
 - a callback that can be used to remove the subscriber, not
         
null 
 - 
notifyProcessedCommandSubscribers
protected void notifyProcessedCommandSubscribers(List<SignalCommand> commands, Map<Id, CommandResult> results) Notifies all subscribers after a command is processed. This method must be called from a code block that holds the tree lock.- Parameters:
 commands- the list of processed commands, notnullresults- the map of results for the commands, notnull
 
 -