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

ACE_Buffered_Svc_Handler Class Template Reference

Defines the interface for a service that exchanges data with its connected peer and supports buffering. More...

#include <Svc_Handler.h>

Inheritance diagram for ACE_Buffered_Svc_Handler:

Inheritance graph
[legend]
Collaboration diagram for ACE_Buffered_Svc_Handler:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Buffered_Svc_Handler (ACE_Thread_Manager *thr_mgr=0, ACE_Message_Queue< ACE_SYNCH_USE > *mq=0, ACE_Reactor *reactor=ACE_Reactor::instance(), size_t max_buffer_size=0, ACE_Time_Value *relative_timeout=0)
virtual ~ACE_Buffered_Svc_Handler (void)
 Destructor, which calls <flush>. More...

virtual int put (ACE_Message_Block *message_block, ACE_Time_Value *timeout=0)
virtual int flush (void)
 Flush the <ACE_Message_Queue>, which writes all the queued <ACE_Message_Block>s to the <PEER_STREAM>. More...

virtual int handle_timeout (const ACE_Time_Value &time, const void *)
 This method is not currently implemented -- this is where the integration with the <Reactor> would occur. More...

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


Protected Methods

virtual int flush_i (void)
 Implement the flush operation on the <ACE_Message_Queue>, which writes all the queued <ACE_Message_Block>s to the <PEER_STREAM>. Assumes that the caller holds the lock. More...


Protected Attributes

size_t maximum_buffer_size_
 Maximum size the <Message_Queue> can be before we have to flush the buffer. More...

size_t current_buffer_size_
 Current size in bytes of the <Message_Queue> contents. More...

ACE_Time_Value next_timeout_
 Timeout value used to control when the buffer is flushed. More...

ACE_Time_Value interval_
 Interval of the timeout. More...

ACE_Time_Valuetimeoutp_
 Timeout pointer. More...


Detailed Description

template<ACE_PEER_STREAM_1, ACE_SYNCH_DECL>
class ACE_Buffered_Svc_Handler<, >

Defines the interface for a service that exchanges data with its connected peer and supports buffering.

The buffering feature makes it possible to queue up <ACE_Message_Blocks> in an <ACE_Message_Queue> until (1) the queue is "full" or (2) a period of time elapses, at which point the queue is "flushed" via <sendv_n> to the peer.

Definition at line 256 of file Svc_Handler.h.


Constructor & Destructor Documentation

template<PR_ST_1 , ACE_SYNCH_DECL >
ACE_Buffered_Svc_Handler<, >::ACE_Buffered_Svc_Handler ACE_Thread_Manager   thr_mgr = 0,
ACE_Message_Queue< ACE_SYNCH_USE > *    mq = 0,
ACE_Reactor   reactor = ACE_Reactor::instance(),
size_t    max_buffer_size = 0,
ACE_Time_Value   relative_timeout = 0
 

Constructor initializes the <thr_mgr> and <mq> by passing them down to the <ACE_Task> base class. The <reactor> is passed to the <ACE_Event_Handler>. The <max_buffer_size> and <relative_timeout> are used to determine at what point to flush the <mq>. By default, there's no buffering at all. The <relative_timeout> value is interpreted to be in a unit that's relative to the current time returned by <ACE_OS::gettimeofday>.

Definition at line 402 of file Svc_Handler.cpp.

References ACE_SYNCH_USE, ACE_TRACE, ACE_OS::gettimeofday, interval_, next_timeout_, PR_ST_2, and timeoutp_.

00407   : ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE> (tm, mq, reactor),
00408     maximum_buffer_size_ (maximum_buffer_size),
00409     current_buffer_size_ (0),
00410     timeoutp_ (timeout)
00411 {
00412   ACE_TRACE ("ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::ACE_Buffered_Svc_Handler");
00413 
00414   if (this->timeoutp_ != 0)
00415     {
00416       this->interval_ = *timeout;
00417       this->next_timeout_ = ACE_OS::gettimeofday () + this->interval_;
00418     }
00419 }

template<PR_ST_1 , ACE_SYNCH_DECL >
ACE_Buffered_Svc_Handler<, >::~ACE_Buffered_Svc_Handler void    [virtual]
 

Destructor, which calls <flush>.

Definition at line 396 of file Svc_Handler.cpp.

References flush.

00397 {
00398   this->flush ();
00399 }


Member Function Documentation

template<PR_ST_1 , ACE_SYNCH_DECL >
void ACE_Buffered_Svc_Handler<, >::dump void    const
 

Dump the state of an object.

Reimplemented from ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >.

Definition at line 482 of file Svc_Handler.cpp.

References ACE_DEBUG, ACE_TRACE, LM_DEBUG, next_timeout_, timeoutp_, and ACE_Time_Value::usec.

00483 {
00484   ACE_TRACE ("ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump");
00485 
00486   ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump ();
00487   ACE_DEBUG ((LM_DEBUG,
00488               "maximum_buffer_size_ = %d\n",
00489               this->maximum_buffer_size_));
00490   ACE_DEBUG ((LM_DEBUG,
00491               "current_buffer_size_ = %d\n",
00492               this->current_buffer_size_));
00493   if (this->timeoutp_ != 0)
00494     ACE_DEBUG ((LM_DEBUG,
00495                 "next_timeout_.sec = %d, next_timeout_.usec = %d\n",
00496                 this->next_timeout_.sec (),
00497                 this->next_timeout_.usec ()));
00498 }

template<PR_ST_1 , ACE_SYNCH_DECL >
int ACE_Buffered_Svc_Handler<, >::flush void    [virtual]
 

Flush the <ACE_Message_Queue>, which writes all the queued <ACE_Message_Block>s to the <PEER_STREAM>.

