JQuantLib v0.1.2-SNAPSHOT API Javadocs

org.jquantlib.util
Class DefaultObservable

Package class diagram package DefaultObservable
java.lang.Object
  extended by org.jquantlib.util.DefaultObservable
All Implemented Interfaces:
Observable
Direct Known Subclasses:
WeakReferenceObservable

@NotThreadSafe
public class DefaultObservable
extends java.lang.Object
implements Observable

Default implementation of an Observable.

This implementation notifies the observers in a synchronous fashion. Note that this can cause trouble if you notify the observers while in a transactional context because once the notification is done it cannot be rolled back.

Author:
Richard Gomes, Srinivas Hasti
See Also:
Martin Fischer: Observer and Observable interfaces, Improved Observer/Observable, Observable, Observer, WeakReferenceObservable

Field Summary
private static Logger logger
           
private  Observable observable
           
private  java.util.List<Observer> observers
           
 
Constructor Summary
DefaultObservable(Observable observable)
           
 
Method Summary
 void addObserver(Observer observer)
          Attaches a observer to the Observable.
 int countObservers()
          Counts how many Observers were attached to this class.
 void deleteObserver(Observer observer)
          Detaches a previously attached observer to the observable.
 void deleteObservers()
          Detaches all previously attached observer to the observable.
 java.util.List<Observer> getObservers()
          Returns list of observers registered with the Observable.
 void notifyObservers()
          Notifies all attached observers about changes in the observable.
 void notifyObservers(java.lang.Object arg)
          Notifies all attached observers about changes in the observable.
protected  void wrappedNotify(Observer observer, Observable observable, java.lang.Object arg)
          This method is intended to encapsulate the notification semantics, in order to let extended classes to implement their own version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final Logger logger

observers

private final java.util.List<Observer> observers

observable

private final Observable observable
Constructor Detail

DefaultObservable

public DefaultObservable(Observable observable)
Method Detail

addObserver

public void addObserver(Observer observer)
Description copied from interface: Observable
Attaches a observer to the Observable. After attachment the observer gets informed about changes in the Observable.

Specified by:
addObserver in interface Observable
Parameters:
observer - The observer to attach to the observable

countObservers

public int countObservers()
Description copied from interface: Observable
Counts how many Observers were attached to this class.

Specified by:
countObservers in interface Observable
Returns:
the number of Observers
See Also:
Observer

getObservers

public java.util.List<Observer> getObservers()
Description copied from interface: Observable
Returns list of observers registered with the Observable. List returned is unmodifiable list.

Specified by:
getObservers in interface Observable
Returns:
list of observers

deleteObserver

public void deleteObserver(Observer observer)
Description copied from interface: Observable
Detaches a previously attached observer to the observable. After detachment the observer does no longer receive change notifications from the observable.

Specified by:
deleteObserver in interface Observable
Parameters:
observer - The observer to detach from the observable

deleteObservers

public void deleteObservers()
Description copied from interface: Observable
Detaches all previously attached observer to the observable. After detachment observers do not longer receive change notifications from the observable.

Specified by:
deleteObservers in interface Observable

notifyObservers

public void notifyObservers()
Description copied from interface: Observable
Notifies all attached observers about changes in the observable.

Specified by:
notifyObservers in interface Observable

notifyObservers

public void notifyObservers(java.lang.Object arg)
Description copied from interface: Observable
Notifies all attached observers about changes in the observable.

Specified by:
notifyObservers in interface Observable
Parameters:
arg - an arbitrary Object to be passed to the Observer

wrappedNotify

protected void wrappedNotify(Observer observer,
                             Observable observable,
                             java.lang.Object arg)
This method is intended to encapsulate the notification semantics, in order to let extended classes to implement their own version. Possible implementations are:
  • remote notification;
  • notification via SwingUtilities.invokeLater
  • others...
  • The default notification simply does

     observer.update(observable, arg);
     

    Parameters:
    observer -
    observable -
    arg -

    JQuantLib v0.1.2-SNAPSHOT API Javadocs

    Submit a bug or feature

    JQuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email mailto:jquant-devel@lists.sourceforge.net. The license is also available online at http://www.jquantlib.org/index.php/LICENSE.TXT.