PamguardMVC
Class ThreadedObserver

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

public class ThreadedObserver
extends java.lang.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

Nested Class Summary
(package private)  class ThreadedObserver.NewObserverThread
          New observer thread.
 
Field Summary
private  java.util.List<PamDataUnit> dataUnitList
           
private  boolean emptyRead
           
private  int jitterSleep
           
private  boolean killThread
           
private  int maxJitter
           
private  int maxQueSize
           
private  ThreadedObserver.NewObserverThread newObserverThread
           
private  java.lang.Thread observerThread
           
private  PamObservable pamObservable
           
private  PamObserver singleThreadObserver
           
 
Constructor Summary
ThreadedObserver(PamObservable pamObservable, PamObserver singleThreadObserver)
           
 
Method Summary
private  boolean canMultiThread()
          Not possible to multi thread when data come from a sound file, do don't try.
 int getInterThreadListSize()
           
 java.lang.String getObserverName()
           
 PamObserver getObserverObject()
           
 long getRequiredDataHistory(PamObservable o, java.lang.Object arg)
           
 PamObserver getSingleThreadObserver()
           
 boolean isEmptyRead()
           
 void masterClockUpdate(long milliSeconds, long sampleNumber)
           
 void noteNewSettings()
           
 void removeObservable(PamObservable o)
          called when an Observable (PamDataBlock) is removed from the system
 void setSampleRate(float sampleRate, boolean notify)
          New sample rate
 void update(PamObservable o, PamDataUnit arg)
          Informs the PamObserver that new data have been added to the Observable class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleThreadObserver

private PamObserver singleThreadObserver

pamObservable

private PamObservable pamObservable

dataUnitList

private java.util.List<PamDataUnit> dataUnitList

newObserverThread

private ThreadedObserver.NewObserverThread newObserverThread

observerThread

private java.lang.Thread observerThread

killThread

private volatile boolean killThread

emptyRead

private volatile boolean emptyRead

maxQueSize

private int maxQueSize

maxJitter

private int maxJitter

jitterSleep

private int jitterSleep
Constructor Detail

ThreadedObserver

public ThreadedObserver(PamObservable pamObservable,
                        PamObserver singleThreadObserver)
Method Detail

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.

getSingleThreadObserver

public PamObserver getSingleThreadObserver()

getObserverName

public java.lang.String getObserverName()
Specified by:
getObserverName in interface PamObserver

getRequiredDataHistory

public long getRequiredDataHistory(PamObservable o,
                                   java.lang.Object arg)
Specified by:
getRequiredDataHistory in interface PamObserver
Parameters:
o - PamObservable class requiring the data
arg - optional argument from PamObservable
Returns:
time in milliseconds requried by data held in PamObservable

getInterThreadListSize

public int getInterThreadListSize()

noteNewSettings

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

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
notify - Notify other PamObservers and PamObservables in the chain.

masterClockUpdate

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

update

public void update(PamObservable o,
                   PamDataUnit arg)
Description copied from interface: PamObserver
Informs the PamObserver that new data have been added to the Observable class

Specified by:
update in interface PamObserver
Parameters:
o - Reference to the Observable (a PamDataBlock)
arg - Reference to the new PamDataUnit

canMultiThread

private boolean canMultiThread()
Not possible to multi thread when data come from a sound file, do don't try. Can leave the objects wrapped up in the decorator but just pass the data on, rather than multi threading it.

Returns:

isEmptyRead

public boolean isEmptyRead()