Class ADataCollector
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
RandomDataCollectorOffset
,RandomDataCollectorTimeStamped
Extend from this class and override the method collectData()
.
Set it up with code like:
Chart2D chart = new Chart2D(); ITrace2D trace = <initialization> chart.addTrace(trace); // Put the chart in your UI... // ... AbstractDataCollector collector = new <subtypename>(200,trace); collector.start();
Caution
Callingnew Thread(collector).start()
is disallowed and will
throw an exception as it would allow several Threads to run a collector. Use
the start()
instead.
Always connect the trace to a chart first before starting the collector for that trace! (deadlock prevention will raise an exception else).
- Version:
- $Revision: 1.11 $
- Author:
- Achim Westermann
-
Constructor Summary
ConstructorsConstructorDescriptionADataCollector
(ITrace2D trace, long latency) Creates an instance that will collect every latency ms a point and add it to the trace. -
Method Summary
Modifier and TypeMethodDescriptionabstract ITracePoint2D
Override this method.protected void
finalize()
long
Returns the interval in ms a point is collected.getTrace()
Returns the trace that is filled by this collector.boolean
Returns true if this datacollector currently is running.void
run()
void
setLatency
(long latency) Sets the interval for collecting points in ms.void
start()
Starts a Thread using thisRunnable
.void
stop()
Stops this Thread.
-
Constructor Details
-
ADataCollector
Creates an instance that will collect every latency ms a point and add it to the trace.- Parameters:
trace
- the trace to add collected points to.latency
- the interval in ms for collecting points.
-
-
Method Details
-
collectData
Override this method. It will be invoked in intervals of the configured latency time. The TracePoint2D that is returned will be added to the constructor given ITrace2D.
Keep your implementation fast. If the computations performed here take longer than the latency time that desired refresh rate will not be reached.
- Returns:
- the collected point.
-
finalize
-
getLatency
public long getLatency()Returns the interval in ms a point is collected.- Returns:
- the interval in ms a point is collected.
-
getTrace
Returns the trace that is filled by this collector.- Returns:
- Returns the trace.
-
isRunning
public boolean isRunning()Returns true if this datacollector currently is running.- Returns:
- true if this datacollector currently is running.
-
run
public void run() -
setLatency
public void setLatency(long latency) Sets the interval for collecting points in ms.- Parameters:
latency
- the interval for collecting points in ms.
-
start
public void start()Starts a Thread using this
Runnable
.This method will not start a new Thread if the current one is still running. If you prefer to use your own Threads (e.g. from a ThreadPool) prefer:
AbstractDataCollector collector = new <subtypename>(200,trace); new Thread(collector).start();
or more abstract (as proposed for Thread improvement reasons:AbstractDataCollector collector = new <subtypename>(200,trace); <getSomeThreadInstance>(collector).start();
-
stop
public void stop()Stops this Thread. Data collection will end when finished the current loop.Note that your application may
- run into deadlocks (blocking IO,...)
- face memory problems
-