TAO_Asynch_Queued_Message Class Reference

Specialize TAO_Queued_Message for asynch requests, i.e. oneways sent with SYNC_NONE policy. More...

#include <Asynch_Queued_Message.h>

Inheritance diagram for TAO_Asynch_Queued_Message:

Inheritance graph
[legend]
Collaboration diagram for TAO_Asynch_Queued_Message:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_Asynch_Queued_Message (const ACE_Message_Block *contents, TAO_ORB_Core *oc, ACE_Time_Value *timeout, ACE_Allocator *alloc, bool is_heap_allocated)
 Constructor.
virtual ~TAO_Asynch_Queued_Message (void)
 Destructor.
Implement the Template Methods from TAO_Queued_Message
virtual size_t message_length (void) const
 Return the length of the message.
virtual int all_data_sent (void) const
 Return 1 if all the data has been sent.
virtual void fill_iov (int iovcnt_max, int &iovcnt, iovec iov[]) const
 Fill up an io vector using the connects of the message.
virtual void bytes_transferred (size_t &byte_count)
 Update the internal state, data has been sent.
virtual TAO_Queued_Messageclone (ACE_Allocator *alloc)
virtual void destroy (void)
 Reclaim resources.
virtual bool is_expired (const ACE_Time_Value &now) const
 Check for timeout.

Protected Member Functions

 TAO_Asynch_Queued_Message (char *buf, TAO_ORB_Core *oc, size_t size, const ACE_Time_Value &abs_timeout, ACE_Allocator *alloc, bool is_heap_allocated)
 Constructor.

Private Attributes

size_t const size_
 The number of bytes in the buffer.
size_t offset_
 The offset in the buffer.
char * buffer_
 The buffer containing the complete message.
ACE_Time_Value abs_timeout_

Detailed Description

Specialize TAO_Queued_Message for asynch requests, i.e. oneways sent with SYNC_NONE policy.

Definition at line 39 of file Asynch_Queued_Message.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_Asynch_Queued_Message::TAO_Asynch_Queued_Message ( const ACE_Message_Block contents,
TAO_ORB_Core oc,
ACE_Time_Value timeout,
ACE_Allocator alloc,
bool  is_heap_allocated 
)

Constructor.

Parameters:
contents The message block chain that must be sent.
alloc Allocator used for creating this object.
timeout The relative timeout after which this message should be expired.
Todo:
I'm almost sure this class will require a callback interface for AMIs sent with SYNC_NONE policy. Those guys need to hear when the connection timeouts or closes, but cannot block waiting for the message to be delivered.

Definition at line 19 of file Asynch_Queued_Message.cpp.

References ACE_NEW, ACE_High_Res_Timer::gettimeofday_hr(), and ACE_OS::memcpy().

00025   : TAO_Queued_Message (oc, alloc, is_heap_allocated)
00026   , size_ (contents->total_length ())
00027   , offset_ (0)
00028   , abs_timeout_ (ACE_Time_Value::zero)
00029 {
00030   if (timeout != 0)// && *timeout != ACE_Time_Value::zero)
00031     this->abs_timeout_ = ACE_High_Res_Timer::gettimeofday_hr () + *timeout;
00032   // @@ Use a pool for these guys!!
00033   ACE_NEW (this->buffer_, char[this->size_]);
00034 
00035   size_t copy_offset = 0;
00036   for (const ACE_Message_Block *i = contents;
00037        i != 0;
00038        i = i->cont ())
00039     {
00040       ACE_OS::memcpy (this->buffer_ + copy_offset,
00041                       i->rd_ptr (),
00042                       i->length ());
00043       copy_offset += i->length ();
00044     }
00045 }

TAO_Asynch_Queued_Message::~TAO_Asynch_Queued_Message ( void   )  [virtual]

Destructor.

Definition at line 61 of file Asynch_Queued_Message.cpp.

References buffer_.

00062 {
00063   // @@ Use a pool for these guys!
00064   delete [] this->buffer_;
00065 }

TAO_Asynch_Queued_Message::TAO_Asynch_Queued_Message ( char *  buf,
TAO_ORB_Core oc,
size_t  size,
const ACE_Time_Value abs_timeout,
ACE_Allocator alloc,
bool  is_heap_allocated 
) [protected]

Constructor.

Parameters:
buf The buffer that needs to be sent on the wire. The buffer will be owned by this class. The buffer will be deleted when the destructor is called and hence the buffer should always come off the heap!
oc The ORB Core
size The size of the buffer <buf> that is being handed over.
abs_timeout The time after which this message should be expired.
alloc Allocator used for creating <this> object.

