#include <LF_Event.h>
Inheritance diagram for TAO_LF_Event:
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 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_Follower * | follower_ |
The bounded follower. | |
Private Member Functions | |
virtual void | set_state (int new_state) |
Set the state irrespective of anything. | |
Friends | |
class | TAO_Leader_Follower |
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.)
Definition at line 50 of file LF_Event.h.
anonymous enum |
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 };
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] |
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.
Reimplemented in TAO_LF_Multi_Event.
Definition at line 8 of file LF_Event.inl.
References follower_.
Referenced by 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 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.
ACE_INLINE int TAO_LF_Event::keep_waiting | ( | void | ) |
Check if we should keep waiting.
Definition at line 32 of file LF_Event.inl.
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().
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.
References state_.
Referenced by TAO_IIOP_Connection_Handler::handle_timeout().
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 44 of file LF_Event.cpp.
References state_.
Referenced by TAO_Leader_Follower::wait_for_event().
00045 { 00046 this->state_ = new_state; 00047 }
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.
Sort of double-checked optimization..
Definition at line 29 of file LF_Event.cpp.
References ACE_GUARD, follower_, TAO_Leader_Follower::lock(), TAO_LF_Follower::signal(), and TAO_SYNCH_MUTEX.
Referenced by TAO_Synch_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_Transport::drain_queue_i(), TAO_IIOP_Connection_Handler::open(), and TAO_Wait_On_Read::wait().
00030 { 00031 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, lf.lock ()); 00032 00033 if (this->is_state_final () == 0) 00034 { 00035 this->state_changed_i (new_state); 00036 00037 /// Sort of double-checked optimization.. 00038 if (this->follower_ != 0) 00039 this->follower_->signal (); 00040 } 00041 }
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.
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 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_.
00018 { 00019 if (this->follower_ == 0) 00020 return -1; 00021 this->follower_ = 0; 00022 return 0; 00023 }
friend class TAO_Leader_Follower [friend] |
Definition at line 54 of file LF_Event.h.
TAO_LF_Follower* TAO_LF_Event::follower_ [protected] |
The bounded follower.
Definition at line 145 of file LF_Event.h.
Referenced by bind(), state_changed(), and unbind().
int TAO_LF_Event::state_ [protected] |
The current state.
Definition at line 142 of file LF_Event.h.
Referenced by TAO_LF_CH_Event::error_detected(), TAO_Connection_Handler::is_connecting(), TAO_Connection_Handler::is_open(), TAO_LF_CH_Event::is_state_final(), reset_state(), 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().