info.monitorenter.gui.chart.io
Class ADataCollector

java.lang.Object
  extended by info.monitorenter.gui.chart.io.ADataCollector
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
RandomDataCollectorOffset, RandomDataCollectorTimeStamped

public abstract class ADataCollector
extends Object
implements Runnable

A simple Runnable that contiuously 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 = <initializatioin>
       chart.addTrace(trace);
       // Put the chart in your UI...
       // ...
       AbstractDataCollector collector = new <subtypename>(200,trace);
       collector.start();
 

Caution

Calling new Thread(collector).start() is disallowed and will throw an exception as it would allow several Threads to run a collector. Use the start() instead.

rabbel rabbel.

Version:
$Revision: 1.3 $
Author:
Achim Westermann

Constructor Summary
ADataCollector(ITrace2D trace, long latency)
          Creates an instance that will collect every latency ms a point and add it to the trace.
 
Method Summary
abstract  TracePoint2D 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 this Runnable.
 void stop()
          Stops this Thread.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 TracePoint2D 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 colleted point.

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
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 interface 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

  1. run into deadlocks (blocking IO,...)
  2. face memory problems
if the AbstractDataCollector implementation fetches and removes data from 1) a limited buffer or a 2) unlimited buffer. This behaviour will of course not appear if the data is not read from a queue where it has to be removed from.



Copyright © 2001 - 2007 LGPL, All Rights Footloose.