Definition at line 47 of file Asynch_Queued_Message.cpp.

00053   : TAO_Queued_Message (oc, alloc, is_heap_allocated)
00054   , size_ (size)
00055   , offset_ (0)
00056   , buffer_ (buf)
00057   , abs_timeout_ (abs_timeout)
00058 {
00059 }


Member Function Documentation

int TAO_Asynch_Queued_Message::all_data_sent ( void   )  const [virtual]

Return 1 if all the data has been sent.

Implements TAO_Queued_Message.

Definition at line 74 of file Asynch_Queued_Message.cpp.

References offset_, and size_.

00075 {
00076   return this->size_ == this->offset_;
00077 }

void TAO_Asynch_Queued_Message::bytes_transferred ( size_t &  byte_count  )  [virtual]

Update the internal state, data has been sent.

After the TAO_Transport class completes a successful (or partially successful) I/O operation it must update the state of all the messages queued. This callback method is used by each message to update its state and determine if all the data has been sent already.

Parameters:
byte_count The number of bytes succesfully sent. The TAO_Queued_Message should decrement this value by the number of bytes that must still be sent.
Returns:
Returns 1 if the TAO_Queued_Message has any more data to send.

Implements TAO_Queued_Message.

Definition at line 93 of file Asynch_Queued_Message.cpp.

References TAO_LF_Event::LFS_ACTIVE, TAO_LF_Event::LFS_SUCCESS, offset_, size_, and TAO_LF_Invocation_Event::state_changed_i().

00094 {
00095   this->state_changed_i (TAO_LF_Event::LFS_ACTIVE);
00096 
00097   size_t const remaining_bytes = this->size_ - this->offset_;
00098   if (byte_count > remaining_bytes)
00099     {
00100       this->offset_ = this->size_;
00101       byte_count -= remaining_bytes;
00102       return;
00103     }
00104   this->offset_ += byte_count;
00105   byte_count = 0;
00106 
00107   if (this->all_data_sent ())
00108     this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00109                          this->orb_core_->leader_follower ());
00110 }

TAO_Queued_Message * TAO_Asynch_Queued_Message::clone ( ACE_Allocator alloc  )  [virtual]

Note:
No reason to believe why this would be called. But have it here for the sake of uniformity.

Implements TAO_Queued_Message.

Definition at line 114 of file Asynch_Queued_Message.cpp.

References ACE_DEBUG, ACE_NEW_MALLOC_RETURN, ACE_NEW_RETURN, LM_DEBUG, ACE_Allocator::malloc(), ACE_OS::memcpy(), offset_, size_, and TAO_debug_level.

00115 {
00116   char *buf = 0;
00117 
00118   // @todo: Need to use a memory pool. But certain things need to
00119   // change a bit in this class for that. Till then.
00120 
00121   // Just allocate and copy data that needs to be sent, no point
00122   // copying the whole buffer.
00123   size_t const sz = this->size_ - this->offset_;
00124 
00125   ACE_NEW_RETURN (buf,
00126                   char[sz],
00127                   0);
00128 
00129   ACE_OS::memcpy (buf,
00130                   this->buffer_ + this->offset_,
00131                   sz);
00132 
00133   TAO_Asynch_Queued_Message *qm = 0;
00134 
00135   if (alloc)
00136     {
00137       ACE_NEW_MALLOC_RETURN (qm,
00138                              static_cast<TAO_Asynch_Queued_Message *> (
00139                                  alloc->malloc (sizeof (TAO_Asynch_Queued_Message))),
00140                              TAO_Asynch_Queued_Message (buf,
00141                                                         this->orb_core_,
00142                                                         sz,
00143                                                         this->abs_timeout_,
00144                                                         alloc,
00145                                                         true),
00146                              0);
00147     }
00148   else
00149     {
00150       // No allocator, so use the common heap!
00151       if (TAO_debug_level == 4)
00152         {
00153           // This debug is for testing purposes!
00154           ACE_DEBUG ((LM_DEBUG,
00155                       "TAO (%P|%t) - Asynch_Queued_Message::clone\n"
00156                       "Using global pool for allocation \n"));
00157         }
00158 
00159       ACE_NEW_RETURN (qm,
00160                       TAO_Asynch_Queued_Message (buf,
00161                                                  this->orb_core_,
00162                                                  sz,
00163                                                  this->abs_timeout_,
00164                                                  0,
00165                                                  true),
00166                       0);
00167     }
00168 
00169   return qm;
00170 }

