CEC_EventChannel.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   CEC_EventChannel.h
00006  *
00007  *  CEC_EventChannel.h,v 1.23 2006/03/15 07:52:21 jtc Exp
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 (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
00137 
00138   /// Shutdown any internal threads, cleanup all the internal
00139   /// structures, flush all the messages, etc.
00140   virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
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                           ACE_ENV_ARG_DECL_NOT_USED);
00203   virtual void reconnected (TAO_CEC_ProxyPushConsumer*
00204                             ACE_ENV_ARG_DECL_NOT_USED);
00205   virtual void disconnected (TAO_CEC_ProxyPushConsumer*
00206                              ACE_ENV_ARG_DECL_NOT_USED);
00207   virtual void connected (TAO_CEC_ProxyPullConsumer*
00208                           ACE_ENV_ARG_DECL_NOT_USED);
00209   virtual void reconnected (TAO_CEC_ProxyPullConsumer*
00210                             ACE_ENV_ARG_DECL_NOT_USED);
00211   virtual void disconnected (TAO_CEC_ProxyPullConsumer*
00212                              ACE_ENV_ARG_DECL_NOT_USED);
00213 
00214   /// Used to inform the EC that a Supplier has connected or
00215   /// disconnected from it.
00216   virtual void connected (TAO_CEC_ProxyPushSupplier*
00217                           ACE_ENV_ARG_DECL_NOT_USED);
00218   virtual void reconnected (TAO_CEC_ProxyPushSupplier*
00219                             ACE_ENV_ARG_DECL_NOT_USED);
00220   virtual void disconnected (TAO_CEC_ProxyPushSupplier*
00221                              ACE_ENV_ARG_DECL_NOT_USED);
00222   virtual void connected (TAO_CEC_ProxyPullSupplier*
00223                           ACE_ENV_ARG_DECL_NOT_USED);
00224   virtual void reconnected (TAO_CEC_ProxyPullSupplier*
00225                             ACE_ENV_ARG_DECL_NOT_USED);
00226   virtual void disconnected (TAO_CEC_ProxyPullSupplier*
00227                              ACE_ENV_ARG_DECL_NOT_USED);
00228 
00229   // Simple flags to control the EC behavior, set by the application
00230   // at construction time.
00231 
00232   /// Can the consumers reconnect to the EC?
00233   int consumer_reconnect (void) const;
00234 
00235   /// Can the suppliers reconnect to the EC?
00236   int supplier_reconnect (void) const;
00237 
00238   /// Should we send callback disconnect messages when a proxy is
00239   /// disconnected by the client
00240   int disconnect_callbacks (void) const;
00241 
00242   // = The CosEventChannelAdmin::EventChannel methods...
00243   /// The default implementation is:
00244   ///    this->consumer_admin ()->_this (env);
00245   virtual CosEventChannelAdmin::ConsumerAdmin_ptr
00246       for_consumers (ACE_ENV_SINGLE_ARG_DECL)
00247         ACE_THROW_SPEC ((CORBA::SystemException));
00248 
00249   /// The default implementation is:
00250   ///    this->supplier_admin ()->_this (env);
00251   virtual CosEventChannelAdmin::SupplierAdmin_ptr
00252       for_suppliers (ACE_ENV_SINGLE_ARG_DECL)
00253         ACE_THROW_SPEC ((CORBA::SystemException));
00254 
00255   /// Commit suicide.
00256   virtual void destroy (ACE_ENV_SINGLE_ARG_DECL)
00257     ACE_THROW_SPEC ((CORBA::SystemException));
00258 
00259   ServantRetryMap& get_servant_retry_map (void);
00260 
00261 private:
00262   /// The POAs used to activate "supplier-side" and "consumer-side"
00263   /// objects.
00264   PortableServer::POA_var supplier_poa_;
00265   PortableServer::POA_var consumer_poa_;
00266 
00267   /**
00268    * This is the abstract factory that creates all the objects that
00269    * compose an event channel, the event channel simply acts as a
00270    * Mediator among them.
00271    */
00272   TAO_CEC_Factory *factory_;
00273 
00274   /// Flag that indicates if we own the factory.
00275   int own_factory_;
00276 
00277   /// The dispatching "module"
00278   TAO_CEC_Dispatching *dispatching_;
00279 
00280   /// The pulling strategy
00281   TAO_CEC_Pulling_Strategy *pulling_strategy_;
00282 
00283   /// The ConsumerAdmin implementation
00284   TAO_CEC_ConsumerAdmin *consumer_admin_;
00285 
00286   /// The SupplierAdmin implementation
00287   TAO_CEC_SupplierAdmin *supplier_admin_;
00288 
00289   /// Consumer/Supplier reconnection flags
00290   int consumer_reconnect_;
00291   int supplier_reconnect_;
00292 
00293   /// If not zero we send callbacks when a proxy is disconnected
00294   int disconnect_callbacks_;
00295 
00296   /// Strategies to disconnect misbehaving or destroyed consumers and
00297   /// suppliers
00298   TAO_CEC_ConsumerControl *consumer_control_;
00299   TAO_CEC_SupplierControl *supplier_control_;
00300 
00301   ServantRetryMap retry_map_;
00302 };
00303 
00304 TAO_END_VERSIONED_NAMESPACE_DECL
00305 
00306 #if defined (__ACE_INLINE__)
00307 #include "orbsvcs/CosEvent/CEC_EventChannel.i"
00308 #endif /* __ACE_INLINE__ */
00309 
00310 #include /**/ "ace/post.h"
00311 
00312 #endif /* TAO_CEC_EVENT_CHANNEL_H */

Generated on Thu Nov 9 13:18:17 2006 for TAO_CosEvent by doxygen 1.3.6