ACE_Activation_Queue Class Reference

Reifies a method into a request. Subclasses typically represent necessary state and behavior. More...

#include <Activation_Queue.h>

Collaboration diagram for ACE_Activation_Queue:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Activation_Queue (ACE_Message_Queue< ACE_SYNCH > *new_queue=0, ACE_Allocator *alloc=0, ACE_Allocator *db_alloc=0)
 Constructor.

virtual ~ACE_Activation_Queue (void)
 Destructor.

ACE_Method_Requestdequeue (ACE_Time_Value *tv=0)
 Dequeue the next available ACE_Method_Request.

int enqueue (ACE_Method_Request *new_method_request, ACE_Time_Value *tv=0)
 Enqueue the ACE_Method_Request in priority order.

size_t method_count (void) const
 Get the current number of method objects in the queue.

int is_empty (void) const
 Returns 1 if the queue is empty, 0 otherwise.

int is_full (void) const
 Returns 1 if the queue is full, 0 otherwise.

void dump (void) const
 Dump the state of an request.

ACE_Message_Queue< ACE_SYNCH > * queue (void) const
 Get a pointer to the underlying queue.

void queue (ACE_Message_Queue< ACE_SYNCH > *q)
 Set the pointer to the underlying queue.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Protected Attributes

ACE_Message_Queue< ACE_SYNCH > * queue_
 Stores the Method_Requests.

int delete_queue_
 Keeps track of whether we need to delete the queue.


Private Member Functions

 ACE_Activation_Queue (const ACE_Activation_Queue &)
void operator= (const ACE_Activation_Queue &)

Private Attributes

ACE_Allocatorallocator_
 Allocation strategy of the queue.

ACE_Allocatordata_block_allocator_
 Allocation strategy of the message blocks.


Detailed Description

Reifies a method into a request. Subclasses typically represent necessary state and behavior.

Maintains a priority-ordered queue of ACE_Method_Request objects. A scheduler class (often derived from ACE_Task) subsequently removes each method request and invokes its call() method.

This class is discussed in depth in the Active Object chapter of POSA2. In that book, it is referred to as an Activation List.

See also:
ACE_Method_Request

Definition at line 50 of file Activation_Queue.h.


Constructor & Destructor Documentation

ACE_Activation_Queue::ACE_Activation_Queue ACE_Message_Queue< ACE_SYNCH > *  new_queue = 0,
ACE_Allocator alloc = 0,
ACE_Allocator db_alloc = 0
 

Constructor.

Initializes a new activation queue.

Parameters:
new_queue The activation queue uses an ACE_Message_Queue to queue and order the method requests. If this argument is 0, a new ACE_Message_Queue is created for this object's use and will be deleted when this object is destroyed. If a non-zero pointer is supplied, the passed object will be used and will not be deleted when this object is destroyed. If an ACE_Task is being created to act as the scheduler, for instance, its ACE_Message_Queue pointer can be passed to this object.
alloc Optional, the allocator to use when allocating ACE_Message_Block instances that wrap the method requests queued to this activation queue. Defaults to ACE_Allocator::instance().
db_alloc Optional, the allocator to use when allocating data blocks for the ACE_Message_Block instances that wrap the method requests queued to this activation queue. Defaults to ACE_Allocator::instance().

Definition at line 35 of file Activation_Queue.cpp.

References ACE_NEW, allocator_, delete_queue_, ACE_Allocator::instance(), and queue_.

00038   : delete_queue_ (0)
00039   , allocator_(alloc)
00040   , data_block_allocator_(db_alloc)
00041 {
00042   if (this->allocator_ == 0)
00043     this->allocator_ = ACE_Allocator::instance ();
00044 
00045   if (new_queue)
00046     this->queue_ = new_queue;
00047   else
00048     {
00049       ACE_NEW (this->queue_,
00050                ACE_Message_Queue<ACE_SYNCH>);
00051       this->delete_queue_ = 1;
00052     }
00053 }

ACE_Activation_Queue::~ACE_Activation_Queue void   )  [virtual]
 

Destructor.

Definition at line 76 of file Activation_Queue.cpp.

References delete_queue_, and queue_.

