00001 // -*- C++ -*- 00002 /** 00003 * @file EC_Reactive_ConsumerControl.h 00004 * 00005 * $Id: EC_Reactive_ConsumerControl.h 76589 2007-01-25 18:04:11Z elliott_c $ 00006 * 00007 * @author Carlos O'Ryan (coryan@cs.wustl.edu) 00008 * 00009 * Based on previous work by Tim Harrison (harrison@cs.wustl.edu) and 00010 * other members of the DOC group. More details can be found in: 00011 * 00012 * http://doc.ece.uci.edu/~coryan/EC/index.html 00013 */ 00014 00015 #ifndef TAO_EC_REACTIVE_CONSUMERCONTROL_H 00016 #define TAO_EC_REACTIVE_CONSUMERCONTROL_H 00017 00018 #include /**/ "ace/pre.h" 00019 00020 #include "orbsvcs/Event/EC_ConsumerControl.h" 00021 00022 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00023 # pragma once 00024 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00025 00026 #include "orbsvcs/ESF/ESF_Worker.h" 00027 00028 #include "tao/ORB.h" 00029 #include "tao/PolicyC.h" 00030 00031 #include "ace/Event_Handler.h" 00032 00033 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00034 00035 class TAO_EC_Event_Channel_Base; 00036 00037 class TAO_EC_Reactive_ConsumerControl; 00038 00039 /** 00040 * @class TAO_EC_ConsumerControl_Adapter 00041 * 00042 * @brief Forwards timeout events to the Reactive ConsumerControl 00043 * 00044 * The Reactive ConsumerControl strategy uses the reactor to 00045 * periodically wakeup and verify the state of the consumers 00046 * registered with the Event Channel. 00047 */ 00048 class TAO_RTEvent_Serv_Export TAO_EC_ConsumerControl_Adapter : public ACE_Event_Handler 00049 { 00050 public: 00051 /// Constructor 00052 TAO_EC_ConsumerControl_Adapter (TAO_EC_Reactive_ConsumerControl *adaptee); 00053 00054 // = Documented in ACE_Event_Handler. 00055 virtual int handle_timeout (const ACE_Time_Value &tv, 00056 const void *arg = 0); 00057 00058 private: 00059 /// The adapted object 00060 TAO_EC_Reactive_ConsumerControl *adaptee_; 00061 }; 00062 00063 /** 00064 * @class TAO_EC_Reactive_ConsumerControl 00065 * 00066 * @brief ConsumerControl 00067 * 00068 * Defines the interface for the consumer control strategy. 00069 * This strategy handles misbehaving or failing consumers. 00070 */ 00071 class TAO_RTEvent_Serv_Export TAO_EC_Reactive_ConsumerControl : public TAO_EC_ConsumerControl 00072 { 00073 public: 00074 /// Constructor. It does not assume ownership of the @a event_channel 00075 /// parameter. 00076 TAO_EC_Reactive_ConsumerControl (const ACE_Time_Value &rate, 00077 const ACE_Time_Value &timeout, 00078 TAO_EC_Event_Channel_Base *event_channel, 00079 CORBA::ORB_ptr orb); 00080 00081 /// Destructor. 00082 virtual ~TAO_EC_Reactive_ConsumerControl (void); 00083 00084 /// Receive the timeout from the adapter 00085 void handle_timeout (const ACE_Time_Value &tv, 00086 const void* arg); 00087 00088 // = Documented in TAO_EC_ConsumerControl 00089 virtual int activate (void); 00090 virtual int shutdown (void); 00091 virtual void consumer_not_exist (TAO_EC_ProxyPushSupplier *proxy); 00092 virtual void system_exception (TAO_EC_ProxyPushSupplier *proxy, 00093 CORBA::SystemException &); 00094 00095 private: 00096 /// Check if the consumers still exists. It is a helper method for 00097 /// handle_timeout() to isolate the exceptions. 00098 void query_consumers (void); 00099 00100 private: 00101 /// The polling rate 00102 ACE_Time_Value rate_; 00103 00104 /// The polling timeout 00105 ACE_Time_Value timeout_; 00106 00107 /// The Adapter for the reactor events 00108 TAO_EC_ConsumerControl_Adapter adapter_; 00109 00110 /// The event channel 00111 TAO_EC_Event_Channel_Base *event_channel_; 00112 00113 /// The ORB 00114 CORBA::ORB_var orb_; 00115 00116 /// To control the timeout policy in the thread 00117 CORBA::PolicyCurrent_var policy_current_; 00118 00119 /// Precomputed policy list to the set timeout. 00120 CORBA::PolicyList policy_list_; 00121 00122 /// The ORB reactor 00123 ACE_Reactor *reactor_; 00124 00125 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 00126 /// The timer id 00127 long timer_id_; 00128 #endif /* TAO_HAS_CORBA_MESSAGING */ 00129 }; 00130 00131 // **************************************************************** 00132 00133 class TAO_EC_Ping_Consumer : public TAO_ESF_Worker<TAO_EC_ProxyPushSupplier> 00134 { 00135 public: 00136 TAO_EC_Ping_Consumer (TAO_EC_ConsumerControl *control); 00137 00138 virtual void work (TAO_EC_ProxyPushSupplier *supplier); 00139 00140 private: 00141 TAO_EC_ConsumerControl *control_; 00142 }; 00143 00144 TAO_END_VERSIONED_NAMESPACE_DECL 00145 00146 #if defined (__ACE_INLINE__) 00147 #include "orbsvcs/Event/EC_Reactive_ConsumerControl.inl" 00148 #endif /* __ACE_INLINE__ */ 00149 00150 #include /**/ "ace/post.h" 00151 00152 #endif /* TAO_EC_CONSUMERCONTROL_H */