Definition at line 449 of file Svc_Handler.cpp.

References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX_T, and flush_i.

Referenced by ~ACE_Buffered_Svc_Handler.

00450 {
00451   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, m, this->msg_queue ()->lock (), -1);
00452 
00453   return this->flush_i ();
00454 }

template<PR_ST_1 , ACE_SYNCH_DECL >
int ACE_Buffered_Svc_Handler<, >::flush_i void    [protected, virtual]
 

Implement the flush operation on the <ACE_Message_Queue>, which writes all the queued <ACE_Message_Block>s to the <PEER_STREAM>. Assumes that the caller holds the lock.

Definition at line 457 of file Svc_Handler.cpp.

References current_buffer_size_, ACE_Message_Queue< ACE_SYNCH_USE >::flush_i, interval_, ACE_Task< ACE_SYNCH_USE >::msg_queue, ACE_Message_Queue_Iterator::next, next_timeout_, ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >::peer, and timeoutp_.

Referenced by flush, and put.

00458 {
00459   ACE_Message_Queue_Iterator<ACE_SYNCH_USE> iterator (*this->msg_queue ());
00460   ACE_Message_Block *mblk;
00461   int result = 0;
00462 
00463   // Get the first <ACE_Message_Block> so that we can write everything
00464   // out via the <send_n>.
00465   if (iterator.next (mblk) != 0)
00466     result = this->peer ().send_n (mblk);
00467 
00468   // This method assumes the caller holds the queue's lock!
00469   if (result != -1)
00470     this->msg_queue ()->flush_i ();
00471 
00472   if (this->timeoutp_ != 0)
00473     // Update the next timeout period by adding the interval.
00474     this->next_timeout_ += this->interval_;
00475 
00476   this->current_buffer_size_ = 0;
00477 
00478   return result;
00479 }

template<PR_ST_1 , ACE_SYNCH_DECL >
int ACE_Buffered_Svc_Handler<, >::handle_timeout const ACE_Time_Value   time,
const void *   
[virtual]
 

This method is not currently implemented -- this is where the integration with the <Reactor> would occur.

Reimplemented from ACE_Svc_Handler< ACE_PEER_STREAM_2, ACE_SYNCH_USE >.

Definition at line 501 of file Svc_Handler.cpp.

References ACE_TRACE.

00503 {
00504   ACE_TRACE ("ACE_Buffered_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::handle_timeout");
00505   return 0;
00506 }

template<PR_ST_1 , ACE_SYNCH_DECL >
int ACE_Buffered_Svc_Handler<, >::put ACE_Message_Block   message_block,
ACE_Time_Value   timeout = 0
[virtual]
 

Insert the <ACE_Message_Block> chain rooted at <message_block> into the <ACE_Message_Queue> with the designated <timeout>. The <flush> method will be called if this <put> causes the number of bytes to exceed the maximum buffer size or if the timeout period has elapsed.

Reimplemented from ACE_Task_Base.

Definition at line 422 of file Svc_Handler.cpp.

References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX_T, current_buffer_size_, flush_i, ACE_OS::gettimeofday, maximum_buffer_size_, next_timeout_, ACE_Task< ACE_SYNCH_USE >::putq, timeoutp_, and ACE_Message_Block::total_size.

00424 {
00425   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, m, this->msg_queue ()->lock (), -1);
00426 
00427   // Enqueue <mb> onto the message queue.
00428   if (this->putq (mb, tv) == -1)
00429     return -1;
00430   else
00431     {
00432       // Update the current number of bytes on the queue.
00433       this->current_buffer_size_ += mb->total_size ();
00434 
00435       // Flush the buffer when the number of bytes exceeds the maximum
00436       // buffer size or when the timeout period has elapsed.
00437       if (this->current_buffer_size_ >= this->maximum_buffer_size_
00438           || (this->timeoutp_ != 0
00439               && this->next_timeout_ <= ACE_OS::gettimeofday ()))
00440         return this->flush_i ();
00441       else
00442         return 0;
00443     }
00444 }


Member Data Documentation

template<ACE_PEER_STREAM_1 , ACE_SYNCH_DECL >
size_t ACE_Buffered_Svc_Handler::current_buffer_size_ [protected]
 

Current size in bytes of the <Message_Queue> contents.

Definition at line 311 of file Svc_Handler.h.

Referenced by flush_i, and put.

template<ACE_PEER_STREAM_1 , ACE_SYNCH_DECL >
ACE_Time_Value ACE_Buffered_Svc_Handler::interval_ [protected]
 

Interval of the timeout.

Definition at line 317 of file Svc_Handler.h.

Referenced by ACE_Buffered_Svc_Handler, and flush_i.

template<ACE_PEER_STREAM_1 , ACE_SYNCH_DECL >
size_t ACE_Buffered_Svc_Handler::maximum_buffer_size_ [protected]
 

Maximum size the <Message_Queue> can be before we have to flush the buffer.

Definition at line 308 of file Svc_Handler.h.

Referenced by put.

template<ACE_PEER_STREAM_1 , ACE_SYNCH_DECL >
ACE_Time_Value ACE_Buffered_Svc_Handler::next_timeout_ [protected]
 

Timeout value used to control when the buffer is flushed.

Definition at line 314 of file Svc_Handler.h.

Referenced by ACE_Buffered_Svc_Handler, dump, flush_i, and put.

template<ACE_PEER_STREAM_1 , ACE_SYNCH_DECL >
ACE_Time_Value* ACE_Buffered_Svc_Handler::timeoutp_ [protected]
 

Timeout pointer.

Definition at line 320 of file Svc_Handler.h.

Referenced by ACE_Buffered_Svc_Handler, dump, flush_i, and put.


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