CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes

stor::ExpirableQueue< T, Policy > Class Template Reference

#include <ExpirableQueue.h>

List of all members.

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.8
Date:
2011/03/07 15:31:31

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.

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]

Clear the queue. Return the number of elements removed.

Definition at line 180 of file ExpirableQueue.h.

  {
    return events_.clear();
  }  
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.

References hitfit::clear().

  {
    if (stalenessTime_ < now)
    {
      clearedEvents = clear();
      return true;
    }
    else
    {
      clearedEvents = 0;
      return false;
    }
  }
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().

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.

  {
    return events_.empty();
  }
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.

  {
    if ( stale(now) )
    {
      events_.addExternallyDroppedEvents(1);
      return 1;
    }
    return events_.enqNowait(event);
  }  
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.

  {
    return events_.full();
  }
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 lumiQTWidget::t.

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.

  {
    return events_.size();
  }
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.

  {
    return (stalenessTime_ < now);
  }
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.

  {
    return 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.