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