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_CLOSED
}
void state_changed (int new_state, TAO_Leader_Follower &lf)
virtual int successful (void) const=0
virtual int error_detected (void) const=0
int keep_waiting (void)
 Check if we should keep waiting.


Public Types


Public Member Functions

 TAO_LF_Event (void)
 Constructor.

virtual ~TAO_LF_Event (void)
 Destructor.

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

virtual int unbind (void)
 Unbind the follower.

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


Protected Member Functions

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

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


Protected Attributes

int state_
 The current state.

TAO_LF_Followerfollower_
 The bounded follower.


Private Member Functions

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


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 50 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_CLOSED  The connection was closed.

Definition at line 88 of file LF_Event.h.

00088        {
00089     /// The event is created, and is in initial state
00090     LFS_IDLE = 0,
00091     /// The event is active
00092     LFS_ACTIVE,
00093     /// The event is waiting for connection completion.
00094     LFS_CONNECTION_WAIT,
00095     /// The event has completed successfully
00096     LFS_SUCCESS,
00097     /// A failure has been detected while the event was active
00098     LFS_FAILURE,
00099     /// The event has timed out
00100     LFS_TIMEOUT,
00101     /// The connection was closed.
00102     LFS_CONNECTION_CLOSED
00103   };


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_LF_Event::TAO_LF_Event void   ) 
 

Constructor.

Definition at line 18 of file LF_Event.cpp.

00019   : state_ (TAO_LF_Event::LFS_IDLE)
00020   , follower_ (0)
00021 {
00022 }

TAO_LF_Event::~TAO_LF_Event void   )  [virtual]
 

Destructor.

Definition at line 24 of file LF_Event.cpp.

00025 {
00026 }


Member Function Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int TAO_LF_Event::bind TAO_LF_Follower follower  )  [virtual]
 

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.

This is virtual to allow the LF_Multi_Event derived type share the follower with all the subordinate LF_CH_Events.

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

Reimplemented in TAO_LF_Multi_Event.

Definition at line 8 of file LF_Event.inl.

References follower_.

Referenced by TAO_LF_Multi_Event::bind(), and TAO_LF_Event_Binder::TAO_LF_Event_Binder().

00009 {
00010   if (this->follower_ != 0)
00011     return -1;
00012   this->follower_ = follower;
00013   return 0;
00014 }

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, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.

Referenced by keep_waiting(), TAO_Leader_Follower::wait_for_event(), TAO_Reactive_Connect_Strategy::wait_i(), and TAO_LF_Connect_Strategy::wait_i().

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, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.

Referenced by state_changed().

ACE_INLINE int TAO_LF_Event::keep_waiting void   ) 
 

Check if we should keep waiting.

Definition at line 32 of file LF_Event.inl.

References error_detected(), and successful().

Referenced by TAO_IIOP_Connector::complete_connection(), TAO_Wait_On_Read::wait(), TAO_Wait_On_Reactor::wait(), TAO_Leader_Follower::wait_for_event(), and TAO_Reactive_Connect_Strategy::wait_i().

00033 {
00034   return (this->successful () == 0) && (this->error_detected () == 0);
00035 }

ACE_INLINE void TAO_LF_Event::reset_state int  new_state  ) 
 

Reset the state, irrespective of the previous states.

Definition at line 26 of file LF_Event.inl.

00027 {
00028   this->state_ = new_state;
00029 }

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 45 of file LF_Event.cpp.

Referenced by TAO_Leader_Follower::wait_for_event().

00046 {
00047   this->state_ = new_state;
00048 }

void TAO_LF_Event::state_changed int  new_state,
TAO_Leader_Follower lf
 

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

Definition at line 29 of file LF_Event.cpp.

References ACE_GUARD, follower_, is_state_final(), 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_Transport::cleanup_queue_i(), TAO_Connection_Handler::close_connection_eh(), TAO_Connection_Handler::close_handler(), TAO_Synch_Reply_Dispatcher::connection_closed(), TAO_Synch_Reply_Dispatcher::dispatch_reply(), TAO_IIOP_Connection_Handler::open(), TAO_Connection_Handler::TAO_Connection_Handler(), and TAO_Wait_On_Read::wait().

00031 {
00032   ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, lf.lock ());
00033 
00034   if (this->is_state_final () == 0)
00035     {
00036       this->state_changed_i (new_state);
00037 
00038       /// Sort of double-checked optimization..
00039       if (this->follower_ != 0)
00040         this->follower_->signal ();
00041     }
00042 }

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

Validate the state change.

Implemented in TAO_LF_CH_Event, TAO_LF_Invocation_Event, and TAO_LF_Multi_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, TAO_LF_Invocation_Event, and TAO_LF_Multi_Event.

Referenced by keep_waiting(), and TAO_Leader_Follower::wait_for_event().

ACE_INLINE int TAO_LF_Event::unbind void   )  [virtual]
 

Unbind the follower.

Reimplemented in TAO_LF_Multi_Event.

Definition at line 17 of file LF_Event.inl.

References follower_.

Referenced by TAO_LF_Multi_Event::unbind(), and TAO_LF_Event_Binder::~TAO_LF_Event_Binder().

00018 {
00019   if (this->follower_ == 0)
00020     return -1;
00021   this->follower_ = 0;
00022   return 0;
00023 }


Friends And Related Function Documentation

friend class TAO_Leader_Follower [friend]
 

Definition at line 54 of file LF_Event.h.


Member Data Documentation

TAO_LF_Follower* TAO_LF_Event::follower_ [protected]
 

The bounded follower.

Definition at line 146 of file LF_Event.h.

Referenced by bind(), state_changed(), and unbind().

int TAO_LF_Event::state_ [protected]
 

The current state.

Definition at line 143 of file LF_Event.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 12:22:07 2006 for TAO by doxygen 1.3.6