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

TAO_LF_Event Class Reference

Use the Leader/Follower loop to wait for one specific event. More...

#include <LF_Event.h>

Inheritance diagram for TAO_LF_Event:

Inheritance graph
[legend]
Collaboration diagram for TAO_LF_Event:

Collaboration graph
[legend]
List of all members.

State management

A Leader/Followers event goes through several states during its lifetime. We use an enum to represent those states and state changes are validated according to the rules defined in the concrete classes. We treat the states as finite states in a FSM. The possible sequence of states through which the FSM migrates is defined in the concrete classes.

enum  {
  LFS_IDLE = 0, LFS_ACTIVE, LFS_CONNECTION_WAIT, LFS_SUCCESS,
  LFS_FAILURE, LFS_TIMEOUT, LFS_CONNECTION_CLOSE_WAIT, LFS_CONNECTION_CLOSED
}
void state_changed (int new_state)
 Accessor to change the state. The state isnt changed unless certain conditions are satisfied. More...

virtual int successful (void) const=0
 Return 1 if the condition was satisfied successfully, 0 if it has not. More...

virtual int error_detected (void) const=0
 Return 1 if an error was detected while waiting for the event. More...

int keep_waiting (void)
 Check if we should keep waiting. More...


Public Types


Public Methods

 TAO_LF_Event (void)
 Constructor. More...

virtual ~TAO_LF_Event (void)
 Destructor. More...

int bind (TAO_LF_Follower *follower)
 Bind a follower. More...

int unbind (void)
 Unbind the follower. More...

void reset_state (int new_state)
 Reset the state, irrespective of the previous states. More...


Protected Methods

virtual void state_changed_i (int new_state)=0
 Validate the state change. More...

virtual int is_state_final (void)=0
 Check whether we have reached the final state.. More...


Protected Attributes

int state_
 The current state. More...

TAO_LF_Followerfollower_
 The bounded follower. More...


Private Methods

virtual void set_state (int new_state)
 Set the state irrespective of anything. More...


Friends

class TAO_Leader_Follower

Detailed Description

Use the Leader/Follower loop to wait for one specific event.

The Leader/Follower event loop is used to wait for incoming responses, as well as to wait for all the data to be flushed. This class encapsulates this event loop. It uses Template Method to parametrize the 'waited for' predicate (i.e. reply received or message sent or connection establishment etc.)

Todo:
Implementing the Leader/Followers loop in this class, as well as the callbacks to communicate that an event has completed leads to excessive coupling. A better design would use a separate class to signal the events, that would allow us to remove the Leader/Followers logic from the ORB. However, that requires other major changes and it somewhat complicates the design.

Definition at line 44 of file LF_Event.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
LFS_IDLE  The event is created, and is in initial state.
LFS_ACTIVE  The event is active.
LFS_CONNECTION_WAIT  The event is waiting for connection completion.
LFS_SUCCESS  The event has completed successfully.
LFS_FAILURE  A failure has been detected while the event was active.
LFS_TIMEOUT  The event has timed out.
LFS_CONNECTION_CLOSE_WAIT  The event is waiting for connection closure. This is a temporary state.
LFS_CONNECTION_CLOSED  The connection was closed.

Definition at line 79 of file LF_Event.h.

00079        {
00080     /// The event is created, and is in initial state
00081     LFS_IDLE = 0,
00082     /// The event is active
00083     LFS_ACTIVE,
00084     /// The event is waiting for connection completion.
00085     LFS_CONNECTION_WAIT,
00086     /// The event has completed successfully
00087     LFS_SUCCESS,
00088     /// A failure has been detected while the event was active
00089     LFS_FAILURE,
00090     /// The event has timed out
00091     LFS_TIMEOUT,
00092     /// The event is waiting for connection closure. This is a
00093     /// temporary state
00094     LFS_CONNECTION_CLOSE_WAIT,
00095     /// The connection was closed.
00096     LFS_CONNECTION_CLOSED
00097   };


Constructor & Destructor Documentation

TAO_LF_Event::TAO_LF_Event void   
 

Constructor.

Definition at line 14 of file LF_Event.cpp.

00015   : state_ (TAO_LF_Event::LFS_IDLE)
00016   , follower_ (0)
00017 {
00018 }

TAO_LF_Event::~TAO_LF_Event void    [virtual]
 

Destructor.

Definition at line 20 of file LF_Event.cpp.

00021 {
00022 }


Member Function Documentation

ACE_INLINE int TAO_LF_Event::bind TAO_LF_Follower   follower
 

Bind a follower.

An event can be waited on by at most one follower thread, this method is used to bind the waiting thread to the event, in order to let the event signal any important state changes.

Returns:
-1 if the LF_Event is already bound, 0 otherwise

Definition at line 5 of file LF_Event.inl.

References follower_.

Referenced by TAO_LF_Event_Binder::TAO_LF_Event_Binder.

00006 {
00007   if (this->follower_ != 0)
00008     return -1;
00009   this->follower_ = follower;
00010   return 0;
00011 }

