EC_Event_Channel_Base.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file   EC_Event_Channel_Base.h
00005  *
00006  *  EC_Event_Channel_Base.h,v 1.11 2006/03/14 06:14:25 jtc Exp
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 (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
00120 
00121   /// Shutdown any internal threads, cleanup all the internal
00122   /// structures, flush all the messages, etc.
00123   virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
00124 
00125   virtual void for_each_consumer (
00126                     TAO_ESF_Worker<TAO_EC_ProxyPushSupplier> *worker
00127                     ACE_ENV_ARG_DECL)
00128     ACE_THROW_SPEC ((CORBA::SystemException));
00129 
00130   virtual void for_each_supplier (
00131                     TAO_ESF_Worker<TAO_EC_ProxyPushConsumer> *worker
00132                     ACE_ENV_ARG_DECL)
00133     ACE_THROW_SPEC ((CORBA::SystemException));
00134 
00135   /// Access the dispatching module....
00136   TAO_EC_Dispatching* dispatching (void) const;
00137 
00138   /// Access the filter builder....
00139   TAO_EC_Filter_Builder* filter_builder (void) const;
00140 
00141   /// Access the filter builder....
00142   TAO_EC_Supplier_Filter_Builder* supplier_filter_builder (void) const;
00143 
00144   /// Access the consumer admin implementation, useful for controlling
00145   /// the activation...
00146   TAO_EC_ConsumerAdmin* consumer_admin (void) const;
00147 
00148   /// Access the supplier admin implementation, useful for controlling
00149   /// the activation...
00150   TAO_EC_SupplierAdmin* supplier_admin (void) const;
00151 
00152   /// Access the timer module...
00153   TAO_EC_Timeout_Generator* timeout_generator (void) const;
00154 
00155   /// Access the scheduling strategy
00156   TAO_EC_Scheduling_Strategy* scheduling_strategy (void) const;
00157 
00158   /// Access the client control strategies.
00159   TAO_EC_ConsumerControl *consumer_control (void) const;
00160   TAO_EC_SupplierControl *supplier_control (void) const;
00161 
00162   // = The factory methods, they delegate on the EC_Factory.
00163   /// Create and destroy a ProxyPushSupplier
00164   void create_proxy (TAO_EC_ProxyPushSupplier*&);
00165   void destroy_proxy (TAO_EC_ProxyPushSupplier*);
00166 
00167   /// Create and destroy a ProxyPushConsumer
00168   void create_proxy (TAO_EC_ProxyPushConsumer*&);
00169   void destroy_proxy (TAO_EC_ProxyPushConsumer*);
00170 
00171 
00172   /// Create and destroy a the collections used to store
00173   /// ProxyPushSuppliers
00174   void create_proxy_collection (TAO_EC_ProxyPushSupplier_Collection*&);
00175   void destroy_proxy_collection (TAO_EC_ProxyPushSupplier_Collection*);
00176 
00177 
00178   /// Create and destroy a the collections used to store
00179   /// ProxyPushConsumers
00180   void create_proxy_collection (TAO_EC_ProxyPushConsumer_Collection*&);
00181   void destroy_proxy_collection (TAO_EC_ProxyPushConsumer_Collection*);
00182 
00183   /// Access the supplier and consumer POAs from the factory.
00184   PortableServer::POA_ptr supplier_poa (void);
00185   PortableServer::POA_ptr consumer_poa (void);
00186 
00187   /// Locking strategies for the ProxyPushConsumer and
00188   /// ProxyPushSupplier objects
00189   ACE_Lock* create_consumer_lock (void);
00190   void destroy_consumer_lock (ACE_Lock*);
00191   ACE_Lock* create_supplier_lock (void);
00192   void destroy_supplier_lock (ACE_Lock*);
00193 
00194   /// Used to inform the EC that a Consumer has connected or
00195   /// disconnected from it.
00196   virtual void connected (TAO_EC_ProxyPushConsumer*
00197                           ACE_ENV_ARG_DECL_NOT_USED);
00198   virtual void reconnected (TAO_EC_ProxyPushConsumer*
00199                             ACE_ENV_ARG_DECL_NOT_USED);
00200   virtual void disconnected (TAO_EC_ProxyPushConsumer*
00201                              ACE_ENV_ARG_DECL_NOT_USED);
00202 
00203   /// Used to inform the EC that a Supplier has connected or
00204   /// disconnected from it.
00205   virtual void connected (TAO_EC_ProxyPushSupplier*
00206                           ACE_ENV_ARG_DECL_NOT_USED);
00207   virtual void reconnected (TAO_EC_ProxyPushSupplier*
00208                             ACE_ENV_ARG_DECL_NOT_USED);
00209   virtual void disconnected (TAO_EC_ProxyPushSupplier*
00210                              ACE_ENV_ARG_DECL_NOT_USED);
00211 
00212   // Simple flags to control the EC behavior, set by the application
00213   // at construction time.
00214 
00215   /// Can the consumers reconnect to the EC?
00216   int consumer_reconnect (void) const;
00217 
00218   /// Can the suppliers reconnect to the EC?
00219   int supplier_reconnect (void) const;
00220 
00221   /// Should we send callback disconnect messages when a proxy is
00222   /// disconnected by the client
00223   int disconnect_callbacks (void) const;
00224 
00225   /// Obtain the scheduler, the user must release
00226   CORBA::Object_ptr scheduler (void);
00227 
00228   // = The RtecEventChannelAdmin::EventChannel methods...
00229   /// The default implementation is:
00230   ///    this->consumer_admin ()->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00231   virtual RtecEventChannelAdmin::ConsumerAdmin_ptr
00232       for_consumers (ACE_ENV_SINGLE_ARG_DECL)
00233         ACE_THROW_SPEC ((CORBA::SystemException));
00234 
00235   /// The default implementation is:
00236   ///    this->supplier_admin ()->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
00237   virtual RtecEventChannelAdmin::SupplierAdmin_ptr
00238       for_suppliers (ACE_ENV_SINGLE_ARG_DECL)
00239         ACE_THROW_SPEC ((CORBA::SystemException));
00240 
00241   /// Commit suicide.
00242   virtual void destroy (ACE_ENV_SINGLE_ARG_DECL)
00243     ACE_THROW_SPEC ((CORBA::SystemException));
00244 
00245   virtual RtecEventChannelAdmin::Observer_Handle
00246       append_observer (RtecEventChannelAdmin::Observer_ptr
00247                        ACE_ENV_ARG_DECL)
00248       ACE_THROW_SPEC ((
00249           CORBA::SystemException,
00250           RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR,
00251           RtecEventChannelAdmin::EventChannel::CANT_APPEND_OBSERVER));
00252   virtual void
00253       remove_observer (RtecEventChannelAdmin::Observer_Handle
00254                        ACE_ENV_ARG_DECL)
00255       ACE_THROW_SPEC ((
00256           CORBA::SystemException,
00257           RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR,
00258           RtecEventChannelAdmin::EventChannel::CANT_REMOVE_OBSERVER));
00259 
00260   /// Return 1 if the event channel is already destroyed.
00261   int destroyed (void);
00262 
00263 protected:
00264   /**
00265    * Constructor
00266    * If @a own_factory is not 0 it assumes ownership of the factory.
00267    * If the @a factory is nil it uses the Service_Configurator to load
00268    * the Factory, if not found it uses TAO_EC_Default_Resource_Factory
00269    */
00270   TAO_EC_Event_Channel_Base (const TAO_EC_Event_Channel_Attributes& attributes,
00271                              TAO_EC_Factory* factory = 0,
00272                              int own_factory = 0);
00273 
00274   /**
00275    * Get the factory.
00276    */
00277   TAO_EC_Factory * factory (void) const;
00278 
00279   /**
00280    * Set the factory, if @a own_factory is not 0 it assumes ownership of the
00281    * factory.
00282    */
00283   void factory (TAO_EC_Factory* factory,
00284                 int own_factory = 0);
00285 
00286   /**
00287    * Create all strategies
00288    */
00289   void create_strategies (void);
00290 
00291   /// Helpers.  Deactivate admins from their POAs, ignoring any CORBA
00292   /// exceptions.
00293   //@{
00294   void deactivate_supplier_admin (void);
00295   void deactivate_consumer_admin (void);
00296   //@}
00297 
00298   /// The POAs used to activate "supplier-side" and "consumer-side"
00299   /// objects.
00300   PortableServer::POA_var supplier_poa_;
00301   PortableServer::POA_var consumer_poa_;
00302 
00303   /**
00304    * This is the abstract factory that creates all the objects that
00305    * compose an event channel, the event channel simply acts as a
00306    * Mediator among them.
00307    */
00308   TAO_EC_Factory *factory_;
00309 
00310   /// Flag that indicates if we own the factory.
00311   int own_factory_;
00312 
00313   /// The dispatching "module"
00314   TAO_EC_Dispatching *dispatching_;
00315 
00316   /// The filter builder
00317   TAO_EC_Filter_Builder *filter_builder_;
00318 
00319   /// The filter builder for suppliers
00320   TAO_EC_Supplier_Filter_Builder *supplier_filter_builder_;
00321 
00322   /// The ConsumerAdmin implementation
00323   TAO_EC_ConsumerAdmin *consumer_admin_;
00324 
00325   /// The SupplierAdmin implementation
00326   TAO_EC_SupplierAdmin *supplier_admin_;
00327 
00328   /// The timeout generator
00329   TAO_EC_Timeout_Generator *timeout_generator_;
00330 
00331   /// The observer strategy
00332   TAO_EC_ObserverStrategy *observer_strategy_;
00333 
00334   /// The scheduler (may be nil)
00335   CORBA::Object_var scheduler_;
00336 
00337   /// The scheduling strategy
00338   TAO_EC_Scheduling_Strategy *scheduling_strategy_;
00339 
00340   /// Consumer reconnection flags
00341   int consumer_reconnect_;
00342 
00343   /// Supplier reconnection flags
00344   int supplier_reconnect_;
00345 
00346   /// If not zero we send callbacks when a proxy is disconnected
00347   int disconnect_callbacks_;
00348 
00349   /// Strategies to disconnect misbehaving or destroyed consumers
00350   TAO_EC_ConsumerControl *consumer_control_;
00351 
00352   /// Strategies to disconnect misbehaving or destroyed suppliers
00353   TAO_EC_SupplierControl *supplier_control_;
00354 
00355   /// Mutex to protect the internal state
00356   TAO_SYNCH_MUTEX mutex_;
00357 
00358   /// Flag to track the status of the event channel
00359   enum {
00360     EC_S_IDLE
00361     , EC_S_ACTIVATING
00362     , EC_S_ACTIVE
00363     , EC_S_DESTROYING
00364     , EC_S_DESTROYED
00365   };
00366   int status_;
00367 };
00368 
00369 TAO_END_VERSIONED_NAMESPACE_DECL
00370 
00371 #if defined (__ACE_INLINE__)
00372 #include "orbsvcs/Event/EC_Event_Channel_Base.i"
00373 #endif /* __ACE_INLINE__ */
00374 
00375 #include /**/ "ace/post.h"
00376 
00377 #endif /* TAO_EC_EVENT_CHANNEL_BASE_H */

Generated on Thu Nov 9 13:11:07 2006 for TAO_RTEvent by doxygen 1.3.6