Package edu.wpi.grip.core.observables
Class SynchronizedObservable<T>
- java.lang.Object
-
- edu.wpi.grip.core.observables.SimpleObservable<T>
-
- edu.wpi.grip.core.observables.SynchronizedObservable<T>
-
- Type Parameters:
T- the type of the values to observe
- All Implemented Interfaces:
Observable<T>
public class SynchronizedObservable<T> extends SimpleObservable<T>
A thread-safe implementation ofObservable. This should only be used in situations where observers are very likely to run in multiple threads. Otherwise,SimpleObservableshould be used to avoid the penalties ofsynchronizedand lock contention.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObserver(Observer<? super T> observer)Add an observer to this observable.Tget()Gets the current value of this observable.voidremoveObserver(Observer<? super T> observer)Removes an observer from this observable.voidset(T value)Sets the value of this observable.
-
-
-
Method Detail
-
addObserver
public void addObserver(Observer<? super T> observer)
Description copied from interface:ObservableAdd an observer to this observable. It will be notified of any future changes to the value of this observable. Listeners will be fired in the order in which they were added, and on the thread that updates the observed value. Because of this, listeners should take as little time as possible to run (unless submitting a long-running task to a worker thread).- Specified by:
addObserverin interfaceObservable<T>- Overrides:
addObserverin classSimpleObservable<T>
-
removeObserver
public void removeObserver(Observer<? super T> observer)
Description copied from interface:ObservableRemoves an observer from this observable. The observer will not be updated with future changes to the value of this observable.- Specified by:
removeObserverin interfaceObservable<T>- Overrides:
removeObserverin classSimpleObservable<T>
-
get
public T get()
Description copied from interface:ObservableGets the current value of this observable.- Specified by:
getin interfaceObservable<T>- Overrides:
getin classSimpleObservable<T>
-
set
public void set(T value)
Description copied from interface:ObservableSets the value of this observable. If it's notequalto the current value, all observers will be notified of the change.- Specified by:
setin interfaceObservable<T>- Overrides:
setin classSimpleObservable<T>
-
-