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,SimpleObservable
should be used to avoid the penalties ofsynchronized
and lock contention.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addObserver(Observer<? super T> observer)
Add an observer to this observable.T
get()
Gets the current value of this observable.void
removeObserver(Observer<? super T> observer)
Removes an observer from this observable.void
set(T value)
Sets the value of this observable.
-
-
-
Method Detail
-
addObserver
public void addObserver(Observer<? super T> observer)
Description copied from interface:Observable
Add 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:
addObserver
in interfaceObservable<T>
- Overrides:
addObserver
in classSimpleObservable<T>
-
removeObserver
public void removeObserver(Observer<? super T> observer)
Description copied from interface:Observable
Removes an observer from this observable. The observer will not be updated with future changes to the value of this observable.- Specified by:
removeObserver
in interfaceObservable<T>
- Overrides:
removeObserver
in classSimpleObservable<T>
-
get
public T get()
Description copied from interface:Observable
Gets the current value of this observable.- Specified by:
get
in interfaceObservable<T>
- Overrides:
get
in classSimpleObservable<T>
-
set
public void set(T value)
Description copied from interface:Observable
Sets the value of this observable. If it's notequal
to the current value, all observers will be notified of the change.- Specified by:
set
in interfaceObservable<T>
- Overrides:
set
in classSimpleObservable<T>
-
-