Package PamguardMVC

Class ThreadedObserver

java.lang.Object
PamguardMVC.ThreadedObserver
All Implemented Interfaces:
PamObserver

public class ThreadedObserver extends Object implements PamObserver
This is a decorator class for PamObservers which intercepts any data being sent to that observer and puts the data into a list which will then be re-read in a separate thread, rather than sending if for direct execution.

There is a bit of jiggledy piggledy to get the data history times right since they may need to be extended slightly to allow for data that are not yet used.

Author:
Doug Gillespie
  • Constructor Details

    • ThreadedObserver

      public ThreadedObserver(PamObservable pamObservable, PamObserver singleThreadObserver)
      Make an intermediate observer of a PamObservable (i.e. datablock) which will queue the data for analysis in a different thread.
      Parameters:
      pamObservable -
      singleThreadObserver -
  • Method Details

    • getObserverObject

      public PamObserver getObserverObject()
      Specified by:
      getObserverObject in interface PamObserver
      Returns:
      the actual observer. In most cases concrete classes will just return 'this' in response. The exception is the Threaded observer, which will return the single thread observer.
    • getObserverName

      public String getObserverName()
      Specified by:
      getObserverName in interface PamObserver
    • getRequiredDataHistory

      public long getRequiredDataHistory(PamObservable o, Object arg)
      Specified by:
      getRequiredDataHistory in interface PamObserver
      Parameters:
      arg - optional argument from PamObservable
      Returns:
      time in milliseconds required by data held in PamObservable
    • getInterThreadListSize

      public int getInterThreadListSize()
      Get the number of objects in the queue.
      Returns:
      number of objests
    • noteNewSettings

      public void noteNewSettings()
      Specified by:
      noteNewSettings in interface PamObserver
    • terminateThread

      public void terminateThread()
      Terminate the threaded observer by setting the flag that causes the observing loop to drop out.
    • removeObservable

      public void removeObservable(PamObservable o)
      Description copied from interface: PamObserver
      called when an Observable (PamDataBlock) is removed from the system
      Specified by:
      removeObservable in interface PamObserver
    • setSampleRate

      public void setSampleRate(float sampleRate, boolean notify)
      Description copied from interface: PamObserver
      New sample rate
      Specified by:
      setSampleRate in interface PamObserver
      Parameters:
      notify - Notify other PamObservers and PamObservables in the chain.
    • masterClockUpdate

      public void masterClockUpdate(long milliSeconds, long sampleNumber)
      Specified by:
      masterClockUpdate in interface PamObserver
    • addData

      public void addData(PamObservable o, PamDataUnit newDataUnit)
      Description copied from interface: PamObserver
      Informs the PamObserver that new data have been added to the Observable class
      Specified by:
      addData in interface PamObserver
    • updateData

      public void updateData(PamObservable observable, PamDataUnit pamDataUnit)
      Description copied from interface: PamObserver
      Informs the PamObserver that existing data have been updated
      Specified by:
      updateData in interface PamObserver
    • receiveSourceNotification

      public void receiveSourceNotification(int type, Object object)
      Description copied from interface: PamObserver
      Receive a notification from the data source - typically a change in DAQ status. See the constants listed in AcquisitionProcess for potential change types.
      Specified by:
      receiveSourceNotification in interface PamObserver
      Parameters:
      type - the type of change
      object - generic object added here so that we can include anything in the future
    • getQueueLimits

      public long[] getQueueLimits()
      Get the millisecond times of the first and last items in the queue.
      Returns:
      first and last times, or null if the queue is empty.
    • waitToEmpty

      public long waitToEmpty(long timeout)
      Wait for the queue to be empty. This REALLY must not get called from the NewObserverThread or you'll get a thread lock, so don't
      Parameters:
      timeout - maximum time to wait for thread.
      Returns:
      +ve integer number of millis if it ended normally, negative for an error code. -1 for a timeout or -2 for it calling within it's own observer thread.
    • sleepWriter

      public void sleepWriter()
      Sleep the writing thread by jittersleep (default 10ms)
    • isEmptyRead

      public boolean isEmptyRead()
      Returns:
    • getMaxJitter

      public long getMaxJitter()
      This is the maximum amount of data in milliseconds that can sit in the queue. Normally it's about a second.
      Returns:
      the maxJitter
    • setMaxJitter

      public void setMaxJitter(long maxJitter)
      Parameters:
      maxJitter - the maxJitter to set
    • clearEverything

      public void clearEverything()
    • dumpBufferStatus

      public void dumpBufferStatus(String message, boolean sayEmpties)