BoundedQueue< T > Class Template Reference

A bounded, threadsafe FIFO processing queue. More...

#include <BoundedQueue.h++>

List of all members.

Public Member Functions

 BoundedQueue (uint_t capacity)
 Construct a new BoundedQueue.
virtual ~BoundedQueue ()
 Destructor.
void clear ()
 Clear the queue.
void reset ()
 Reset the queue.
void put (T item) throw (InterruptedException)
 Put an item in the queue.
void tryPut (T item, timespan_ms_t timeout=0) throw (TimeoutException, InterruptedException)
 Put an item in the queue.
take () throw (InterruptedException)
 Take an item from the queue.
tryTake (timespan_ms_t timeout=0) throw (TimeoutException, InterruptedException)
 Take an item from the queue.
uint_t getSize () const throw ()
 Get the size of the queue, that is, the number of items currently in the queue.
uint_t getCapacity () const throw ()
 Get the capacity of the queue, that is, the maximum number of items that the queue can hold.
void setCapacity (uint_t capacity) throw ()
 Change the capacity of the queue.
void interrupt () throw ()
 Interrupt the queue.
void shutdown () throw ()
 Shut down the queue.
bool isShutdown () const throw ()
 Test if the queue has been shut down.

Detailed Description

template<typename T>
class ccxx::BoundedQueue< T >

A bounded, threadsafe FIFO processing queue.

Items are enqueued by one or more producers and consumed by one or more consumers.

Author:
Mark Lindner

Constructor & Destructor Documentation

BoundedQueue ( uint_t  capacity  ) 

Construct a new BoundedQueue.

Parameters:
capacity The queue capacity: the maximum number of items that it can hold at any given time.
virtual ~BoundedQueue (  )  [virtual]

Destructor.


Member Function Documentation

void clear (  ) 

Clear the queue.

All items are removed from the queue.

uint_t getCapacity (  )  const throw () [inline]

Get the capacity of the queue, that is, the maximum number of items that the queue can hold.

uint_t getSize (  )  const throw ()

Get the size of the queue, that is, the number of items currently in the queue.

void interrupt (  )  throw ()

Interrupt the queue.

Unblocks any pending operations, causing the corresponding methods to throw an InterruptedException.

bool isShutdown (  )  const throw () [inline]

Test if the queue has been shut down.

void put ( item  )  throw (InterruptedException)

Put an item in the queue.

If the queue is full, the method blocks until space becomes available.

Parameters:
item The item to enqueue.
Exceptions:
InterruptedException If the queue was interrupted via a call to interrupt().
void reset (  ) 

Reset the queue.

Clears the queue, and clears the shutdown flag, if it was previously set via a call to shutdown(). This method must be called before a shut down queue can be reused.

void setCapacity ( uint_t  capacity  )  throw ()

Change the capacity of the queue.

Parameters:
capacity The new capacity. If the value is less than 1, the request is ignored. It is possible to set the capacity to be less than the number of elements currently in the queue; in this case it will not be possible to add more elements until the size of the queue drops below the new capacity.
void shutdown (  )  throw ()

Shut down the queue.

All subsequent operations will throw an InterruptedException.

T take (  )  throw (InterruptedException)

Take an item from the queue.

If the queue is empty, the method blocks until an item becomes available.

Returns:
The dequeued item.
Exceptions:
InterruptedException If the queue was interrupted via a call to interrupt().
void tryPut ( item,
timespan_ms_t  timeout = 0 
) throw (TimeoutException, InterruptedException)

Put an item in the queue.

If the queue is full, the method blocks until space becomes available or the timeout expires, whichever occurs first.

Parameters:
item The item to enqueue.
timeout The timeout, in milliseconds.
Exceptions:
InterruptedException If the queue was interrupted via a call to interrupt().
TimeoutException If the operation timed out.
T tryTake ( timespan_ms_t  timeout = 0  )  throw (TimeoutException, InterruptedException)

Take an item from the queue.

If the queue is empty, the method blocks until an item becomes available or the timeout expires, whichever occurs first.

Parameters:
timeout The timeout, in milliseconds.
Returns:
The dequeued item.
Exceptions:
InterruptedException If the queue was interrupted via a call to interrupt().
TimeoutException If the operation timed out.

The documentation for this class was generated from the following file:
Generated on Sat Nov 26 16:49:08 2011 for libcommonc++ by  doxygen 1.6.3