virtual int TAO_LF_Event::error_detected void    const [pure virtual]
 

Return 1 if an error was detected while waiting for the event.

Implemented in TAO_LF_CH_Event.

Referenced by keep_waiting, and TAO_Leader_Follower::wait_for_event.

virtual int TAO_LF_Event::is_state_final void    [protected, pure virtual]
 

Check whether we have reached the final state..

Implemented in TAO_LF_CH_Event.

Referenced by state_changed.

ACE_INLINE int TAO_LF_Event::keep_waiting void   
 

Check if we should keep waiting.

Definition at line 29 of file LF_Event.inl.

References error_detected, and successful.

Referenced by TAO_Wait_On_Read::wait, TAO_Wait_On_Reactor::wait, TAO_Reactive_Connect_Strategy::wait, and TAO_Leader_Follower::wait_for_event.

00030 {
00031   return (this->successful () == 0) && (this->error_detected () == 0);
00032 }

ACE_INLINE void TAO_LF_Event::reset_state int    new_state
 

Reset the state, irrespective of the previous states.

Reimplemented in TAO_LF_CH_Event.

Definition at line 23 of file LF_Event.inl.

References state_.

Referenced by TAO_GIOP_Twoway_Invocation::reset_states.

00024 {
00025   this->state_ = new_state;
00026 }

void TAO_LF_Event::set_state int    new_state [private, virtual]
 

Set the state irrespective of anything.

Reimplemented in TAO_LF_CH_Event.

Definition at line 51 of file LF_Event.cpp.

References state_.

Referenced by TAO_Leader_Follower::wait_for_event.

00052 {
00053   this->state_ = new_state;
00054 }

void TAO_LF_Event::state_changed int    new_state
 

Accessor to change the state. The state isnt changed unless certain conditions are satisfied.

Virtual methods for this class hierarchy..

Definition at line 25 of file LF_Event.cpp.

References ACE_GUARD, follower_, is_state_final, TAO_LF_Follower::leader_follower, TAO_Leader_Follower::lock, TAO_LF_Follower::signal, state_changed_i, and TAO_SYNCH_MUTEX.

Referenced by TAO_Synch_Queued_Message::bytes_transferred, TAO_Asynch_Queued_Message::bytes_transferred, TAO_Connection_Handler::close_connection_eh, TAO_Connection_Handler::connection_close_wait, TAO_Synch_Reply_Dispatcher::connection_closed, TAO_Synch_Reply_Dispatcher::dispatch_reply, TAO_IIOP_Connection_Handler::open, TAO_Transport::send_connection_closed_notifications_i, TAO_Connection_Handler::TAO_Connection_Handler, and TAO_Wait_On_Read::wait.

00026 {
00027   if (this->follower_ == 0)
00028     {
00029       this->state_changed_i (new_state);
00030     }
00031   else
00032     {
00033       TAO_Leader_Follower &leader_follower =
00034         this->follower_->leader_follower ();
00035 
00036       ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, leader_follower.lock ());
00037 
00038       if (this->is_state_final () == 0)
00039         {
00040           this->state_changed_i (new_state);
00041 
00042           /// Sort of double-checked optimization..
00043           if (this->follower_ != 0)
00044             this->follower_->signal ();
00045         }
00046     }
00047 }

virtual void TAO_LF_Event::state_changed_i int    new_state [protected, pure virtual]
 

Validate the state change.

Implemented in TAO_LF_CH_Event.

Referenced by state_changed.

virtual int TAO_LF_Event::successful void    const [pure virtual]
 

Return 1 if the condition was satisfied successfully, 0 if it has not.

Implemented in TAO_LF_CH_Event.

Referenced by keep_waiting, and TAO_Leader_Follower::wait_for_event.

ACE_INLINE int TAO_LF_Event::unbind void   
 

Unbind the follower.

Definition at line 14 of file LF_Event.inl.

References follower_.

Referenced by TAO_LF_Event_Binder::~TAO_LF_Event_Binder.

00015 {
00016   if (this->follower_ == 0)
00017     return -1;
00018   this->follower_ = 0;
00019   return 0;
00020 }


Friends And Related Function Documentation

friend class TAO_Leader_Follower [friend]
 

Definition at line 48 of file LF_Event.h.


Member Data Documentation

TAO_LF_Follower* TAO_LF_Event::follower_ [protected]
 

The bounded follower.

Definition at line 139 of file LF_Event.h.

Referenced by bind, state_changed, and unbind.

int TAO_LF_Event::state_ [protected]
 

The current state.

Definition at line 136 of file LF_Event.h.

Referenced by TAO_LF_Invocation_Event::error_detected, TAO_LF_CH_Event::error_detected, TAO_LF_Invocation_Event::is_state_final, TAO_LF_CH_Event::is_state_final, reset_state, set_state, TAO_LF_CH_Event::set_state, TAO_LF_Invocation_Event::state_changed_i, TAO_LF_CH_Event::state_changed_i, TAO_LF_Invocation_Event::successful, and TAO_LF_CH_Event::successful.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 15:25:05 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002