Package coilmq :: Package store :: Module dbm :: Class DbmQueue
[frames] | no frames]

Class DbmQueue

object --+    
         |    
QueueStore --+
             |
            DbmQueue

A QueueStore implementation that stores messages and queue information in DBM-style database.

Several database files will be used to support this functionality: metadata about the queues will be stored in its own database and each queue will also have its own database file.

This classes uses a threading.RLock to guard access to the memory store, since it appears that at least some of the underlying implementations that anydbm uses are not thread-safe

Due to some impedence mismatch between the types of data we need to store in queues (specifically lists) and the types of data that are best stored in DBM databases (specifically dicts), this class uses the `shelve` module to abstract away some of the ugliness. The consequence of this is that we only persist objects periodically to the datastore, for performance reasons. How periodic is determined by the `checkpoint_operations` and `checkpoint_timeout` instance variables (and params to __init__).

Instance Methods
 
__init__(self, data_dir, checkpoint_operations=100, checkpoint_timeout=30)
A base constructor that sets up logging and the lock used by synchronized decorator.
 
enqueue(self, destination, frame)
Store message (frame) for specified destinationination.
stompclient.frame.Frame
dequeue(self, destination)
Removes and returns an item from the queue (or None if no items in queue).
bool
has_frames(self, destination)
Whether specified queue has any frames.
int
size(self, destination)
Size of the queue for specified destination.
 
close(self)
Closes the databases, freeing any resources (and flushing any unsaved changes to disk).
set
destinations(self)
Provides a list of destinations (queue "addresses") available.

Inherited from QueueStore: frames, requeue

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables

Inherited from QueueStore: __metaclass__

Instance Variables
int checkpoint_operations
Number of operations between syncs.
float checkpoint_timeout
Max time (in seconds) that can elapse between sync of cache.
str data_dir
The directory where DBM files will be stored.
shelve.Shelf frame_store
A Shelf (DBM) database that contains frame contents indexed by message id.
  queue_metadata
A Shelf (DBM) database that tracks stats & delivered message ids for all the queues.

Inherited from QueueStore: log

Properties

Inherited from object: __class__

Method Details

__init__(self, data_dir, checkpoint_operations=100, checkpoint_timeout=30)
(Constructor)

 

A base constructor that sets up logging and the lock used by synchronized decorator.

If you extend this class, you should either call this method or at minimum make sure these values get set.

Parameters:
  • data_dir - The directory where DBM files will be stored.
  • data_dir - str
  • checkpoint_operations (int) - Number of operations between syncs.
  • checkpoint_timeout (float) - Max time (in seconds) that can elapse between sync of cache.
Overrides: object.__init__

enqueue(self, destination, frame)

 

Store message (frame) for specified destinationination.

Parameters:
  • destination (str) - The destinationination queue name for this message (frame).
  • frame (stompclient.frame.Frame) - The message (frame) to send to specified destinationination.
Decorators:
  • @synchronized
Overrides: QueueStore.enqueue

dequeue(self, destination)

 

Removes and returns an item from the queue (or None if no items in queue).

Parameters:
  • destination (str) - The queue name (destinationination).
Returns: stompclient.frame.Frame
The first frame in the specified queue, or None if there are none.
Decorators:
  • @synchronized
Overrides: QueueStore.dequeue

has_frames(self, destination)

 

Whether specified queue has any frames.

Parameters:
  • destination (str) - The queue name (destinationination).
Returns: bool
Whether there are any frames in the specified queue.
Decorators:
  • @synchronized
Overrides: QueueStore.has_frames

size(self, destination)

 

Size of the queue for specified destination.

Parameters:
  • destination (str) - The queue destination (e.g. /queue/foo)
Returns: int
The number of frames in specified queue.
Decorators:
  • @synchronized
Overrides: QueueStore.size

close(self)

 

Closes the databases, freeing any resources (and flushing any unsaved changes to disk).

Decorators:
  • @synchronized
Overrides: QueueStore.close

destinations(self)

 

Provides a list of destinations (queue "addresses") available.

Returns: set
A list of the detinations available.
Decorators:
  • @synchronized
Overrides: QueueStore.destinations