Package net.apartium.cocoabeans.state
Class WatcherManager
java.lang.Object
net.apartium.cocoabeans.state.WatcherManager
- All Implemented Interfaces:
WatcherOperator
A reference implementation of
WatcherOperator, referencing watchers via an identity hash set.
This implementation is thread safe.
NOTE: To make an instance do anything, its heartbeat() method has to be triggered externally.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddetach(AttachedWatcher<?> watcher) Detach a watcher attached with the current instancevoidTriggers heartbeat on all the attached watchers<T> AttachedWatcher<T>watch(Observable<T> depends, Consumer<T> consumer) Creates a watcher instance attached to the current instance
-
Constructor Details
-
WatcherManager
public WatcherManager()
-
-
Method Details
-
heartbeat
public void heartbeat()Triggers heartbeat on all the attached watchers- See Also:
-
watch
Creates a watcher instance attached to the current instance- Type Parameters:
T- state element type- Parameters:
depends- observable to depend onconsumer- action to run on change of the observable- Returns:
- a new attached watcher instance
- See Also:
-
detach
Detach a watcher attached with the current instance- Specified by:
detachin interfaceWatcherOperator- Parameters:
watcher- watcher instance
-