00077 {
00078   if (this->delete_queue_ != 0)
00079     delete this->queue_;
00080 }

ACE_Activation_Queue::ACE_Activation_Queue const ACE_Activation_Queue  )  [private]
 


Member Function Documentation

ACE_Method_Request * ACE_Activation_Queue::dequeue ACE_Time_Value tv = 0  ) 
 

Dequeue the next available ACE_Method_Request.

Parameters:
tv If 0, the method will block until a method request is available, else will wait until the absolute time specified in the referenced ACE_Time_Value. This method will return, earlier, however, if queue is closed, deactivated, or when a signal occurs.
Return values:
Pointer to the dequeued ACE_Method_Request object.
0 an error occurs; errno contains further information. If the specified timeout elapses, errno will be EWOULDBLOCK.

Definition at line 83 of file Activation_Queue.cpp.

References ACE_Message_Block::base(), ACE_Message_Queue< ACE_SYNCH >::dequeue_head(), queue_, and ACE_Message_Block::release().

00084 {
00085   ACE_Message_Block *mb = 0;
00086 
00087   // Dequeue the message.
00088   if (this->queue_->dequeue_head (mb, tv) != -1)
00089     {
00090       // Get the next <Method_Request>.
00091       ACE_Method_Request *mr =
00092         reinterpret_cast<ACE_Method_Request *> (mb->base ());
00093       // Delete the message block.
00094       mb->release ();
00095       return mr;
00096     }
00097   else
00098     return 0;
00099 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Activation_Queue::dump void   )  const
 

Dump the state of an request.

Definition at line 19 of file Activation_Queue.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_Message_Queue< ACE_SYNCH >::dump(), LM_DEBUG, LM_INFO, and queue_.

00020 {
00021 #if defined (ACE_HAS_DUMP)
00022   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023   ACE_DEBUG ((LM_DEBUG,
00024               ACE_LIB_TEXT ("delete_queue_ = %d\n"),
00025               this->delete_queue_));
00026   ACE_DEBUG ((LM_INFO, ACE_LIB_TEXT ("queue_: \n")));
00027   if (this->queue_)
00028     this->queue_->dump();
00029   else
00030     ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("(NULL)\n")));
00031   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00032 #endif /* ACE_HAS_DUMP */
00033 }

int ACE_Activation_Queue::enqueue ACE_Method_Request new_method_request,
ACE_Time_Value tv = 0
 

Enqueue the ACE_Method_Request in priority order.

The priority of the method request is obtained via the priority() method of the queued method request. Priority ordering is determined by the ACE_Message_Queue class; 0 is the lowest priority.

Parameters:
new_method_request Pointer to the ACE_Method_Request object to queue. This object's priority() method is called to obtain the priority.
tv If 0, the method will block until the method request can be queued, else will wait until the absolute time specified in the referenced ACE_Time_Value. This method will return, earlier, however, if queue is closed, deactivated, or when a signal occurs.
Return values:
>0 The number of method requests on the queue after adding the specified request.
-1 if an error occurs; errno contains further information. If the specified timeout elapses, errno will be EWOULDBLOCK.

Definition at line 102 of file Activation_Queue.cpp.

References ACE_DES_FREE, ACE_Message_Block, ACE_NEW_MALLOC_RETURN, allocator_, data_block_allocator_, ACE_Message_Queue< ACE_SYNCH >::enqueue_prio(), and queue_.

00104 {
00105   ACE_Message_Block *mb = 0;
00106 
00107   // We pass sizeof (*mr) here so that flow control will work
00108   // correctly.  Since we also pass <mr> note that no unnecessary
00109   // memory is actually allocated -- just the size field is set.
00110   ACE_NEW_MALLOC_RETURN (mb,
00111                          static_cast<ACE_Message_Block *> (this->allocator_->malloc (sizeof (ACE_Message_Block))),
00112                          ACE_Message_Block (sizeof (*mr),    // size
00113                                             ACE_Message_Block::MB_DATA, // type
00114                                             0,       // cont
00115                                             (char *) mr,    // data
00116                                             0,       // allocator
00117                                             0,       // locking strategy
00118                                             mr->priority (), // priority
00119                                             ACE_Time_Value::zero,     // execution time
00120                                             ACE_Time_Value::max_time, // absolute time of deadline
00121                                             this->data_block_allocator_,  // data_block allocator
00122                                             this->allocator_), // message_block allocator
00123                          -1);
00124 
00125   // Enqueue in priority order.
00126   int const result = this->queue_->enqueue_prio (mb, tv);
00127 
00128   // Free ACE_Message_Block if enqueue_prio failed.
00129   if (result == -1)
00130       ACE_DES_FREE (mb, this->allocator_->free, ACE_Message_Block);
00131 
00132   return result;
00133 }

