Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Priority_Reactor Class Reference

Implements priority based dispatching. More...

#include <Priority_Reactor.h>

Inheritance diagram for ACE_Priority_Reactor:

Inheritance graph
[legend]
Collaboration diagram for ACE_Priority_Reactor:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Priority_Reactor (ACE_Sig_Handler *=0, ACE_Timer_Queue *=0)
 Initialize <ACE_Priority_Reactor> with the default size. More...

 ACE_Priority_Reactor (size_t size, int restart=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0)
 Initialize <ACE_Priority_Reactor> with size <size>. More...

virtual ~ACE_Priority_Reactor (void)
 Close down the select_reactor and release all of its resources. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Methods

virtual int dispatch_io_set (int number_of_active_handles, int &number_dispatched, int mask, ACE_Handle_Set &dispatch_mask, ACE_Handle_Set &ready_mask, ACE_EH_PTMF callback)
 We simply override this function to implement the priority dispatching. More...


Private Types

typedef ACE_Unbounded_Queue<
ACE_Event_Tuple
QUEUE
 There is a queue per-priority, which simply holds the Event_Handlers until we know who goes first. More...


Private Methods

void init_bucket (void)
 A small helper to initialize the bucket. More...

 ACE_Priority_Reactor (const ACE_Select_Reactor &)
 Deny access since member-wise won't work... More...

ACE_Priority_Reactor & operator= (const ACE_Select_Reactor &)

Private Attributes

QUEUE ** bucket_
ACE_Allocatortuple_allocator_
 The queues themselves use this allocator to minimize dynamic memory usage. More...


Detailed Description

Implements priority based dispatching.

This class refines the dispatching mechanism for the Select_Reactor by taking advantage of the priority method on ACE_Event_Handler.

Definition at line 34 of file Priority_Reactor.h.


Member Typedef Documentation

typedef ACE_Unbounded_Queue<ACE_Event_Tuple> ACE_Priority_Reactor::QUEUE [private]
 

There is a queue per-priority, which simply holds the Event_Handlers until we know who goes first.

Definition at line 76 of file Priority_Reactor.h.


Constructor & Destructor Documentation

ACE_Priority_Reactor::ACE_Priority_Reactor ACE_Sig_Handler   = 0,
ACE_Timer_Queue   = 0
 

Initialize <ACE_Priority_Reactor> with the default size.

Definition at line 42 of file Priority_Reactor.cpp.

References ACE_TRACE, and init_bucket.

00044   : ACE_Select_Reactor(sh, tq),
00045     bucket_ (0),
00046     tuple_allocator_ (0)
00047 {
00048   ACE_TRACE ("ACE_Priority_Reactor::ACE_Priority_Reactor");
00049   this->init_bucket ();
00050 }

ACE_Priority_Reactor::ACE_Priority_Reactor size_t    size,
int    restart = 0,
ACE_Sig_Handler   = 0,
ACE_Timer_Queue   = 0
 

Initialize <ACE_Priority_Reactor> with size <size>.

Definition at line 52 of file Priority_Reactor.cpp.

References ACE_TRACE, and init_bucket.

00056   : ACE_Select_Reactor (size, rs, sh, tq),
00057     bucket_ (0),
00058     tuple_allocator_ (0)
00059 {
00060   ACE_TRACE ("ACE_Priority_Reactor::ACE_Priority_Reactor");
00061   this->init_bucket ();
00062 }

ACE_Priority_Reactor::~ACE_Priority_Reactor void    [virtual]
 

Close down the select_reactor and release all of its resources.

Definition at line 64 of file Priority_Reactor.cpp.

References ACE_TRACE, bucket_, npriorities, and tuple_allocator_.

00065 {
00066   ACE_TRACE ("ACE_Priority_Reactor::~ACE_Priority_Reactor");
00067 
00068   for (int i = 0; i < npriorities; ++i)
00069     delete this->bucket_[i];
00070 
00071   delete[] this->bucket_;
00072   delete tuple_allocator_;
00073 }

ACE_Priority_Reactor::ACE_Priority_Reactor const ACE_Select_Reactor   [private]
 

Deny access since member-wise won't work...


Member Function Documentation

int ACE_Priority_Reactor::dispatch_io_set int    number_of_active_handles,
int &    number_dispatched,
int    mask,
ACE_Handle_Set   dispatch_mask,
ACE_Handle_Set   ready_mask,
ACE_EH_PTMF    callback
[protected, virtual]
 

We simply override this function to implement the priority dispatching.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 76 of file Priority_Reactor.cpp.

