PG_GenericFactory.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  * @file  PG_GenericFactory.h
00006  *
00007  * PG_GenericFactory.h,v 1.21 2006/03/14 06:14:34 jtc Exp
00008  *
00009  * @author Ossama Othman <ossama@dre.vanderbilt.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_PG_GENERIC_FACTORY_H
00015 #define TAO_PG_GENERIC_FACTORY_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 #include "ace/config-all.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 #pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #include "orbsvcs/PortableGroup/PG_Factory_Map.h"
00026 #include "orbsvcs/PortableGroup/portablegroup_export.h"
00027 #include "tao/PortableServer/PortableServerC.h"
00028 #include "orbsvcs/PortableGroupC.h"
00029 #include "ace/Null_Mutex.h"
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 /// Forward declarations.
00034 class TAO_PG_ObjectGroupManager;
00035 class TAO_PG_PropertyManager;
00036 
00037 struct TAO_PG_ObjectGroup_Map_Entry;
00038 
00039 
00040 /**
00041  * @class TAO_PG_GenericFactory
00042  *
00043  * @brief PortableGroup::GenericFactory implementation used by the
00044  *        load balancer when creating object groups.
00045  *
00046  * This GenericFactory creates an object group reference for given set
00047  * of replicas.  Those replicas will be created by this GenericFactory
00048  * if the "infrastructure-controlled" membership style is configured.
00049  */
00050 class TAO_PortableGroup_Export TAO_PG_GenericFactory
00051   : public virtual PortableGroup::GenericFactory
00052 {
00053 public:
00054 
00055   /// Constructor.
00056   TAO_PG_GenericFactory (TAO_PG_ObjectGroupManager & object_group_map,
00057                          TAO_PG_PropertyManager & property_manager);
00058 
00059   /// Destructor.
00060   ~TAO_PG_GenericFactory (void);
00061 
00062   /**
00063    * @name TAO_LoadBalancer::GenericFactory methods
00064    */
00065   //@{
00066 
00067   /**
00068    * Create an object of the specified type that adheres to the
00069    * restrictions defined by the provided Criteria.  The out
00070    * FactoryCreationId parameter may be passed to the delete_object()
00071    * method to delete the object.
00072    */
00073   virtual CORBA::Object_ptr create_object (
00074       const char * type_id,
00075       const PortableGroup::Criteria & the_criteria,
00076       PortableGroup::GenericFactory::FactoryCreationId_out
00077         factory_creation_id
00078       ACE_ENV_ARG_DECL_WITH_DEFAULTS)
00079     ACE_THROW_SPEC ((CORBA::SystemException,
00080                      PortableGroup::NoFactory,
00081                      PortableGroup::ObjectNotCreated,
00082                      PortableGroup::InvalidCriteria,
00083                      PortableGroup::InvalidProperty,
00084                      PortableGroup::CannotMeetCriteria));
00085 
00086   /**
00087    * Delete the object corresponding to the provided
00088    * FactoryCreationId.  If the object is actually an ObjectGroup,
00089    * then all members within the ObjectGroup will be deleted.
00090    * Afterward, the ObjectGroup itself will be deleted.
00091    */
00092   virtual void delete_object (
00093       const PortableGroup::GenericFactory::FactoryCreationId &
00094         factory_creation_id
00095       ACE_ENV_ARG_DECL_WITH_DEFAULTS)
00096     ACE_THROW_SPEC ((CORBA::SystemException,
00097                      PortableGroup::ObjectNotFound));
00098 
00099   //@}
00100 
00101   /// Set the POA to use when creating object references.
00102   void poa (PortableServer::POA_ptr p);
00103 
00104   /// Call delete_object() on all factories use to create members in a
00105   /// given object group.
00106   /**
00107    * If ignore_exceptions is true, any exception returned from the
00108    * delete_object() call on the remote factory will be ignored in
00109    * order to allow other objects to be deleted via other registered
00110    * factories.
00111    */
00112   void delete_object_i (TAO_PG_Factory_Set & factory_set,
00113                         CORBA::Boolean ignore_exceptions
00114                         ACE_ENV_ARG_DECL);
00115 
00116   /// If the member corresponding to the given group ID and location
00117   /// was created by the infrastructure, call delete_object() on the
00118   /// remote GenericFactory that created it.
00119   /**
00120    * This method is only used by the TAO_PG_ObjectGroupManager class
00121    * when ObjectGroupManager::remove_member() is explicitly called.
00122    */
00123   void delete_member (CORBA::ULong group_id,
00124                       const PortableGroup::Location & location
00125                       ACE_ENV_ARG_DECL);
00126 
00127   /// Verify that the MinimumNumberMembers criterion is satisfied.
00128   /**
00129    * If the current number of members in the given object group is
00130    * less than the MinimumNumberMembers criterion in effect for that
00131    * group, the infrastructure will attempt create and add more
00132    * members to the group by invoking any unused application-supplied
00133    * GenericFactorys.
00134    */
00135   void check_minimum_number_members (
00136     PortableGroup::ObjectGroup_ptr object_group,
00137     CORBA::ULong group_id,
00138     const char * type_id
00139     ACE_ENV_ARG_DECL);
00140 
00141   /// Create a new object group member using the supplied FactoryInfo
00142   /// and RepositoryId and add it to the given object group.
00143   /**
00144    * @note This method is only used by the infrastructure.
00145    */
00146   PortableGroup::GenericFactory::FactoryCreationId * create_member (
00147       PortableGroup::ObjectGroup_ptr object_group,
00148       const PortableGroup::FactoryInfo & factory_info,
00149       const char * type_id,
00150       const CORBA::Boolean propagate_member_already_present
00151       ACE_ENV_ARG_DECL)
00152     ACE_THROW_SPEC ((CORBA::SystemException,
00153                      PortableGroup::NoFactory,
00154                      PortableGroup::ObjectNotCreated,
00155                      PortableGroup::InvalidCriteria,
00156                      PortableGroup::InvalidProperty,
00157                      PortableGroup::CannotMeetCriteria,
00158                      PortableGroup::MemberAlreadyPresent));
00159 
00160 private:
00161 
00162   /// Populate the object group being created.  Called when the
00163   /// infrastructure-controlled membership style is used for the
00164   /// object group being created.
00165   void populate_object_group (
00166          PortableGroup::ObjectGroup_ptr object_group,
00167          const char * type_id,
00168          const PortableGroup::FactoryInfos &factory_infos,
00169          PortableGroup::InitialNumberMembersValue initial_number_members,
00170          TAO_PG_Factory_Set & factory_set
00171          ACE_ENV_ARG_DECL);
00172 
00173   /// Get a new ObjectId to be used when creating a new ObjectGroup.
00174   /**
00175    * An ObjectId created by this method will never be reused within
00176    * the scope of a given ReplicationManager.  A value suitable for
00177    * use in a map association <ext_id> is also returned.
00178    */
00179   void get_ObjectId (CORBA::ULong fcid,
00180                      PortableServer::ObjectId_out oid);
00181 
00182   /// Process criteria to be applied to the object group being
00183   /// created.
00184   /**
00185    * Only the MemberShipStyle, Factories, InitialNumberMembers and
00186    * MinimumNumberMembers criteria/properties are defined by the
00187    * PortableGroup IDL.  Other services that implement the
00188    * GenericFactory interface, such as load balancing and fault
00189    * tolerance, may choose to support more.
00190    * @par
00191    * The extracted criteria are object group-specific.  In particular,
00192    * they are the object group creation time criteria.
00193    */
00194   void process_criteria (
00195     const char * type_id,
00196     const PortableGroup::Criteria & criteria,
00197     PortableGroup::MembershipStyleValue & membership_style,
00198     PortableGroup::FactoriesValue & factory_infos,
00199     PortableGroup::InitialNumberMembersValue & initial_number_members,
00200     PortableGroup::MinimumNumberMembersValue & minimum_number_members
00201     ACE_ENV_ARG_DECL);
00202 
00203 private:
00204 
00205   /// Reference to the POA used to create object group references.
00206   PortableServer::POA_var poa_;
00207 
00208   /// Reference to the ObjectGroup map.
00209   TAO_PG_ObjectGroupManager & object_group_manager_;
00210 
00211   /// Reference to the PropertyManager.
00212   TAO_PG_PropertyManager & property_manager_;
00213 
00214   /// Table that maps FactoryCreationId to TAO_PG_Factory_Set.
00215   /**
00216    * The TAO_PG_Factory_Set corresponding to a given FactoryCreationId
00217    * contains the information necessary to clean up objects (members)
00218    * that were created by the infrastructure, i.e. this
00219    * GenericFactory.  For example, this GenericFactory will invoke
00220    * other application defined GenericFactorys when creating new
00221    * object group members.  The information returned from those
00222    * application defined GenericFactorys is stored in a
00223    * TAO_PG_Factory_Set, and thus this table.
00224    */
00225   TAO_PG_Factory_Map factory_map_;
00226 
00227   /// The FactoryCreationId that will be assigned to the next object
00228   /// group that is created.
00229   /**
00230    * Value that is used when assigning a FactoryCreationId to the
00231    * factory that was used to create a given ObjectGroup.  The
00232    * FactoryCreationId is typically comprised of this value in
00233    * addition to another value that makes it unique to a given Load
00234    * Balancer.
00235    */
00236   CORBA::ULong next_fcid_;
00237 
00238   /// Lock used to synchronize access to the factory creation id
00239   /// index (i.e. next_fcid_).
00240   TAO_SYNCH_MUTEX lock_;
00241 
00242 };
00243 
00244 TAO_END_VERSIONED_NAMESPACE_DECL
00245 
00246 #include /**/ "ace/post.h"
00247 
00248 #endif  /* TAO_PG_GENERIC_FACTORY_H */

Generated on Thu Nov 9 14:03:33 2006 for TAO_PortableGroup by doxygen 1.3.6