ACE_INLINE int ACE_Activation_Queue::is_empty void   )  const
 

Returns 1 if the queue is empty, 0 otherwise.

Definition at line 20 of file Activation_Queue.inl.

References ACE_Message_Queue< ACE_SYNCH >::is_empty(), and queue_.

00021 {
00022   return queue_->is_empty ();
00023 }

ACE_INLINE int ACE_Activation_Queue::is_full void   )  const
 

Returns 1 if the queue is full, 0 otherwise.

Definition at line 14 of file Activation_Queue.inl.

References ACE_Message_Queue< ACE_SYNCH >::is_full(), and queue_.

00015 {
00016   return queue_->is_full ();
00017 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE size_t ACE_Activation_Queue::method_count void   )  const
 

Get the current number of method objects in the queue.

Definition at line 8 of file Activation_Queue.inl.

References ACE_Message_Queue< ACE_SYNCH >::message_count(), and queue_.

00009 {
00010   return queue_->message_count ();
00011 }

void ACE_Activation_Queue::operator= const ACE_Activation_Queue  )  [private]
 

void ACE_Activation_Queue::queue ACE_Message_Queue< ACE_SYNCH > *  q  ) 
 

Set the pointer to the underlying queue.

Definition at line 56 of file Activation_Queue.cpp.

References delete_queue_, and queue_.

00057 {
00058   // Destroy the internal queue if one exist.
00059   if (this->delete_queue_ != 0)
00060     {
00061       // Destroy the current queue.
00062       delete this->queue_;
00063  
00064       // Set the flag to false.  NOTE that the delete_queue_ flag is a
00065       // flag used to only indicate whether or not if an internal
00066       // ACE_Message_Queue has been created, therefore, it will not
00067       // affect the user if the user decided to replace the queue with
00068       // their own queue no matter how many time they call on this
00069       // function.
00070       this->delete_queue_ = 0;
00071     }
00072  
00073   queue_ = q;
00074 }

ACE_INLINE ACE_Message_Queue< ACE_SYNCH > * ACE_Activation_Queue::queue void   )  const
 

Get a pointer to the underlying queue.

Definition at line 26 of file Activation_Queue.inl.

References queue_.

00027 {
00028   return queue_;
00029 }


Member Data Documentation

ACE_Activation_Queue::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 141 of file Activation_Queue.h.

ACE_Allocator* ACE_Activation_Queue::allocator_ [private]
 

Allocation strategy of the queue.

Definition at line 160 of file Activation_Queue.h.

Referenced by ACE_Activation_Queue(), and enqueue().

ACE_Allocator* ACE_Activation_Queue::data_block_allocator_ [private]
 

Allocation strategy of the message blocks.

Definition at line 163 of file Activation_Queue.h.

Referenced by enqueue().

int ACE_Activation_Queue::delete_queue_ [protected]
 

Keeps track of whether we need to delete the queue.

Definition at line 155 of file Activation_Queue.h.

Referenced by ACE_Activation_Queue(), queue(), and ~ACE_Activation_Queue().

ACE_Message_Queue<ACE_SYNCH>* ACE_Activation_Queue::queue_ [protected]
 

Stores the Method_Requests.

Definition at line 152 of file Activation_Queue.h.

Referenced by ACE_Activation_Queue(), dequeue(), dump(), enqueue(), is_empty(), is_full(), method_count(), queue(), and ~ACE_Activation_Queue().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:19:03 2006 for ACE by doxygen 1.3.6