void TAO_Asynch_Queued_Message::destroy ( void   )  [virtual]

Reclaim resources.

Reliable messages are allocated from the stack, thus they do not be deallocated. Asynchronous (SYNC_NONE) messages are allocated from the heap (or a pool), they need to be reclaimed explicitly.

Implements TAO_Queued_Message.

Definition at line 173 of file Asynch_Queued_Message.cpp.

References ACE_DES_FREE.

00174 {
00175   if (this->is_heap_created_)
00176     {
00177       // If we have an allocator release the memory to the allocator
00178       // pool.
00179       if (this->allocator_)
00180         {
00181           ACE_DES_FREE (this,
00182                         this->allocator_->free,
00183                         TAO_Asynch_Queued_Message);
00184 
00185         }
00186       else // global release..
00187         {
00188           delete this;
00189         }
00190     }
00191 }

void TAO_Asynch_Queued_Message::fill_iov ( int  iovcnt_max,
int &  iovcnt,
iovec  iov[] 
) const [virtual]

Fill up an io vector using the connects of the message.

Different versions of this class represent the message using either a single buffer, or a message block. This method allows a derived class to fill up the contents of an io vector, the TAO_Transport class uses this method to group as many messages as possible in an iovector before sending them to the OS I/O subsystem.

Parameters:
iovcnt_max The number of elements in iov
iovcnt The number of elements already used by iov, this method should update this counter
iov The io vector

Implements TAO_Queued_Message.

Definition at line 80 of file Asynch_Queued_Message.cpp.

References ACE_ASSERT, buffer_, offset_, and size_.

00083 {
00084   ACE_ASSERT (iovcnt_max > iovcnt);
00085   ACE_UNUSED_ARG (iovcnt_max); // not used if ACE_ASSERT() is empty
00086 
00087   iov[iovcnt].iov_base = this->buffer_ + this->offset_;
00088   iov[iovcnt].iov_len  = static_cast<u_long> (this->size_ - this->offset_);
00089   ++iovcnt;
00090 }

bool TAO_Asynch_Queued_Message::is_expired ( const ACE_Time_Value now  )  const [virtual]

Check for timeout.

Parameters:
now Pass in the current time using ACE_High_Res_Timer::gettimeofday_hr(). This is a parameter in order to avoid calling gettimeofday_hr() inside of this method (which will be called in a tight loop).
Returns:
true if the relative roundtrip timeout has expired.

Reimplemented from TAO_Queued_Message.

Definition at line 194 of file Asynch_Queued_Message.cpp.

References abs_timeout_, and ACE_Time_Value::zero.

00195 {
00196   if (this->abs_timeout_ > ACE_Time_Value::zero)
00197     {
00198       if (this->offset_ > 0)
00199         {
00200           return false; //never expire partial messages
00201         }
00202       return this->abs_timeout_ < now;
00203     }
00204   return false;
00205 }

size_t TAO_Asynch_Queued_Message::message_length ( void   )  const [virtual]

Return the length of the message.

If the message has been partially sent it returns the number of bytes that are still not sent.

Implements TAO_Queued_Message.

Definition at line 68 of file Asynch_Queued_Message.cpp.

References offset_, and size_.

00069 {
00070   return this->size_ - this->offset_;
00071 }


Member Data Documentation

ACE_Time_Value TAO_Asynch_Queued_Message::abs_timeout_ [private]

Definition at line 119 of file Asynch_Queued_Message.h.

Referenced by is_expired().

char* TAO_Asynch_Queued_Message::buffer_ [private]

The buffer containing the complete message.

Definition at line 116 of file Asynch_Queued_Message.h.

Referenced by fill_iov(), and ~TAO_Asynch_Queued_Message().

size_t TAO_Asynch_Queued_Message::offset_ [private]

The offset in the buffer.

Data up to offset has been sent already, only the [offset_,size_) range remains to be sent.

Definition at line 113 of file Asynch_Queued_Message.h.

Referenced by all_data_sent(), bytes_transferred(), clone(), fill_iov(), and message_length().

size_t const TAO_Asynch_Queued_Message::size_ [private]

The number of bytes in the buffer.

Definition at line 106 of file Asynch_Queued_Message.h.

Referenced by all_data_sent(), bytes_transferred(), clone(), fill_iov(), and message_length().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:39:21 2010 for TAO by  doxygen 1.4.7