00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file CEC_EventChannel.h 00006 * 00007 * $Id: CEC_EventChannel.h 77001 2007-02-12 07:54:49Z johnnyw $ 00008 * 00009 * @author Carlos O'Ryan (coryan@cs.wustl.edu) 00010 * 00011 * A new implementation of the COS Event Channel. 00012 * This version does not rely on the RTEC in its implementation. 00013 * 00014 * 00015 */ 00016 //============================================================================= 00017 00018 00019 #ifndef TAO_CEC_EVENTCHANNEL_H 00020 #define TAO_CEC_EVENTCHANNEL_H 00021 00022 #include /**/ "ace/pre.h" 00023 00024 #include "orbsvcs/CosEvent/CEC_Factory.h" 00025 00026 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00027 # pragma once 00028 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00029 00030 #include "orbsvcs/CosEventChannelAdminS.h" 00031 00032 #include "orbsvcs/CosEvent/CEC_Defaults.h" 00033 #include "orbsvcs/CosEvent/event_serv_export.h" 00034 #include "ace/Hash_Map_Manager.h" 00035 00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00037 00038 /** 00039 * @class TAO_CEC_EventChannel_Attributes 00040 * 00041 * @brief Defines the construction time attributes for the Event 00042 * Channel. 00043 * 00044 * The event channel implementation is controlled by two 00045 * mechanisms: 00046 * The CEC_Factory that provides the strategies for the EC 00047 * implementation. 00048 * The EC attributes that define constants and values required 00049 * by the EC construction. 00050 * This class encapsulates those constants and values, providing 00051 * an easy mechanism to extend the attributes without requiring 00052 * changes in the EC constructor. 00053 */ 00054 class TAO_Event_Serv_Export TAO_CEC_EventChannel_Attributes 00055 { 00056 public: 00057 /** 00058 * The basic constructor. 00059 * The attributes listed as arguments are *required* by the EC, and 00060 * no appropiate defaults are available for them. 00061 */ 00062 TAO_CEC_EventChannel_Attributes (PortableServer::POA_ptr supplier_poa, 00063 PortableServer::POA_ptr consumer_poa); 00064 00065 // Most fields are public, there is no need to protect them, in fact 00066 // the user should be able to set any values she wants. 00067 00068 /// Can consumers or suppliers invoke connect_push_* multiple times? 00069 int consumer_reconnect; 00070 int supplier_reconnect; 00071 00072 /** 00073 * If not zero the event channel will send disconnect callbacks when 00074 * a disconnect method is called on a Proxy. In other words, if a 00075 * consumer calls disconnect_push_supplier() on its proxy the EC 00076 * will invoke disconnect_push_consumer() on the consumer. A 00077 * similar thing is done for suppliers. 00078 * It is a matter of debate what the spec requires for the regular 00079 * event service. 00080 */ 00081 int disconnect_callbacks; 00082 00083 private: 00084 /// Only the EC can read the private fields. 00085 friend class TAO_CEC_EventChannel; 00086 00087 /// The POAs 00088 PortableServer::POA_ptr supplier_poa; 00089 PortableServer::POA_ptr consumer_poa; 00090 }; 00091 00092 /** 00093 * @class TAO_CEC_EventChannel 00094 * 00095 * @brief The CosEventChannelAdmin::EventChannel implementation. 00096 * 00097 * This class is the Mediator between all the classes in the EC 00098 * implementation, its main task is to redirect the messages to 00099 * the right components, to hold and manage the lifetime of the 00100 * long lived objects (Timer_Module, SupplierAdmin, 00101 * ConsumerAdmin and Dispatching) and to provide a simpler 00102 * interface to the CEC_Factory. 00103 */ 00104 class TAO_Event_Serv_Export TAO_CEC_EventChannel : public POA_CosEventChannelAdmin::EventChannel 00105 { 00106 public: 00107 class ServantBaseHash 00108 { 00109 public: 00110 u_long operator() (PortableServer::ServantBase* const & ptr) const { 00111 return reinterpret_cast<u_long> (ptr); 00112 } 00113 }; 00114 00115 typedef ACE_Hash_Map_Manager_Ex<PortableServer::ServantBase*, 00116 unsigned int, 00117 ServantBaseHash, 00118 ACE_Equal_To<PortableServer::ServantBase*>, 00119 TAO_SYNCH_MUTEX> ServantRetryMap; 00120 00121 /** 00122 * constructor 00123 * If <own_factory> is not 0 it assumes ownership of the factory. 00124 * If the factory is <nil> it uses the Service_Configurator to load 00125 * the Factory, if not found it uses TAO_CEC_Default_Resource_Factory 00126 */ 00127 TAO_CEC_EventChannel (const TAO_CEC_EventChannel_Attributes& attributes, 00128 TAO_CEC_Factory* factory = 0, 00129 int own_factory = 0); 00130 00131 /// destructor 00132 virtual ~TAO_CEC_EventChannel (void); 00133 00134 /// Start the internal threads (if any), etc. 00135 /// After this call the EC can be used. 00136 virtual void activate (void); 00137 00138 /// Shutdown any internal threads, cleanup all the internal 00139 /// structures, flush all the messages, etc. 00140 virtual void shutdown (void); 00141 00142 /// Access the dispatching module.... 00143 TAO_CEC_Dispatching* dispatching (void) const; 00144 00145 /// Access the consumer admin implementation. 00146 TAO_CEC_ConsumerAdmin* consumer_admin (void) const; 00147 00148 /// Access the supplier admin implementation. 00149 TAO_CEC_SupplierAdmin* supplier_admin (void) const; 00150 00151 /// Access the consumer control strategy. 00152 TAO_CEC_ConsumerControl* consumer_control (void) const; 00153 00154 /// Access the supplier control strategy. 00155 TAO_CEC_SupplierControl* supplier_control (void) const; 00156 00157 // = The factory methods, they delegate on the CEC_Factory. 00158 /// Create and destroy a ProxyPushSupplier 00159 void create_proxy (TAO_CEC_ProxyPushSupplier*&); 00160 void destroy_proxy (TAO_CEC_ProxyPushSupplier*); 00161 00162 /// Create and destroy a ProxyPullSupplier 00163 void create_proxy (TAO_CEC_ProxyPullSupplier*&); 00164 void destroy_proxy (TAO_CEC_ProxyPullSupplier*); 00165 00166 /// Create and destroy a ProxyPushConsumer 00167 void create_proxy (TAO_CEC_ProxyPushConsumer*&); 00168 void destroy_proxy (TAO_CEC_ProxyPushConsumer*); 00169 00170 /// Create and destroy a ProxyPushConsumer 00171 void create_proxy (TAO_CEC_ProxyPullConsumer*&); 00172 void destroy_proxy (TAO_CEC_ProxyPullConsumer*); 00173 00174 /// Create and destroy a the collections used to store 00175 /// Proxy*Suppliers 00176 void create_proxy_collection (TAO_CEC_ProxyPushSupplier_Collection*&); 00177 void destroy_proxy_collection (TAO_CEC_ProxyPushSupplier_Collection*); 00178 void create_proxy_collection (TAO_CEC_ProxyPullSupplier_Collection*&); 00179 void destroy_proxy_collection (TAO_CEC_ProxyPullSupplier_Collection*); 00180 00181 /// Create and destroy a the collections used to store 00182 /// Proxy*Consumers 00183 void create_proxy_collection (TAO_CEC_ProxyPushConsumer_Collection*&); 00184 void destroy_proxy_collection (TAO_CEC_ProxyPushConsumer_Collection*); 00185 void create_proxy_collection (TAO_CEC_ProxyPullConsumer_Collection*&); 00186 void destroy_proxy_collection (TAO_CEC_ProxyPullConsumer_Collection*); 00187 00188 /// Access the supplier and consumer POAs from the factory. 00189 PortableServer::POA_ptr supplier_poa (void); 00190 PortableServer::POA_ptr consumer_poa (void); 00191 00192 /// Locking strategies for the ProxyPushConsumer and 00193 /// ProxyPushSupplier objects 00194 ACE_Lock* create_consumer_lock (void); 00195 void destroy_consumer_lock (ACE_Lock*); 00196 ACE_Lock* create_supplier_lock (void); 00197 void destroy_supplier_lock (ACE_Lock*); 00198 00199 /// Used to inform the EC that a Consumer has connected or 00200 /// disconnected from it. 00201 virtual void connected (TAO_CEC_ProxyPushConsumer*); 00202 virtual void reconnected (TAO_CEC_ProxyPushConsumer*); 00203 virtual void disconnected (TAO_CEC_ProxyPushConsumer*); 00204 virtual void connected (TAO_CEC_ProxyPullConsumer*); 00205 virtual void reconnected (TAO_CEC_ProxyPullConsumer*); 00206 virtual void disconnected (TAO_CEC_ProxyPullConsumer*); 00207 00208 /// Used to inform the EC that a Supplier has connected or 00209 /// disconnected from it. 00210 virtual void connected (TAO_CEC_ProxyPushSupplier*); 00211 virtual void reconnected (TAO_CEC_ProxyPushSupplier*); 00212 virtual void disconnected (TAO_CEC_ProxyPushSupplier*); 00213 virtual void connected (TAO_CEC_ProxyPullSupplier*); 00214 virtual void reconnected (TAO_CEC_ProxyPullSupplier*); 00215 virtual void disconnected (TAO_CEC_ProxyPullSupplier*); 00216 00217 // Simple flags to control the EC behavior, set by the application 00218 // at construction time. 00219 00220 /// Can the consumers reconnect to the EC? 00221 int consumer_reconnect (void) const; 00222 00223 /// Can the suppliers reconnect to the EC? 00224 int supplier_reconnect (void) const; 00225 00226 /// Should we send callback disconnect messages when a proxy is 00227 /// disconnected by the client 00228 int disconnect_callbacks (void) const; 00229 00230 // = The CosEventChannelAdmin::EventChannel methods... 00231 /// The default implementation is: 00232 /// this->consumer_admin ()->_this (env); 00233 virtual CosEventChannelAdmin::ConsumerAdmin_ptr 00234 for_consumers (void); 00235 00236 /// The default implementation is: 00237 /// this->supplier_admin ()->_this (env); 00238 virtual CosEventChannelAdmin::SupplierAdmin_ptr 00239 for_suppliers (void); 00240 00241 /// Commit suicide. 00242 virtual void destroy (void); 00243 00244 ServantRetryMap& get_servant_retry_map (void); 00245 00246 /// Forwarded to the factory 00247 CORBA::Policy_ptr 00248 create_roundtrip_timeout_policy (const ACE_Time_Value &timeout); 00249 00250 private: 00251 /// The POAs used to activate "supplier-side" and "consumer-side" 00252 /// objects. 00253 PortableServer::POA_var supplier_poa_; 00254 PortableServer::POA_var consumer_poa_; 00255 00256 /** 00257 * This is the abstract factory that creates all the objects that 00258 * compose an event channel, the event channel simply acts as a 00259 * Mediator among them. 00260 */ 00261 TAO_CEC_Factory *factory_; 00262 00263 /// Flag that indicates if we own the factory. 00264 int own_factory_; 00265 00266 /// The dispatching "module" 00267 TAO_CEC_Dispatching *dispatching_; 00268 00269 /// The pulling strategy 00270 TAO_CEC_Pulling_Strategy *pulling_strategy_; 00271 00272 /// The ConsumerAdmin implementation 00273 TAO_CEC_ConsumerAdmin *consumer_admin_; 00274 00275 /// The SupplierAdmin implementation 00276 TAO_CEC_SupplierAdmin *supplier_admin_; 00277 00278 /// Consumer/Supplier reconnection flags 00279 int consumer_reconnect_; 00280 int supplier_reconnect_; 00281 00282 /// If not zero we send callbacks when a proxy is disconnected 00283 int disconnect_callbacks_; 00284 00285 /// Strategies to disconnect misbehaving or destroyed consumers and 00286 /// suppliers 00287 TAO_CEC_ConsumerControl *consumer_control_; 00288 TAO_CEC_SupplierControl *supplier_control_; 00289 00290 ServantRetryMap retry_map_; 00291 }; 00292 00293 TAO_END_VERSIONED_NAMESPACE_DECL 00294 00295 #if defined (__ACE_INLINE__) 00296 #include "orbsvcs/CosEvent/CEC_EventChannel.inl" 00297 #endif /* __ACE_INLINE__ */ 00298 00299 #include /**/ "ace/post.h" 00300 00301 #endif /* TAO_CEC_EVENT_CHANNEL_H */