FileDocCategorySizeDatePackage
Observable.javaAPI DocExample4413Wed Feb 05 01:48:20 GMT 1997imaginary.util

Observable

public class Observable extends UnicastRemoteObject implements RemoteObservable
This class is a distributed version of the standard Java Observable class. It uses the exact same API as the Java class.
see
java.util.Observable

Fields Summary
private boolean
changed
private Vector
observers
Constructors Summary
public Observable()
Constructs a new observable


      
             
        
        super();
    
Methods Summary
public synchronized voidaddObserver(RemoteObserver ob)
Adds a RemoteObserver to the list of objects observing this object.

param
ob the new RemoteObserver

        if( !observers.contains(ob) ) {
            observers.addElement(ob);
        }
    
protected synchronized voidclearChanged()
Marks the observable as unchanged.

        changed = false;
    
public synchronized intcountObservers()

return
the number of observers observing this object

        return observers.size();
    
public synchronized voiddeleteObserver(RemoteObserver ob)
Removes the specified RemoteObserver from the list of objects being observed.

param
ob the RemoteObserver to be removed

        if( observers.contains(ob) ) {
            observers.removeElement(ob);
        }
    
public synchronized voiddeleteObservers()
Clears out the entire observer list.

        observers = new Vector();
    
public synchronized booleanhasChanged()

return
true if the observable is flagged as changed

        return changed;
    
public voidnotifyObservers(java.rmi.Remote r)
Notifies observers of a change with the specified remote reference as an argument.

param
r the remote object to pass to observers

        performNotify(r);
    
public voidnotifyObservers(java.io.Serializable s)
Notifies observers of a change with the specified serializable object as an argument.

param
s the serializable object to send to the observers

        performNotify(s);
    
public voidnotifyObservers()
Assuming the object has been changed called, this method will notify its observers with null as an argument.

        performNotify(null);
    
public voidperformNotify(java.lang.Object arg)

        RemoteObserver[] obs;
        int count;
        
        synchronized (this) {
            if( !hasChanged() ) {
                return;
            }
            count = observers.size();
            obs = new RemoteObserver[count];
            observers.copyInto(obs);
            clearChanged();
        }
        for(int i=0; i<count; i++) {
            if( obs[i] != null ) {
                try {
                    obs[i].update(this, arg);
                }
                catch( RemoteException e ) {
                    e.printStackTrace();
                }
            }
        }
    
protected synchronized voidsetChanged()
Marks the observable as changed.

        changed = true;