Package PamguardMVC

Class PamObservable

java.lang.Object
PamguardMVC.PamObservable
Direct Known Subclasses:
PamDataBlock

public class PamObservable extends Object
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 Details

    • PamObservable

      public PamObservable()
  • Method Details

    • addObserver

      public void addObserver(PamObserver o)
      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

      public void addInstantObserver(PamObserver o)
      Add an observer which will always get called before data are saved or sent on to 'normal' processes.
      Parameters:
      o - Observer
    • addObserver

      public void addObserver(PamObserver observer, boolean reThread)
    • findThreadedObserver

      public ThreadedObserver findThreadedObserver(PamObserver o)
      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

      public void deleteObserver(PamObserver o)
      Removes an observer from the list of things that get notified from this datablock

      This 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

      public PamObserver getPamObserver(int ind)
      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

      public void notifyObservers(PamDataUnit o)
      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

      public void notifyInstantObservers(PamDataUnit o)
      Notify just the instant observers.
      Parameters:
      o - PamDataUnit that's been updated.
    • notifyNornalObservers

      public void notifyNornalObservers(PamDataUnit o)
      Notify the 'normal' observes, i.e. the ones which aren't instant.
      Parameters:
      o - PamDataUnit that's been updated.
    • updateObservers

      public void updateObservers(PamDataUnit dataUnit)
      Notify all observes of an update.
      Parameters:
      dataUnit -
    • isInstantObserver

      public boolean isInstantObserver(PamObserver o)
      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

      public double getCPUPercent(PamObserver pamObserver)
    • getRequiredHistory

      public long getRequiredHistory()
      Goes through all observers and works out which requires data the longest.
      Returns:
      Required data storage time in milliseconds.
    • getLongestObserver

      public PamObserver getLongestObserver()
    • setOverlayDraw

      public void setOverlayDraw(PanelOverlayDraw overlayDraw)
      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

      public Rectangle drawDataUnit(Graphics g, PamDataUnit pamDataUnit, GeneralProjector projectorInfo)
      Parameters:
      g - An awt Graphics object

      projectorInfo - 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

      public boolean canDraw(GeneralProjector generalProjector)
      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

      public String getHoverText(GeneralProjector generalProjector, PamDataUnit dataUnit, int iSide)
    • createKeyItem

      public PamKeyItem createKeyItem(GeneralProjector generalProjector, int keyType)
    • getOverlayDraw

      public PanelOverlayDraw 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.