Public Member Functions | Private Attributes

TAO::CSD::TP_Queue Class Reference

Queue of servant requests that need to be dispatched. More...

#include <CSD_TP_Queue.h>

List of all members.

Public Member Functions

 TP_Queue ()
 Default Constructor.
 ~TP_Queue ()
 Destructor.
void put (TP_Request *request)
 Place a request at the end of the queue.
bool is_empty () const
 Returns true if the queue is empty. Returns false otherwise.
void accept_visitor (TP_Queue_Visitor &visitor)

Private Attributes

TP_Requesthead_
 The request at the front of the queue.
TP_Requesttail_
 The request at the end of the queue.

Detailed Description

Queue of servant requests that need to be dispatched.

This is the queue of pending servant requests that is "owned" by a TP_Strategy object. When an ORB thread dispatches a servant request to the strategy object, it will create the appropriate (subclass of) TP_Request object to "wrap" the servant request in a "queue-friendly" wrapper. The ORB thread will then place the TP_Request object on to the queue. Note that this scenario pertains to what are being called "remote requests". There are other scenarios in which other types of requests can get added to this queue.

The strategy object will employ a set of worker threads that are responsible for "servicing" the servant requests in the queue.

Note: In the future, support will be added to allow the client application inject "custom" TP_Request objects into a TP_Strategy object, causing them to be placed in the queue.

Definition at line 59 of file CSD_TP_Queue.h.


Constructor & Destructor Documentation

TAO::CSD::TP_Queue::TP_Queue (  ) 

Default Constructor.

Definition at line 9 of file CSD_TP_Queue.inl.

  : head_(0),
    tail_(0)
{
}

TAO::CSD::TP_Queue::~TP_Queue (  ) 

Destructor.

Definition at line 17 of file CSD_TP_Queue.inl.

{
}


Member Function Documentation

void TAO::CSD::TP_Queue::accept_visitor ( TP_Queue_Visitor visitor  ) 

Visitors will visit each request in the queue, from front to back, and have the ability to stop visiting at any time (ie, before visiting every request).

Definition at line 47 of file CSD_TP_Queue.cpp.

{
  TP_Request* cur = this->head_;

  while (cur != 0)
    {
      TP_Request* prev = cur->prev_;
      TP_Request* next = cur->next_;

      // Pass the current request to the visitor.  Also pass-in a reference
      // to the remove_from_queue flag.  The visitor may decide that it
      // wants to keep the current request for itself, and desires that the
      // request be (surgically) removed from the queue.  The visitor also
      // gets to decide, via its return value, whether or not visitation
      // should continue (or cease to continue).
      bool remove_from_queue = false;

      bool continue_visitation = visitor.visit_request(cur,remove_from_queue);

      if (remove_from_queue)
        {
          // Create a local handle to release the current request once
          // the handle falls out of scope.  We need to do this because the
          // queue "owns" a "copy" of each request in the queue.
          TP_Request_Handle handle = cur;

          if (this->head_ == cur)
            {
              // The current request is at the front (the head_) of the queue.

              // Move the head_ to the next request in the queue.
              this->head_ = next;

              if (this->head_ == 0)
                {
                  // Not only was the current request at the front of the
                  // queue - it was the *only* request in the queue.
                  // Update the tail_ pointer now that the queue is empty.
                  this->tail_ = 0;
                }
              else
                {
                  // Set the (new) head_ request's prev_ pointer to be NULL.
                  this->head_->prev_ = 0;
                }
            }
          else if (this->tail_ == cur)
            {
              // The current request is not at the front of the queue,
              // but it is at the back of the queue.  This implies that
              // the queue currently contains at least two requests -
              // the current request (cur), and the previous request (prev).
              // The point is that we can now assume that the 'prev' pointer
              // is never NULL in this case.
              this->tail_ = prev;
              this->tail_->next_ = 0;
            }
          else
            {
              // The current request is not at the front or at the back.
              // This implies that there are at least three requests in
              // the queue.  We can assume that the 'next' and 'prev'
              // pointers are never NULL in this case.
              prev->next_ = next;
              next->prev_ = prev;
            }
        }

      if (!continue_visitation)
        {
          // The visitor doesn't want to procede with any further visitation.
          // Break out of the visitation loop now.
          break;
        }

      // Move on to the next request in the queue.
      cur = next;
    }
}

bool TAO::CSD::TP_Queue::is_empty ( void   )  const

Returns true if the queue is empty. Returns false otherwise.

Definition at line 24 of file CSD_TP_Queue.inl.

{
  return (this->head_ == 0);
}

void TAO::CSD::TP_Queue::put ( TP_Request request  ) 

Place a request at the end of the queue.

Definition at line 18 of file CSD_TP_Queue.cpp.

{
  // The request is passed in as an "in" argument, and we would like to
  // hold on to a "copy" within the queue (the linked list).  We will
  // perform an _add_ref() on the request now to make the queue's "copy".
  request->_add_ref();

  if (this->tail_ == 0)
    {
      // The tail_ is a NULL pointer only when the queue is empty.
      // Make the request be the only element in the queue.
      this->head_ = this->tail_ = request;

      // Make sure the request's prev_ and next_ pointers are set to NULL.
      request->prev_ = request->next_ = 0;
    }
  else
    {
      // There is at least one request already in the queue.  "Append" the
      // supplied request object to the end of the queue.
      request->prev_ = this->tail_;
      request->next_ = 0;
      this->tail_->next_ = request;
      this->tail_ = request;
    }
}


Member Data Documentation

TP_Request* TAO::CSD::TP_Queue::head_ [private]

The request at the front of the queue.

Definition at line 84 of file CSD_TP_Queue.h.

TP_Request* TAO::CSD::TP_Queue::tail_ [private]

The request at the end of the queue.

Definition at line 87 of file CSD_TP_Queue.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines