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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an observer which will always get called before data are saved or sent on to 'normal' processes.void
Adds a PamObserver, which will then receive notifications when data is added.void
addObserver
(PamObserver observer, boolean reThread) boolean
canDraw
(GeneralProjector generalProjector) boolean
canDraw
(GeneralProjector.ParameterType[] parameterTypes, GeneralProjector.ParameterUnits[] parameterUnits) void
Set flag to say the data have changedint
createKeyItem
(GeneralProjector generalProjector, int keyType) void
Removes an observer from the list of things that get notified from this datablockvoid
Removes 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,double
getCPUPercent
(int objectIndex) double
getCPUPercent
(PamObserver pamObserver) getHoverText
(GeneralProjector generalProjector, PamDataUnit dataUnit, int iSide) int
Get the maximum jitter allowable on output of an observable.getPamObserver
(int ind) Get a pam observer at the given index.long
Goes through all observers and works out which requires data the longest.boolean
See if an observer is in the instant list.void
Notify just the instant observers.void
Notify the 'normal' observes, i.e.void
Instruction to notify observers that data have changed, but not to send them any information about the new data.void
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 dovoid
Set flag to say the data have changedvoid
setOverlayDraw
(PanelOverlayDraw overlayDraw) void
Had some issues with the Timer holding a reference to the underlying PamDataBlock (RoccaContourDataBlock, in this case) and not releasing it for garbage collection.void
updateObservers
(PamDataUnit dataUnit) Notify all observes of an update.boolean
waitForThreadedObservers
(long timeOutms) Go through all the threaded observers and wait for them to finish processing any data remaining in their lists.
-
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.
-