00001 // -*- C++ -*- 00002 00003 /** 00004 * @file ECG_Reconnect_ConsumerEC_Control.h 00005 * 00006 * ECG_Reconnect_ConsumerEC_Control.h,v 1.8 2006/03/14 06:14:25 jtc Exp 00007 * 00008 * @author Johnny Willemsen (jwillemsen@remedy.nl) 00009 * 00010 */ 00011 00012 #ifndef TAO_ECG_RECONNECT_CONSUMEREC_CONTROL_H 00013 #define TAO_ECG_RECONNECT_CONSUMEREC_CONTROL_H 00014 00015 #include /**/ "ace/pre.h" 00016 00017 #include "orbsvcs/Event/ECG_ConsumerEC_Control.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "tao/ORB.h" 00024 #include "tao/PolicyC.h" 00025 00026 #include "ace/Event_Handler.h" 00027 00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00029 00030 class TAO_ECG_Reconnect_ConsumerEC_Control; 00031 class TAO_EC_Gateway_IIOP; 00032 00033 /** 00034 * @class TAO_ECG_Reconnect_ConsumerEC_Control_Adapter 00035 * 00036 * @brief Forwards timeout events to the Reconnect ConsumerControl 00037 * 00038 * The Reconnect ConsumerControl strategy uses the reactor to 00039 * periodically wakeup and verify the state of the consumers 00040 * registered with the Event Channel. 00041 */ 00042 class TAO_RTEvent_Serv_Export TAO_ECG_Reconnect_ConsumerEC_Control_Adapter 00043 : public ACE_Event_Handler 00044 { 00045 public: 00046 /// Constructor 00047 TAO_ECG_Reconnect_ConsumerEC_Control_Adapter (TAO_ECG_Reconnect_ConsumerEC_Control *adaptee); 00048 00049 // = Documented in ACE_Event_Handler. 00050 virtual int handle_timeout (const ACE_Time_Value &tv, 00051 const void *arg = 0); 00052 00053 private: 00054 /// The adapted object 00055 TAO_ECG_Reconnect_ConsumerEC_Control *adaptee_; 00056 }; 00057 00058 /** 00059 * @class TAO_ECG_Reconnect_ConsumerEC_Control 00060 * 00061 * @brief Consumer event channel control 00062 * 00063 * Defines the interface for the consumer event channel control strategy. 00064 * This strategy handles misbehaving or failing consumer event channels. 00065 * 00066 * This control tries to reconnect to the consumer ec incase of a connection 00067 * loss and then does a reconnect when the connection is back again. When also 00068 * a restart of the consumer ec must be handled correctly, then the consumer 00069 * ec must use a persistent IOR. 00070 */ 00071 class TAO_RTEvent_Serv_Export TAO_ECG_Reconnect_ConsumerEC_Control 00072 : public TAO_ECG_ConsumerEC_Control 00073 { 00074 public: 00075 /// Constructor. It does not assume ownership of the @a event_channel 00076 /// parameter. 00077 TAO_ECG_Reconnect_ConsumerEC_Control (const ACE_Time_Value &rate, 00078 const ACE_Time_Value &timeout, 00079 TAO_EC_Gateway_IIOP* gateway, 00080 CORBA::ORB_ptr orb); 00081 00082 /// Destructor. 00083 virtual ~TAO_ECG_Reconnect_ConsumerEC_Control (void); 00084 00085 /// Receive the timeout from the adapter 00086 void handle_timeout (const ACE_Time_Value &tv, 00087 const void* arg); 00088 00089 // = Documented in TAO_EC_ConsumerControl 00090 virtual int activate (void); 00091 virtual int shutdown (void); 00092 virtual void event_channel_not_exist (TAO_EC_Gateway_IIOP *gateway 00093 ACE_ENV_ARG_DECL_NOT_USED); 00094 virtual void system_exception (TAO_EC_Gateway_IIOP *gateway, 00095 CORBA::SystemException & 00096 ACE_ENV_ARG_DECL_NOT_USED); 00097 00098 private: 00099 /// Check if the consumers still exists. It is a helper method for 00100 /// handle_timeout() to isolate the exceptions. 00101 void query_eventchannel (ACE_ENV_SINGLE_ARG_DECL); 00102 00103 /// Look if we can reconnect again. 00104 void try_reconnect (ACE_ENV_SINGLE_ARG_DECL); 00105 00106 /// Reconnect to the consumer ec. 00107 void reconnect (ACE_ENV_SINGLE_ARG_DECL); 00108 00109 private: 00110 /// The polling rate 00111 ACE_Time_Value rate_; 00112 00113 /// The polling timeout 00114 ACE_Time_Value timeout_; 00115 00116 /// The Adapter for the reactor events 00117 TAO_ECG_Reconnect_ConsumerEC_Control_Adapter adapter_; 00118 00119 /// The gateway 00120 TAO_EC_Gateway_IIOP* gateway_; 00121 00122 /// The ORB 00123 CORBA::ORB_var orb_; 00124 00125 /// To control the timeout policy in the thread 00126 CORBA::PolicyCurrent_var policy_current_; 00127 00128 /// Precomputed policy list to the set timeout. 00129 CORBA::PolicyList policy_list_; 00130 00131 /// The ORB reactor 00132 ACE_Reactor *reactor_; 00133 00134 /// Do we have a connection to the consumer ec 00135 int is_consumer_ec_connected_; 00136 00137 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 00138 /// The timer id 00139 long timer_id_; 00140 #endif /* TAO_HAS_CORBA_MESSAGING */ 00141 }; 00142 00143 TAO_END_VERSIONED_NAMESPACE_DECL 00144 00145 #include /**/ "ace/post.h" 00146 00147 #endif /* TAO_ECG_RECONNECT_CONSUMEREC_CONTROL_H */