References ACE_EH_PTMF, ACE_TRACE, bucket_, ACE_Unbounded_Queue< ACE_Event_Tuple >::dequeue_head, ACE_Unbounded_Queue< ACE_Event_Tuple >::enqueue_tail, ACE_Event_Tuple::event_handler_, ACE_Event_Tuple::handle_, ACE_Event_Handler::HI_PRIORITY, ACE_Unbounded_Queue< ACE_Event_Tuple >::is_empty, ACE_Event_Handler::LO_PRIORITY, ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::notify_handle, ACE_Event_Handler::priority, ACE_Unbounded_Queue< ACE_Event_Tuple >::reset, and ACE_Select_Reactor_Impl::state_changed_.

00082 {
00083   ACE_TRACE ("ACE_Priority_Reactor::dispatch_io_set");
00084 
00085   if (number_of_active_handles == 0)
00086     return 0;
00087 
00088   // The range for which there exists any Event_Tuple is computed on
00089   // the ordering loop, minimizing iterations on the dispatching loop.
00090   int min_priority = ACE_Event_Handler::HI_PRIORITY;
00091   int max_priority = ACE_Event_Handler::LO_PRIORITY;
00092 
00093   ACE_Handle_Set_Iterator handle_iter (dispatch_mask);
00094 
00095   for (ACE_HANDLE handle;
00096        (handle = handle_iter ()) != ACE_INVALID_HANDLE;
00097        )
00098     {
00099       ACE_Event_Tuple et (this->handler_rep_.find (handle),
00100                           handle);
00101       int prio = et.event_handler_->priority ();
00102 
00103       // If the priority is out of range assign the minimum priority.
00104       if (prio < ACE_Event_Handler::LO_PRIORITY
00105           || prio > ACE_Event_Handler::HI_PRIORITY)
00106         prio = ACE_Event_Handler::LO_PRIORITY;
00107 
00108       bucket_[prio]->enqueue_tail (et);
00109 
00110       // Update the priority ranges....
00111       if (min_priority > prio)
00112         min_priority = prio;
00113       if (max_priority < prio)
00114         max_priority = prio;
00115     }
00116 
00117   for (int i = max_priority; i >= min_priority; --i)
00118     {
00119       // Remove all the entries from the wrappers
00120       while (!bucket_[i]->is_empty ()
00121              && number_dispatched < number_of_active_handles
00122              && this->state_changed_ == 0)
00123         {
00124           ACE_Event_Tuple et;
00125           bucket_[i]->dequeue_head (et);
00126           this->notify_handle (et.handle_,
00127                                mask,
00128                                ready_mask,
00129                                et.event_handler_,
00130                                callback);
00131           number_dispatched++;
00132         }
00133       // Even if we are aborting the loop due to this->state_changed
00134       // or another error we still want to cleanup the buckets.
00135       bucket_[i]->reset ();
00136     }
00137 
00138   if (number_dispatched > 0 && this->state_changed_)
00139     return -1;
00140 
00141   return 0;
00142 }

void ACE_Priority_Reactor::dump void    const [virtual]
 

Dump the state of an object.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 145 of file Priority_Reactor.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TRACE, ACE_Select_Reactor_T< ACE_Select_Reactor_Token >::dump, and LM_DEBUG.

00146 {
00147   ACE_TRACE ("ACE_Priority_Reactor::dump");
00148 
00149   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00150 
00151   ACE_Select_Reactor::dump ();
00152 
00153   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00154 }

void ACE_Priority_Reactor::init_bucket void    [private]
 

A small helper to initialize the bucket.

Definition at line 24 of file Priority_Reactor.cpp.

References ACE_NEW, and npriorities.

Referenced by ACE_Priority_Reactor.

00025 {
00026   // Allocate enough space for all the handles.
00027   // TODO: This can be wrong, maybe we should use other kind of
00028   // allocator here?
00029   ACE_NEW (this->tuple_allocator_,
00030            TUPLE_ALLOCATOR (ACE_Select_Reactor::DEFAULT_SIZE));
00031 
00032   // The event handlers are assigned to a new As the Event
00033   ACE_NEW (this->bucket_,
00034            QUEUE *[npriorities]);
00035 
00036   // This loops "ensures" exception safety.
00037   for (int i = 0; i < npriorities; ++i)
00038     ACE_NEW (this->bucket_[i],
00039              QUEUE (this->tuple_allocator_));
00040 }

ACE_Priority_Reactor& ACE_Priority_Reactor::operator= const ACE_Select_Reactor   [private]
 


Member Data Documentation

ACE_Priority_Reactor::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Definition at line 56 of file Priority_Reactor.h.

QUEUE** ACE_Priority_Reactor::bucket_ [private]
 

Definition at line 77 of file Priority_Reactor.h.

Referenced by dispatch_io_set, and ~ACE_Priority_Reactor.

ACE_Allocator* ACE_Priority_Reactor::tuple_allocator_ [private]
 

The queues themselves use this allocator to minimize dynamic memory usage.

Definition at line 81 of file Priority_Reactor.h.

Referenced by ~ACE_Priority_Reactor.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:54:14 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002