00001 // -*- C++ -*- 00002 00003 /** 00004 * @file EC_Event_Channel_Base.h 00005 * 00006 * $Id: EC_Event_Channel_Base.h 77001 2007-02-12 07:54:49Z johnnyw $ 00007 * 00008 * @author Carlos O'Ryan (coryan@cs.wustl.edu) 00009 * @author Marina Spivak (marina@atdesk.com) 00010 * @author Jason Smith (jason@atdesk.com) 00011 * 00012 * Based on previous work by Tim Harrison (harrison@cs.wustl.edu) and 00013 * other members of the DOC group. More details can be found in: 00014 * 00015 * http://doc.ece.uci.edu/~coryan/EC/index.html 00016 */ 00017 00018 #ifndef TAO_EC_EVENT_CHANNEL_BASE_H 00019 #define TAO_EC_EVENT_CHANNEL_BASE_H 00020 00021 #include /**/ "ace/pre.h" 00022 00023 #include "orbsvcs/Event/EC_Factory.h" 00024 00025 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00026 # pragma once 00027 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00028 00029 #include "orbsvcs/Event/EC_Defaults.h" 00030 00031 #include "orbsvcs/RtecEventChannelAdminS.h" 00032 00033 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00034 00035 template<class> class TAO_ESF_Worker; 00036 00037 /** 00038 * @class TAO_EC_Event_Channel_Attributes 00039 * 00040 * @brief Defines the construction time attributes for the Event 00041 * Channel. 00042 * 00043 * The event channel implementation is controlled by two 00044 * mechanisms: 00045 * The EC_Factory that provides the strategies for the EC 00046 * implementation. 00047 * The EC attributes that define constants and values required 00048 * by the EC construction. 00049 * This class encapsulates those constants and values, providing 00050 * an easy mechanism to extend the attributes without requiring 00051 * changes in the EC constructor. 00052 */ 00053 class TAO_RTEvent_Serv_Export TAO_EC_Event_Channel_Attributes 00054 { 00055 public: 00056 /** 00057 * The basic constructor. 00058 * The attributes listed as arguments are *required* by the EC, and 00059 * no appropiate defaults are available for them. 00060 */ 00061 TAO_EC_Event_Channel_Attributes (PortableServer::POA_ptr supplier_poa, 00062 PortableServer::POA_ptr consumer_poa); 00063 00064 // Most fields are public, there is no need to protect them, in fact 00065 // the user should be able to set any values she wants. 00066 00067 /// Can consumers or suppliers invoke connect_push_* multiple times? 00068 int consumer_reconnect; 00069 int supplier_reconnect; 00070 00071 /** 00072 * It not zero the event channel will send disconnect callbacks when 00073 * a disconnect method is called on a Proxy. In other words, if a 00074 * consumer calls disconnect_push_supplier() on its proxy the EC 00075 * will invoke disconnect_push_consumer() on the consumer. A 00076 * similar thing is done for suppliers. 00077 * It is a matter of debate what the spec requires for the regular 00078 * event service. 00079 */ 00080 int disconnect_callbacks; 00081 00082 /** 00083 * The scheduling service that we will use with this event channel. 00084 * Notice that this is optional and will only take effect if the EC 00085 * is configured with the right filtering strategies. 00086 */ 00087 CORBA::Object_ptr scheduler; 00088 00089 private: 00090 /// Only the EC can read the private fields. 00091 friend class TAO_EC_Event_Channel_Base; 00092 00093 /// The POAs 00094 PortableServer::POA_ptr supplier_poa; 00095 PortableServer::POA_ptr consumer_poa; 00096 }; 00097 00098 /** 00099 * @class TAO_EC_Event_Channel_Base 00100 * 00101 * @brief The RtecEventChannelAdmin::EventChannel implementation. 00102 * 00103 * This class is the Mediator between all the classes in the EC 00104 * implementation, its main task is to redirect the messages to 00105 * the right components, to hold and manage the lifetime of the 00106 * long lived objects (Timer_Module, SupplierAdmin, 00107 * ConsumerAdmin and Dispatching) and to provide a simpler 00108 * interface to the EC_Factory. 00109 */ 00110 class TAO_RTEvent_Serv_Export TAO_EC_Event_Channel_Base 00111 : public POA_RtecEventChannelAdmin::EventChannel 00112 { 00113 public: 00114 /// destructor 00115 virtual ~TAO_EC_Event_Channel_Base (void); 00116 00117 /// Start the internal threads (if any), etc. 00118 /// After this call the EC can be used. 00119 virtual void activate (void); 00120 00121 /// Shutdown any internal threads, cleanup all the internal 00122 /// structures, flush all the messages, etc. 00123 virtual void shutdown (void); 00124 00125 virtual void for_each_consumer ( 00126 TAO_ESF_Worker<TAO_EC_ProxyPushSupplier> *worker); 00127 00128 virtual void for_each_supplier ( 00129 TAO_ESF_Worker<TAO_EC_ProxyPushConsumer> *worker); 00130 00131 /// Access the dispatching module.... 00132 TAO_EC_Dispatching* dispatching (void) const; 00133 00134 /// Access the filter builder.... 00135 TAO_EC_Filter_Builder* filter_builder (void) const; 00136 00137 /// Access the filter builder.... 00138 TAO_EC_Supplier_Filter_Builder* supplier_filter_builder (void) const; 00139 00140 /// Access the consumer admin implementation, useful for controlling 00141 /// the activation... 00142 TAO_EC_ConsumerAdmin* consumer_admin (void) const; 00143 00144 /// Access the supplier admin implementation, useful for controlling 00145 /// the activation... 00146 TAO_EC_SupplierAdmin* supplier_admin (void) const; 00147 00148 /// Access the timer module... 00149 TAO_EC_Timeout_Generator* timeout_generator (void) const; 00150 00151 /// Access the scheduling strategy 00152 TAO_EC_Scheduling_Strategy* scheduling_strategy (void) const; 00153 00154 /// Access the client control strategies. 00155 TAO_EC_ConsumerControl *consumer_control (void) const; 00156 TAO_EC_SupplierControl *supplier_control (void) const; 00157 00158 // = The factory methods, they delegate on the EC_Factory. 00159 /// Create and destroy a ProxyPushSupplier 00160 void create_proxy (TAO_EC_ProxyPushSupplier*&); 00161 void destroy_proxy (TAO_EC_ProxyPushSupplier*); 00162 00163 /// Create and destroy a ProxyPushConsumer 00164 void create_proxy (TAO_EC_ProxyPushConsumer*&); 00165 void destroy_proxy (TAO_EC_ProxyPushConsumer*); 00166 00167 00168 /// Create and destroy a the collections used to store 00169 /// ProxyPushSuppliers 00170 void create_proxy_collection (TAO_EC_ProxyPushSupplier_Collection*&); 00171 void destroy_proxy_collection (TAO_EC_ProxyPushSupplier_Collection*); 00172 00173 00174 /// Create and destroy a the collections used to store 00175 /// ProxyPushConsumers 00176 void create_proxy_collection (TAO_EC_ProxyPushConsumer_Collection*&); 00177 void destroy_proxy_collection (TAO_EC_ProxyPushConsumer_Collection*); 00178 00179 /// Access the supplier and consumer POAs from the factory. 00180 PortableServer::POA_ptr supplier_poa (void); 00181 PortableServer::POA_ptr consumer_poa (void); 00182 00183 /// Locking strategies for the ProxyPushConsumer and 00184 /// ProxyPushSupplier objects 00185 ACE_Lock* create_consumer_lock (void); 00186 void destroy_consumer_lock (ACE_Lock*); 00187 ACE_Lock* create_supplier_lock (void); 00188 void destroy_supplier_lock (ACE_Lock*); 00189 00190 /// Used to inform the EC that a Consumer has connected or 00191 /// disconnected from it. 00192 virtual void connected (TAO_EC_ProxyPushConsumer*); 00193 virtual void reconnected (TAO_EC_ProxyPushConsumer*); 00194 virtual void disconnected (TAO_EC_ProxyPushConsumer*); 00195 00196 /// Used to inform the EC that a Supplier has connected or 00197 /// disconnected from it. 00198 virtual void connected (TAO_EC_ProxyPushSupplier*); 00199 virtual void reconnected (TAO_EC_ProxyPushSupplier*); 00200 virtual void disconnected (TAO_EC_ProxyPushSupplier*); 00201 00202 // Simple flags to control the EC behavior, set by the application 00203 // at construction time. 00204 00205 /// Can the consumers reconnect to the EC? 00206 int consumer_reconnect (void) const; 00207 00208 /// Can the suppliers reconnect to the EC? 00209 int supplier_reconnect (void) const; 00210 00211 /// Should we send callback disconnect messages when a proxy is 00212 /// disconnected by the client 00213 int disconnect_callbacks (void) const; 00214 00215 /// Obtain the scheduler, the user must release 00216 CORBA::Object_ptr scheduler (void); 00217 00218 // = The RtecEventChannelAdmin::EventChannel methods... 00219 /// The default implementation is: 00220 /// this->consumer_admin ()->_this (); 00221 virtual RtecEventChannelAdmin::ConsumerAdmin_ptr 00222 for_consumers (void); 00223 00224 /// The default implementation is: 00225 /// this->supplier_admin ()->_this (); 00226 virtual RtecEventChannelAdmin::SupplierAdmin_ptr 00227 for_suppliers (void); 00228 00229 /// Commit suicide. 00230 virtual void destroy (void); 00231 00232 virtual RtecEventChannelAdmin::Observer_Handle 00233 append_observer (RtecEventChannelAdmin::Observer_ptr); 00234 virtual void 00235 remove_observer (RtecEventChannelAdmin::Observer_Handle); 00236 00237 /// Return 1 if the event channel is already destroyed. 00238 int destroyed (void); 00239 00240 protected: 00241 /** 00242 * Constructor 00243 * If @a own_factory is not 0 it assumes ownership of the factory. 00244 * If the @a factory is nil it uses the Service_Configurator to load 00245 * the Factory, if not found it uses TAO_EC_Default_Resource_Factory 00246 */ 00247 TAO_EC_Event_Channel_Base (const TAO_EC_Event_Channel_Attributes& attributes, 00248 TAO_EC_Factory* factory = 0, 00249 int own_factory = 0); 00250 00251 /** 00252 * Get the factory. 00253 */ 00254 TAO_EC_Factory * factory (void) const; 00255 00256 /** 00257 * Set the factory, if @a own_factory is not 0 it assumes ownership of the 00258 * factory. 00259 */ 00260 void factory (TAO_EC_Factory* factory, 00261 int own_factory = 0); 00262 00263 /** 00264 * Create all strategies 00265 */ 00266 void create_strategies (void); 00267 00268 /// Helpers. Deactivate admins from their POAs, ignoring any CORBA 00269 /// exceptions. 00270 //@{ 00271 void deactivate_supplier_admin (void); 00272 void deactivate_consumer_admin (void); 00273 //@} 00274 00275 /// The POAs used to activate "supplier-side" and "consumer-side" 00276 /// objects. 00277 PortableServer::POA_var supplier_poa_; 00278 PortableServer::POA_var consumer_poa_; 00279 00280 /** 00281 * This is the abstract factory that creates all the objects that 00282 * compose an event channel, the event channel simply acts as a 00283 * Mediator among them. 00284 */ 00285 TAO_EC_Factory *factory_; 00286 00287 /// Flag that indicates if we own the factory. 00288 int own_factory_; 00289 00290 /// The dispatching "module" 00291 TAO_EC_Dispatching *dispatching_; 00292 00293 /// The filter builder 00294 TAO_EC_Filter_Builder *filter_builder_; 00295 00296 /// The filter builder for suppliers 00297 TAO_EC_Supplier_Filter_Builder *supplier_filter_builder_; 00298 00299 /// The ConsumerAdmin implementation 00300 TAO_EC_ConsumerAdmin *consumer_admin_; 00301 00302 /// The SupplierAdmin implementation 00303 TAO_EC_SupplierAdmin *supplier_admin_; 00304 00305 /// The timeout generator 00306 TAO_EC_Timeout_Generator *timeout_generator_; 00307 00308 /// The observer strategy 00309 TAO_EC_ObserverStrategy *observer_strategy_; 00310 00311 /// The scheduler (may be nil) 00312 CORBA::Object_var scheduler_; 00313 00314 /// The scheduling strategy 00315 TAO_EC_Scheduling_Strategy *scheduling_strategy_; 00316 00317 /// Consumer reconnection flags 00318 int consumer_reconnect_; 00319 00320 /// Supplier reconnection flags 00321 int supplier_reconnect_; 00322 00323 /// If not zero we send callbacks when a proxy is disconnected 00324 int disconnect_callbacks_; 00325 00326 /// Strategies to disconnect misbehaving or destroyed consumers 00327 TAO_EC_ConsumerControl *consumer_control_; 00328 00329 /// Strategies to disconnect misbehaving or destroyed suppliers 00330 TAO_EC_SupplierControl *supplier_control_; 00331 00332 /// Mutex to protect the internal state 00333 TAO_SYNCH_MUTEX mutex_; 00334 00335 /// Flag to track the status of the event channel 00336 enum { 00337 EC_S_IDLE 00338 , EC_S_ACTIVATING 00339 , EC_S_ACTIVE 00340 , EC_S_DESTROYING 00341 , EC_S_DESTROYED 00342 }; 00343 int status_; 00344 }; 00345 00346 TAO_END_VERSIONED_NAMESPACE_DECL 00347 00348 #if defined (__ACE_INLINE__) 00349 #include "orbsvcs/Event/EC_Event_Channel_Base.inl" 00350 #endif /* __ACE_INLINE__ */ 00351 00352 #include /**/ "ace/post.h" 00353 00354 #endif /* TAO_EC_EVENT_CHANNEL_BASE_H */