Class ADataCollector
- java.lang.Object
-
- info.monitorenter.gui.chart.io.ADataCollector
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
RandomDataCollectorOffset
,RandomDataCollectorTimeStamped
public abstract class ADataCollector extends java.lang.Object implements java.lang.Runnable
A simple Runnable that continuously collects data every latency time period and adds it to the internal ITrace2D instance.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 thestart()
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
Constructors Constructor Description ADataCollector(ITrace2D trace, long latency)
Creates an instance that will collect every latency ms a point and add it to the trace.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ITracePoint2D
collectData()
Override this method.protected void
finalize()
long
getLatency()
Returns the interval in ms a point is collected.ITrace2D
getTrace()
Returns the trace that is filled by this collector.boolean
isRunning()
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 Detail
-
ADataCollector
public ADataCollector(ITrace2D trace, long latency)
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 Detail
-
collectData
public abstract ITracePoint2D 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
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
- See Also:
Object.finalize()
-
getLatency
public long getLatency()
Returns the interval in ms a point is collected.- Returns:
- the interval in ms a point is collected.
-
getTrace
public ITrace2D 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()
- Specified by:
run
in interfacejava.lang.Runnable
- See Also:
Runnable.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
-
-