*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/**
* Implements subscription and notification logic for an observer pattern. This
* class is thread safe.
*/
public class Observable<ObservableType, Event> {
/**
* Implements subscription and notification logic for an observer pattern. This
* class is thread safe.
*/
public class Observable<ObservableType, Event> {
* Object used for implementing notification of listeners.
*/
public Observable(ObservableType aObservable,
* Object used for implementing notification of listeners.
*/
public Observable(ObservableType aObservable,
observable = aObservable;
notifier = aNotifier;
observers = new TreeMap<Long, Observer<ObservableType, Event>>();
observable = aObservable;
notifier = aNotifier;
observers = new TreeMap<Long, Observer<ObservableType, Event>>();
*/
public synchronized long subscribe(Observer<ObservableType, Event> aObserver) {
long subscription = counter++; // integer rage is so large it will
*/
public synchronized long subscribe(Observer<ObservableType, Event> aObserver) {
long subscription = counter++; // integer rage is so large it will
*/
public synchronized void unsubscribe(long aSubscription) {
Object obj = observers.remove(aSubscription);
*/
public synchronized void unsubscribe(long aSubscription) {
Object obj = observers.remove(aSubscription);
// potential deadlock
// situations.
List<Observer<ObservableType, Event>> myObservers = new ArrayList<Observer<ObservableType, Event>>();
// potential deadlock
// situations.
List<Observer<ObservableType, Event>> myObservers = new ArrayList<Observer<ObservableType, Event>>();
for (Observer<ObservableType, Event> observer : myObservers) {
notifier.update(observer, observable, aEvent);
}
for (Observer<ObservableType, Event> observer : myObservers) {
notifier.update(observer, observable, aEvent);
}