Package PamguardMVC
Class ThreadedObserver
java.lang.Object
PamguardMVC.ThreadedObserver
- All Implemented Interfaces:
 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
 
- 
Field Summary
Fields - 
Constructor Summary
ConstructorsConstructorDescriptionThreadedObserver(PamObservable pamObservable, PamObserver singleThreadObserver) Make an intermediate observer of a PamObservable (i.e. - 
Method Summary
Modifier and TypeMethodDescriptionvoidaddData(PamObservable o, PamDataUnit newDataUnit) Informs the PamObserver that new data have been added to the Observable classvoidvoiddumpBufferStatus(String message, boolean sayEmpties) intGet the number of objects in the queue.longThis is the maximum amount of data in milliseconds that can sit in the queue.long[]Get the millisecond times of the first and last items in the queue.longbooleanvoidmasterClockUpdate(long milliSeconds, long sampleNumber) voidvoidreceiveSourceNotification(int type, Object object) Receive a notification from the data source - typically a change in DAQ status.voidcalled when an Observable (PamDataBlock) is removed from the systemvoidsetMaxJitter(long maxJitter) voidsetSampleRate(float sampleRate, boolean notify) New sample ratevoidSleep the writing thread by jittersleep (default 10ms)voidTerminate the threaded observer by setting the flag that causes the observing loop to drop out.voidupdateData(PamObservable observable, PamDataUnit pamDataUnit) Informs the PamObserver that existing data have been updatedprotected voidwaitForQueueToBeReady(ObservedObject theObject) Check to see if the queue is ready to accept a new Object.longwaitToEmpty(long timeout) Wait for the queue to be empty. 
- 
Field Details
- 
MODULEEXCEPTIONLINE
 
 - 
 - 
Constructor Details
- 
ThreadedObserver
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
- Specified by:
 getObserverObjectin interfacePamObserver- 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
- Specified by:
 getObserverNamein interfacePamObserver
 - 
getRequiredDataHistory
- Specified by:
 getRequiredDataHistoryin interfacePamObserver- 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:
 noteNewSettingsin interfacePamObserver
 - 
terminateThread
public void terminateThread()Terminate the threaded observer by setting the flag that causes the observing loop to drop out. - 
removeObservable
Description copied from interface:PamObservercalled when an Observable (PamDataBlock) is removed from the system- Specified by:
 removeObservablein interfacePamObserver
 - 
setSampleRate
public void setSampleRate(float sampleRate, boolean notify) Description copied from interface:PamObserverNew sample rate- Specified by:
 setSampleRatein interfacePamObserver- Parameters:
 sampleRate-notify- Notify other PamObservers and PamObservables in the chain.
 - 
masterClockUpdate
public void masterClockUpdate(long milliSeconds, long sampleNumber) - Specified by:
 masterClockUpdatein interfacePamObserver
 - 
addData
Description copied from interface:PamObserverInforms the PamObserver that new data have been added to the Observable class- Specified by:
 addDatain interfacePamObserver
 - 
updateData
Description copied from interface:PamObserverInforms the PamObserver that existing data have been updated- Specified by:
 updateDatain interfacePamObserver
 - 
receiveSourceNotification
Description copied from interface:PamObserverReceive a notification from the data source - typically a change in DAQ status. See the constants listed in AcquisitionProcess for potential change types.- Specified by:
 receiveSourceNotificationin interfacePamObserver- Parameters:
 type- the type of changeobject- 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.
 
 - 
waitForQueueToBeReady
Check to see if the queue is ready to accept a new Object. If the queue is currently full, then wait inside this method until the queue has emptied out.Note that the object will be added to the queue when this method returns, so all delays must be done in here.
- Parameters:
 theObject- The Object waiting to be added to the queue
 - 
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
 
 -