Class PamObservable
- Direct Known Subclasses:
PamDataBlock
- Author:
- Doug Gillespie
Similar functionality to the Observable Class, but works with the PamObserver interface which has a bit more functionality.
e.g. The PamDataBlock, which is the most common class of PamObservable asks the observers what the first required sample is for each observing process or view.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longSample numbers are now passed around to all observers.protected booleanprotected PanelOverlayDrawReference to a class that knows how to draw these things on any of the standard displays in the view, e.g.protected PamProfiler -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an observer which will always get called before data are saved or sent on to 'normal' processes.voidAdds a PamObserver, which will then receive notifications when data is added.voidaddObserver(PamObserver observer, boolean reThread) booleancanDraw(GeneralProjector generalProjector) booleancanDraw(GeneralProjector.ParameterType[] parameterTypes, GeneralProjector.ParameterUnits[] parameterUnits) voidSet flag to say the data have changedintcreateKeyItem(GeneralProjector generalProjector, int keyType) voidRemoves an observer from the list of things that get notified from this datablockvoidRemoves all observers from the listdrawDataUnit(Graphics g, PamDataUnit pamDataUnit, GeneralProjector projectorInfo) Go through the observer list and check inside any that are wrapped in threaded observers,doublegetCPUPercent(int objectIndex) doublegetCPUPercent(PamObserver pamObserver) getHoverText(GeneralProjector generalProjector, PamDataUnit dataUnit, int iSide) protected List<PamObserver> intGet the maximum jitter allowable on output of an observable.getPamObserver(int ind) Get a pam observer at the given index.protected List<PamObserver> longGoes through all observers and works out which requires data the longest.booleanSee if an observer is in the instant list.voidNotify just the instant observers.voidNotify the 'normal' observes, i.e.voidInstruction to notify observers that data have changed, but not to send them any information about the new data.voidNotify observers that data have changed and send them a reference to the new Data Have tried to synchronise this, but it can cuase a lockup - not 100% sure what to dovoidSet flag to say the data have changedvoidsetOverlayDraw(PanelOverlayDraw overlayDraw) voidHad some issues with the Timer holding a reference to the underlying PamDataBlock (RoccaContourDataBlock, in this case) and not releasing it for garbage collection.voidupdateObservers(PamDataUnit dataUnit) Notify all observes of an update.booleanwaitForThreadedObservers(long timeOutms) Go through all the threaded observers and wait for them to finish processing any data remaining in their lists.
-
Field Details
-
objectChanged
protected boolean objectChanged -
overlayDraw
Reference to a class that knows how to draw these things on any of the standard displays in the view, e.g. whistle contours, particular shapes on the map, etc. -
pamProfiler
-
masterClockSample
protected long masterClockSampleSample numbers are now passed around to all observers.
-
-
Constructor Details
-
PamObservable
public PamObservable()
-
-
Method Details
-
addObserver
Adds a PamObserver, which will then receive notifications when data is added. This is for single thread ops only- Parameters:
o- Reference to the observer
-
addInstantObserver
Add an observer which will always get called before data are saved or sent on to 'normal' processes.- Parameters:
o- Observer
-
addObserver
-
findThreadedObserver
Go through the observer list and check inside any that are wrapped in threaded observers,- Parameters:
o-- Returns:
- reference to threadedobserver.
-
waitForThreadedObservers
public boolean waitForThreadedObservers(long timeOutms) Go through all the threaded observers and wait for them to finish processing any data remaining in their lists.- Parameters:
timeOutms- timeout in milliseconds- Returns:
- false if the timeout time was reached before all threaded observers had emptied their queues. true if all queues had been emptied successfully.
-
deleteObserver
Removes an observer from the list of things that get notified from this datablockThis will mess up if it's ever called directly from within PamProcess since a local record of the source datablock will remain in memory and not be cleared. Instead you should call PamProcess.setParentDataBlock(null) which will guarantee the necessary bookkeeping is carried out with PamProcess before calling this function.
- Parameters:
o- Observer to remove
-
deleteObservers
public void deleteObservers()Removes all observers from the list -
countObservers
public int countObservers()- Returns:
- Count of PamObservers subscribing to this observable including instant and rethreaded
-
getPamObserver
Get a pam observer at the given index.- Parameters:
ind-- Returns:
-
notifyObservers
public void notifyObservers()Instruction to notify observers that data have changed, but not to send them any information about the new data. -
setChanged
public void setChanged()Set flag to say the data have changed -
clearchanged
public void clearchanged()Set flag to say the data have changed -
notifyObservers
Notify observers that data have changed and send them a reference to the new Data Have tried to synchronise this, but it can cuase a lockup - not 100% sure what to do- Parameters:
o- Reference to the new PamDataUnit
-
notifyInstantObservers
Notify just the instant observers.- Parameters:
o- PamDataUnit that's been updated.
-
notifyNornalObservers
Notify the 'normal' observes, i.e. the ones which aren't instant.- Parameters:
o- PamDataUnit that's been updated.
-
updateObservers
Notify all observes of an update.- Parameters:
dataUnit-
-
isInstantObserver
See if an observer is in the instant list.- Parameters:
o- Pam Observer- Returns:
- true if it's in the instant list.
-
stopTimer
public void stopTimer()Had some issues with the Timer holding a reference to the underlying PamDataBlock (RoccaContourDataBlock, in this case) and not releasing it for garbage collection. Added in this method to force the timer to stop and release it's hold. -
getCPUPercent
public double getCPUPercent(int objectIndex) -
getCPUPercent
-
getRequiredHistory
public long getRequiredHistory()Goes through all observers and works out which requires data the longest.- Returns:
- Required data storage time in milliseconds.
-
getLongestObserver
-
setOverlayDraw
- Parameters:
overlayDraw- Instance of a concrete class implementing the PanelIverlayDraw interface.Called to set the class which can draw overlays of the PamDataUnits held in this data block.
-
drawDataUnit
- Parameters:
g- An awt Graphics objectprojectorInfo- Class implementing GeneralProjector which can convert data to screen coordinates.- Returns:
- a rectangle containing the pixels which will need to be
invalidated or redrawn by the calling process
Any PamObserver which has been notified by a PamObservable that a new PamDatUnit has been created can call this function to draw some arbitrary shape on the image, e.g. a whistle contour, a picture of a whale, etc.
This should be overridden in the concrete class if it is to do anything.
-
canDraw
- Parameters:
generalProjector-- Returns:
- true if there is a projector and the data can draw on it.
-
canDraw
public boolean canDraw(GeneralProjector.ParameterType[] parameterTypes, GeneralProjector.ParameterUnits[] parameterUnits) -
getHoverText
-
createKeyItem
-
getOverlayDraw
- Returns:
- the overlayDraw
-
getMaxThreadJitter
public int getMaxThreadJitter()Get the maximum jitter allowable on output of an observable. This used to be fixed at a single global value, but have made it more configurable so I can increase it for certain data blocks which have a very low data rate, but may take a lot of processing.- Returns:
- Maximum queue length in milliseconds.
-
getPamObservers
- Returns:
- the pamObservers
-
getInstantObservers
- Returns:
- the instantObservers
-