CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
stor::ExpirableQueue< T, Policy > Class Template Reference

#include <ExpirableQueue.h>

Public Types

typedef Policy PolicyType
 
typedef ConcurrentQueue< T,
Policy >::SizeType 
SizeType
 
typedef Policy::ValueType ValueType
 

Public Member Functions

SizeType clear ()
 
bool clearIfStale (const utils::TimePoint_t &, SizeType &clearedEvents)
 
bool deqNowait (ValueType &)
 
bool empty () const
 
SizeType enqNowait (T const &, const utils::TimePoint_t &now=utils::getCurrentTime())
 
 ExpirableQueue (SizeType maxsize=std::numeric_limits< SizeType >::max(), utils::Duration_t stalenessInterval=boost::posix_time::seconds(120), utils::TimePoint_t now=utils::getCurrentTime())
 
bool full () const
 
void setStalenessInterval (const utils::Duration_t &)
 
SizeType size () const
 
bool stale (const utils::TimePoint_t &) const
 
utils::Duration_t stalenessInterval () const
 

Private Types

typedef ConcurrentQueue< T,
Policy > 
queue_t
 

Private Member Functions

 ExpirableQueue (ExpirableQueue &)
 
ExpirableQueueoperator= (ExpirableQueue &)
 

Private Attributes

queue_t events_
 
utils::Duration_t stalenessInterval_
 
utils::TimePoint_t stalenessTime_
 

Detailed Description

template<class T, class Policy>
class stor::ExpirableQueue< T, Policy >

Class template ExpirableQueue encapsulates a Queue (held through a shared_ptr, for inexpensive copying) and timing information. It keeps track of when the most recent called to deq was made.

Author:
mommsen
Revision:
1.7.4.1
Date:
2011/03/07 11:33:04

Definition at line 27 of file ExpirableQueue.h.

Member Typedef Documentation

template<class T, class Policy>
typedef Policy stor::ExpirableQueue< T, Policy >::PolicyType

Definition at line 30 of file ExpirableQueue.h.

template<class T, class Policy>
typedef ConcurrentQueue<T, Policy> stor::ExpirableQueue< T, Policy >::queue_t
private

Definition at line 111 of file ExpirableQueue.h.

template<class T, class Policy>
typedef ConcurrentQueue<T, Policy>::SizeType stor::ExpirableQueue< T, Policy >::SizeType

Definition at line 31 of file ExpirableQueue.h.

template<class T, class Policy>
typedef Policy::ValueType stor::ExpirableQueue< T, Policy >::ValueType

Definition at line 32 of file ExpirableQueue.h.

Constructor & Destructor Documentation

template<class T , class Policy >
stor::ExpirableQueue< T, Policy >::ExpirableQueue ( SizeType  maxsize = std::numeric_limits<SizeType>::max(),
utils::Duration_t  stalenessInterval = boost::posix_time::seconds(120),
utils::TimePoint_t  now = utils::getCurrentTime() 
)
explicit

Create an ExpirableQueue with the given maximum size and given "time to stale", specified in seconds.

Definition at line 130 of file ExpirableQueue.h.

134  :
135  events_(maxsize),
138  {
139  }
utils::Duration_t stalenessInterval() const
utils::TimePoint_t stalenessTime_
utils::Duration_t stalenessInterval_
template<class T, class Policy>
stor::ExpirableQueue< T, Policy >::ExpirableQueue ( ExpirableQueue< T, Policy > &  )
private

Member Function Documentation

template<class T , class Policy >
ExpirableQueue< T, Policy >::SizeType stor::ExpirableQueue< T, Policy >::clear ( void  )
inline
template<class T , class Policy >
bool stor::ExpirableQueue< T, Policy >::clearIfStale ( const utils::TimePoint_t now,
SizeType clearedEvents 
)
inline

Return true if the queue is stale, and false if it is not. The queue is stale if its stalenessTime is before the given time. If the queue is stale, we also clear it and return the number of cleared events.

Definition at line 221 of file ExpirableQueue.h.

225  {
226  if (stalenessTime_ < now)
227  {
228  clearedEvents = clear();
229  return true;
230  }
231  else
232  {
233  clearedEvents = 0;
234  return false;
235  }
236  }
utils::TimePoint_t stalenessTime_
template<class T , class Policy >
bool stor::ExpirableQueue< T, Policy >::deqNowait ( ValueType event)

