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
-
Constructor Summary
ConstructorDescriptionThreadedObserver
(PamObservable pamObservable, PamObserver singleThreadObserver) Make an intermediate observer of a PamObservable (i.e. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addData
(PamObservable o, PamDataUnit newDataUnit) Informs the PamObserver that new data have been added to the Observable classvoid
void
dumpBufferStatus
(String message, boolean sayEmpties) int
Get the number of objects in the queue.long
This 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.long
boolean
void
masterClockUpdate
(long milliSeconds, long sampleNumber) void
void
receiveSourceNotification
(int type, Object object) Receive a notification from the data source - typically a change in DAQ status.void
called when an Observable (PamDataBlock) is removed from the systemvoid
setMaxJitter
(long maxJitter) void
setSampleRate
(float sampleRate, boolean notify) New sample ratevoid
Sleep the writing thread by jittersleep (default 10ms)void
Terminate the threaded observer by setting the flag that causes the observing loop to drop out.void
updateData
(PamObservable observable, PamDataUnit pamDataUnit) Informs the PamObserver that existing data have been updatedlong
waitToEmpty
(long timeout) Wait for the queue to be empty.
-
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:
getObserverObject
in 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:
getObserverName
in interfacePamObserver
-
getRequiredDataHistory
- Specified by:
getRequiredDataHistory
in 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:
noteNewSettings
in 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:PamObserver
called when an Observable (PamDataBlock) is removed from the system- Specified by:
removeObservable
in interfacePamObserver
-
setSampleRate
public void setSampleRate(float sampleRate, boolean notify) Description copied from interface:PamObserver
New sample rate- Specified by:
setSampleRate
in interfacePamObserver
- Parameters:
notify
- Notify other PamObservers and PamObservables in the chain.
-
masterClockUpdate
public void masterClockUpdate(long milliSeconds, long sampleNumber) - Specified by:
masterClockUpdate
in interfacePamObserver
-
addData
Description copied from interface:PamObserver
Informs the PamObserver that new data have been added to the Observable class- Specified by:
addData
in interfacePamObserver
-
updateData
Description copied from interface:PamObserver
Informs the PamObserver that existing data have been updated- Specified by:
updateData
in interfacePamObserver
-
receiveSourceNotification
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 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.
-
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
-