org.wamblee.observer
Class Observable<ObservableType,Event>

java.lang.Object
  extended by org.wamblee.observer.Observable<ObservableType,Event>

public class Observable<ObservableType,Event>
extends java.lang.Object

Implements subscription and notification logic for an observer pattern. This class is thread safe.


Constructor Summary
Observable(ObservableType aObservable, ObserverNotifier<ObservableType,Event> aNotifier)
          Constructs the observable.
 
Method Summary
 int getObserverCount()
          Gets the number of subscribed observers.
 void send(Event aEvent)
          Notifies all subscribed observers.
 long subscribe(Observer<ObservableType,Event> aObserver)
          Subscribe an obvers.
 void unsubscribe(long aSubscription)
          Unsubscribe an observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Observable

public Observable(ObservableType aObservable,
                  ObserverNotifier<ObservableType,Event> aNotifier)
Constructs the observable.

Parameters:
aObservable - Observable this instance is used for.
aNotifier - Object used for implementing notification of listeners.
Method Detail

subscribe

public long subscribe(Observer<ObservableType,Event> aObserver)
Subscribe an obvers.

Parameters:
aObserver - Observer to subscribe.
Returns:
Event Event to send.

unsubscribe

public void unsubscribe(long aSubscription)
Unsubscribe an observer.

Parameters:
aSubscription - Subscription which is used
Throws:
java.lang.IllegalArgumentException - In case the subscription is not known.

getObserverCount

public int getObserverCount()
Gets the number of subscribed observers.

Returns:
Number of subscribed observers.

send

public void send(Event aEvent)
Notifies all subscribed observers.

Parameters:
aEvent - Event to send.


Copyright © 2022. All Rights Reserved.