The Micro C++ Library
micxx::Throttle Class Reference

A Throttle could either be used to measure or to limit the througput per second. More...

#include <micxx.hxx>

List of all members.

Public Member Functions

 Throttle (unsigned long maximumThroughput=0)
 Create a Throttle.
virtual ~Throttle ()
virtual unsigned long getMaxThroughtput () const
 The maximum allowed throughtput, or 0 if not limit has been set.
virtual unsigned long getCurCount () const
 The total number of next() calls during the last time interval (the last running second)
virtual double getCurThroughput () const
 The current (predicted) throughput (estimation based on getCurCount()).
virtual double getCurMaxThroughtput () const
 The current maximum throughput that has been measured.
virtual traits::ProgressMonitorgetProgressMonitor ()
 The stored traits::ProgressMonitor reference.
virtual unsigned long long getStartMillis () const
 The milliseconds returned by System::getMillis() when next() was called for the first time.
virtual unsigned long long getTotalCount () const
 The total number of next() calls processed so far.
virtual bool next ()
 Called to issue or measure the next event of a sequence that is controlled or measured by this Throttle.
virtual void setMaxThroughtput (unsigned long value)
 Set the maximum allowed throughput per second.
virtual void setProgressMonitor (traits::ProgressMonitor *progressMonitor)
 Set a reference to a traits::ProgressMonitor to report the current throughput to.

Detailed Description

A Throttle could either be used to measure or to limit the througput per second.

In case the extrapolation of the current throughtput is to high, calls to micxx::Throttle::next() get temporarily suspended, so that the overall throughput per second will stay below the configured maximum throughput.

 micxx::Throttle throttle(1000);
 while (true)
 {
     throttle.next();
     // do something no more that 1000 times per second...
 }
Author:
Norbert Klose
Date:
December, 2006

Constructor & Destructor Documentation

micxx::Throttle::Throttle ( unsigned long  maximumThroughput = 0)

Create a Throttle.

Parameters:
maximumThroughputIf not 0 this value will act as an upper bound to the current allowed throughput (throttle mode). Any call to next() which will result in a current (predicted) throughput that exceeds this upper bound will be suspended, so that the resulting (predicted) throughput will be below value.
A value of 0 simply means an unlimited upper bound (measure mode).
See also:
setMaxThroughtput(unsigned long)
virtual micxx::Throttle::~Throttle ( ) [virtual]

Member Function Documentation

virtual unsigned long micxx::Throttle::getCurCount ( ) const [virtual]

The total number of next() calls during the last time interval (the last running second)

virtual double micxx::Throttle::getCurMaxThroughtput ( ) const [virtual]

The current maximum throughput that has been measured.

virtual double micxx::Throttle::getCurThroughput ( ) const [virtual]

The current (predicted) throughput (estimation based on getCurCount()).

virtual unsigned long micxx::Throttle::getMaxThroughtput ( ) const [virtual]

The maximum allowed throughtput, or 0 if not limit has been set.

virtual traits::ProgressMonitor* micxx::Throttle::getProgressMonitor ( ) [virtual]

The stored traits::ProgressMonitor reference.

Returns:
The stored traits::ProgressMonitor reference or 0, if no ProgressMonitor has been set.
virtual unsigned long long micxx::Throttle::getStartMillis ( ) const [virtual]

The milliseconds returned by System::getMillis() when next() was called for the first time.

virtual unsigned long long micxx::Throttle::getTotalCount ( ) const [virtual]

The total number of next() calls processed so far.

virtual bool micxx::Throttle::next ( ) [virtual]

Called to issue or measure the next event of a sequence that is controlled or measured by this Throttle.

All events that are issued per second together represent the current throughput.

If the throughput is limited (throttle mode), next() will suspend the calling thread, so that the current (predicted) throughput does not exceed the maximum allowed throughput. Otherwise, the current call is just measured and the calling thread is not suspended (measure mode).

If a traits::ProgressMonitor has been set by setProgressMonitor(traits::ProgressMonitor*) next() uses this traits::ProgressMonitor to report the current throughput.

Returns:
!(traits::ProgressMonitor::isCancelled()), if a traits::ProgressMonitor has been set, or
true otherwise.
virtual void micxx::Throttle::setMaxThroughtput ( unsigned long  value) [virtual]

Set the maximum allowed throughput per second.

Parameters:
valueIf not 0 this value will act as an upper bound to the current allowed throughput (throttle mode). Any call to next() which will result in a current (predicted) throughput that exceeds this upper bound will be suspended, so that the resulting (predicted) throughput will be below value.
A value of 0 simply means an unlimited upper bound (measure mode).

If a traits::ProgressMonitor has been set by setProgressMonitor(traits::ProgressMonitor*) this value is propagated to this traits::ProgressMonitor by calling traits::ProgressMonitor::setMaxValue(double).

virtual void micxx::Throttle::setProgressMonitor ( traits::ProgressMonitor progressMonitor) [virtual]

Set a reference to a traits::ProgressMonitor to report the current throughput to.

Parameters:
progressMonitorThe reference to a traits::ProgressMonitor or 0 if an existing reference should be removed. The reference must be valid as long as the Throttle is used and won't be deleted by this Throttle.

The documentation for this class was generated from the following file: