edu.mit.ai.psg.traveler
Class ObservableSupport

java.lang.Object
  |
  +--edu.mit.ai.psg.traveler.ObservableSupport

public class ObservableSupport
extends Object

Support for observable activity records. Designed around the following assumptions:

  1. records may number in the hundreds of thousands or more, so minimizing space is a concern.
  2. once activity has finished, record will no longer change.
Since only a tiny subset of the possible records may be observed, don't waste space with fields in every record to record observers; instead, use a single instance of this class for all records (or all records of a class). This class keeps observer information in a hashtable, and deletes it if the record finishes, thus consuming space proportional to the small number of records that are actually being observed and are subject to change.

To initialize the support for each record, call initializeSupport(java.lang.Object). To release activity as finished, call finished(java.lang.Object). To test whether a record is is finished, test isFinished(java.lang.Object). Note: This class not related to java.util.Observable except in concept.


Field Summary
protected  Map inProgress
          inProgress: used to keep track of records that are in progress, and keeps any observers.
 
Constructor Summary
ObservableSupport()
           
 
Method Summary
 void addChangeObserver(Object record, ChangeObserver observer)
           
 void ensureUnfinished(Object record)
           
 void finished(Object record)
          call if record is finished and no further changes will be made; removes all observers, releasing their storage.
 void fireNotifyAdded(Object observeeRecord, Object newRecord)
           
 void fireNotifyChanged(Object observeeRecord)
           
 boolean hasObservers(Object record)
           
 void initializeSupport(Object record)
          Call when activity record is created, e.g., from constructor.
 boolean isFinished(Object record)
          assumes initializeSupport(java.lang.Object) has been called on record; returns true if finished(java.lang.Object) has also been called on record.
 void removeChangeObserver(Object record, ChangeObserver observer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inProgress

protected Map inProgress
inProgress: used to keep track of records that are in progress, and keeps any observers. keys: ActivityRecordObervableBase instances. value == Boolean.TRUE: in progress, no ChangeObservers. value instanceof Set: in progress, set of ChangeObservers. value == null: finished, not in progress.
Constructor Detail

ObservableSupport

public ObservableSupport()
Method Detail

initializeSupport

public void initializeSupport(Object record)
Call when activity record is created, e.g., from constructor. (Note: record should not be equal to any other record, as it is used as key for hash table)

finished

public void finished(Object record)
call if record is finished and no further changes will be made; removes all observers, releasing their storage. (Note that it is usually inappropriate to call this from an implementation for ActivityRecord.finished, because that is called when the creating thread has completed, but child threads may not have added themselves yet and will not be observed after finished is called.)

isFinished

public boolean isFinished(Object record)
assumes initializeSupport(java.lang.Object) has been called on record; returns true if finished(java.lang.Object) has also been called on record.

ensureUnfinished

public void ensureUnfinished(Object record)

hasObservers

public boolean hasObservers(Object record)

addChangeObserver

public void addChangeObserver(Object record,
                              ChangeObserver observer)

removeChangeObserver

public void removeChangeObserver(Object record,
                                 ChangeObserver observer)

fireNotifyChanged

public void fireNotifyChanged(Object observeeRecord)

fireNotifyAdded

public void fireNotifyAdded(Object observeeRecord,
                            Object newRecord)

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-feedback@ai.mit.edu