#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 &) | |
ExpirableQueue & | operator= (ExpirableQueue &) |
Private Attributes | |
queue_t | events_ |
utils::Duration_t | stalenessInterval_ |
utils::TimePoint_t | stalenessTime_ |
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.
Definition at line 27 of file ExpirableQueue.h.
typedef Policy stor::ExpirableQueue< T, Policy >::PolicyType |
Definition at line 30 of file ExpirableQueue.h.
typedef ConcurrentQueue<T, Policy> stor::ExpirableQueue< T, Policy >::queue_t [private] |
Definition at line 111 of file ExpirableQueue.h.
typedef ConcurrentQueue<T, Policy>::SizeType stor::ExpirableQueue< T, Policy >::SizeType |
Definition at line 31 of file ExpirableQueue.h.
typedef Policy::ValueType stor::ExpirableQueue< T, Policy >::ValueType |
Definition at line 32 of file ExpirableQueue.h.
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.
: events_(maxsize), stalenessInterval_(stalenessInterval), stalenessTime_(now+stalenessInterval_) { }
stor::ExpirableQueue< T, Policy >::ExpirableQueue | ( | ExpirableQueue< T, Policy > & | ) | [private] |
ExpirableQueue< T, Policy >::SizeType stor::ExpirableQueue< T, Policy >::clear | ( | void | ) | [inline] |
Clear the queue. Return the number of elements removed.
Definition at line 180 of file ExpirableQueue.h.
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.
{ if (stalenessTime_ < now) { clearedEvents = clear(); return true; } else { clearedEvents = 0; return false; } }
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().
{ stalenessTime_ = utils::getCurrentTime() + stalenessInterval_; return events_.deqNowait(event); }
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.
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.
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.
ExpirableQueue& stor::ExpirableQueue< T, Policy >::operator= | ( | ExpirableQueue< T, Policy > & | ) | [private] |
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.
{ stalenessInterval_ = t; }
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.
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.
{ return (stalenessTime_ < now); }
utils::Duration_t stor::ExpirableQueue< T, Policy >::stalenessInterval | ( | ) | const [inline] |
Get the staleness interval.
Definition at line 172 of file ExpirableQueue.h.
{ return stalenessInterval_; }
queue_t stor::ExpirableQueue< T, Policy >::events_ [private] |
Definition at line 113 of file ExpirableQueue.h.
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.
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.