Imp
[using it]
Interface Manipulation Package v4.0 (2008-06-25) a-projector ©copyright Author


imp.util
Class Sampler

java.lang.Object
  extended by imp.util.Event.AbstractSender<String>
      extended by imp.util.Sampler
All Implemented Interfaces:
Event.Sender<String>

public abstract class Sampler
extends Event.AbstractSender<String>

Defines the implementation of a periodic task.

The periodic task is defined by the method:
and one parameter the sampling-period.
The periodic task is controlled by the start/stop methods:
A Sampler can be interactively controlled by a SamplerInput


Nested Class Summary
static interface Sampler.Listener
          Defines a start/stop/pause/resume event listener.
 
Constructor Summary
Sampler()
          Constructs a sampler.
 
Method Summary
 int getSpareTime()
          Returns the spare-time between two samplings.
abstract  void iter()
          Periodically called when the sampler is started.
 void resume(boolean resume)
          Pauses/Resumes the iteration mechanism.
 void setSamplingPeriod(int samplingPeriod)
          Sets the sampling period.
 void start(int samplingPeriod)
          (Re)starts the sampling of the iter() method.
 void stop()
          Requires the sampling of the iter() method to stop.
 
Methods inherited from class imp.util.Event.AbstractSender
addListener, eventSent, removeListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sampler

public Sampler()
Constructs a sampler.

Method Detail

getSpareTime

public int getSpareTime()
Returns the spare-time between two samplings.

Returns:
The last spare-time between two samplings, in milliseconds:
  • If negative, it indicates that the task overruns.
  • It is equal to Integer.MIN_VALUE if no iteration has been completed.
  • It depends on both the task execution time and other thread execution times.
Throws:
RuntimeException - if a runtime exception has occurred during sampling.

iter

public abstract void iter()
Periodically called when the sampler is started.


resume

public void resume(boolean resume)
Pauses/Resumes the iteration mechanism.


setSamplingPeriod

public void setSamplingPeriod(int samplingPeriod)
Sets the sampling period.

Parameters:
samplingPeriod - A positive sampling-period in milliseconds.

start

public void start(int samplingPeriod)
(Re)starts the sampling of the iter() method.

Parameters:
samplingPeriod - [optional, default is 10ms or the previous sampling period] A positive sampling-period in milliseconds.

stop

public void stop()
Requires the sampling of the iter() method to stop.
The current iteration, if any, terminates before stopping.

Throws:
RuntimeException - if a runtime exception has occurred during sampling.