Class ADataCollector

java.lang.Object
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 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

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.

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 Details

    • 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 Details

    • 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 Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
      See Also:
    • 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:
    • 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.