Reifies a method into a request. Subclasses typically represent necessary state and behavior. More...
#include <Activation_Queue.h>
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_Request * | dequeue (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. | |
bool | delete_queue_ |
Keeps track of whether we need to delete the queue. | |
Private Attributes | |
ACE_Allocator * | allocator_ |
Allocation strategy of the queue. | |
ACE_Allocator * | data_block_allocator_ |
Allocation strategy of the message blocks. |
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.
Definition at line 52 of file Activation_Queue.h.
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.
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 38 of file Activation_Queue.cpp.
: delete_queue_ (false) , allocator_(alloc) , data_block_allocator_(db_alloc) { if (this->allocator_ == 0) this->allocator_ = ACE_Allocator::instance (); if (new_queue) this->queue_ = new_queue; else { ACE_NEW (this->queue_, ACE_Message_Queue<ACE_SYNCH>); this->delete_queue_ = true; } }
ACE_Activation_Queue::~ACE_Activation_Queue | ( | void | ) | [virtual] |
Destructor.
Definition at line 79 of file Activation_Queue.cpp.
{ if (this->delete_queue_) delete this->queue_; }
ACE_Method_Request * ACE_Activation_Queue::dequeue | ( | ACE_Time_Value * | tv = 0 |
) |
Dequeue the next available ACE_Method_Request.
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. |
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 86 of file Activation_Queue.cpp.
{ ACE_Message_Block *mb = 0; // Dequeue the message. if (this->queue_->dequeue_head (mb, tv) != -1) { // Get the next <Method_Request>. ACE_Method_Request *mr = reinterpret_cast<ACE_Method_Request *> (mb->base ()); // Delete the message block. mb->release (); return mr; } else return 0; }
void ACE_Activation_Queue::dump | ( | void | ) | const |
Dump the state of an request.
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.
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. |
>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 105 of file Activation_Queue.cpp.
{ ACE_Message_Block *mb = 0; // We pass sizeof (*mr) here so that flow control will work // correctly. Since we also pass <mr> note that no unnecessary // memory is actually allocated -- just the size field is set. ACE_NEW_MALLOC_RETURN (mb, static_cast<ACE_Message_Block *> (this->allocator_->malloc (sizeof (ACE_Message_Block))), ACE_Message_Block (sizeof (*mr), // size ACE_Message_Block::MB_DATA, // type 0, // cont (char *) mr, // data 0, // allocator 0, // locking strategy mr->priority (), // priority ACE_Time_Value::zero, // execution time ACE_Time_Value::max_time, // absolute time of deadline this->data_block_allocator_, // data_block allocator this->allocator_), // message_block allocator -1); // Enqueue in priority order. int const result = this->queue_->enqueue_prio (mb, tv); // Free ACE_Message_Block if enqueue_prio failed. if (result == -1) ACE_DES_FREE (mb, this->allocator_->free, ACE_Message_Block); return result; }
int ACE_Activation_Queue::is_empty | ( | void | ) | const [inline] |
Returns 1 if the queue is empty, 0 otherwise.
Definition at line 20 of file Activation_Queue.inl.
int ACE_Activation_Queue::is_full | ( | void | ) | const [inline] |
Returns 1 if the queue is full, 0 otherwise.
Definition at line 14 of file Activation_Queue.inl.
size_t ACE_Activation_Queue::method_count | ( | void | ) | const [inline] |
Get the current number of method objects in the queue.
Definition at line 8 of file Activation_Queue.inl.
{ return queue_->message_count (); }
ACE_Message_Queue< ACE_SYNCH > * ACE_Activation_Queue::queue | ( | void | ) | const [inline] |
Get a pointer to the underlying queue.
Definition at line 26 of file Activation_Queue.inl.
{ return queue_; }
void ACE_Activation_Queue::queue | ( | ACE_Message_Queue< ACE_SYNCH > * | q | ) |
Set the pointer to the underlying queue.
Definition at line 59 of file Activation_Queue.cpp.
{ // Destroy the internal queue if one exist. if (this->delete_queue_) { // Destroy the current queue. delete this->queue_; // Set the flag to false. NOTE that the delete_queue_ flag is a // flag used to only indicate whether or not if an internal // ACE_Message_Queue has been created, therefore, it will not // affect the user if the user decided to replace the queue with // their own queue no matter how many time they call on this // function. this->delete_queue_ = false; } queue_ = q; }
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 154 of file Activation_Queue.h.
Allocation strategy of the message blocks.
Definition at line 157 of file Activation_Queue.h.
bool ACE_Activation_Queue::delete_queue_ [protected] |
Keeps track of whether we need to delete the queue.
Definition at line 149 of file Activation_Queue.h.
ACE_Message_Queue<ACE_SYNCH>* ACE_Activation_Queue::queue_ [protected] |
Stores the Method_Requests.
Definition at line 146 of file Activation_Queue.h.