Try to remove an event from the queue, without blocking. If an event is available, return 'true' and set the output argument 'event'. If no event is available, return 'false'. In either case, update the staleness time to reflect this attempt to get an event.

Definition at line 143 of file ExpirableQueue.h.

References stor::utils::getCurrentTime().

144  {
146  return events_.deqNowait(event);
147  }
TimePoint_t getCurrentTime()
Definition: Utils.h:158
bool deqNowait(ValueType &)
utils::TimePoint_t stalenessTime_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
utils::Duration_t stalenessInterval_
template<class T , class Policy >
bool stor::ExpirableQueue< T, Policy >::empty ( void  ) const
inline

Return true if the queue is empty, and false otherwise.

Definition at line 188 of file ExpirableQueue.h.

Referenced by python.Vispa.Gui.VispaWidget.TextField::setAutosizeFont(), and python.Vispa.Gui.VispaWidget.TextField::setAutotruncate().

189  {
190  return events_.empty();
191  }
template<class T , class Policy >
ExpirableQueue< T, Policy >::SizeType stor::ExpirableQueue< T, Policy >::enqNowait ( T const &  event,
const utils::TimePoint_t now = utils::getCurrentTime() 
)

Put an event onto the queue, if the queue is not stale at the given time. It respects the Policy of this queue that controls what is done in the case of a full queue. This does not affect the staleness time of this queue. Returns the number of dropped events.

Definition at line 151 of file ExpirableQueue.h.

152  {
153  if ( stale(now) )
154  {
156  return 1;
157  }
158  return events_.enqNowait(event);
159  }
bool stale(const utils::TimePoint_t &) const
EnqPolicy::ReturnType enqNowait(T const &item)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void addExternallyDroppedEvents(SizeType)
template<class T , class Policy >
bool stor::ExpirableQueue< T, Policy >::full ( ) const
inline

Return true if the queue is full, and false otherwise.

Definition at line 204 of file ExpirableQueue.h.

205  {
206  return events_.full();
207  }
template<class T, class Policy>
ExpirableQueue& stor::ExpirableQueue< T, Policy >::operator= ( ExpirableQueue< T, Policy > &  )
private
template<class T , class Policy >
void stor::ExpirableQueue< T, Policy >::setStalenessInterval ( const utils::Duration_t t)
inline

Set the staleness interval.

Definition at line 164 of file ExpirableQueue.h.

References matplotRender::t.

165  {
167  }
utils::Duration_t stalenessInterval_
template<class T , class Policy >
ExpirableQueue< T, Policy >::SizeType stor::ExpirableQueue< T, Policy >::size ( void  ) const
inline

Get number of entries in queue

Definition at line 196 of file ExpirableQueue.h.

197  {
198  return events_.size();
199  }
SizeType size() const
template<class T , class Policy >
bool stor::ExpirableQueue< T, Policy >::stale ( const utils::TimePoint_t now) const
inline

Return true if the queue is stale at the given time, and false otherwise.

Definition at line 212 of file ExpirableQueue.h.

213  {
214  return (stalenessTime_ < now);
215  }
utils::TimePoint_t stalenessTime_
template<class T , class Policy >
utils::Duration_t stor::ExpirableQueue< T, Policy >::stalenessInterval ( ) const
inline

Get the staleness interval.

Definition at line 172 of file ExpirableQueue.h.

173  {
174  return stalenessInterval_;
175  }
utils::Duration_t stalenessInterval_

Member Data Documentation

template<class T, class Policy>
queue_t stor::ExpirableQueue< T, Policy >::events_
private

Definition at line 113 of file ExpirableQueue.h.

template<class T, class Policy>
utils::Duration_t stor::ExpirableQueue< T, Policy >::stalenessInterval_
private

Time in seconds it takes for this queue to become stale.

Definition at line 115 of file ExpirableQueue.h.

template<class T, class Policy>
utils::TimePoint_t stor::ExpirableQueue< T, Policy >::stalenessTime_
private

Point in time at which this queue will become stale.

Definition at line 117 of file ExpirableQueue.h.