Object_Adapter.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Object_Adapter.h
00006  *
00007  *  $Id: Object_Adapter.h 81663 2008-05-09 12:43:47Z johnnyw $
00008  *
00009  *  @author Irfan Pyarali
00010  */
00011 //=============================================================================
00012 
00013 #ifndef TAO_OBJECT_ADAPTER_H
00014 #define TAO_OBJECT_ADAPTER_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "tao/PortableServer/portableserver_export.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "tao/PortableServer/Key_Adapters.h"
00025 #include "tao/PortableServer/poa_macros.h"
00026 #include "tao/PortableServer/Servant_Location.h"
00027 #include "tao/PortableServer/Default_Policy_Validator.h"
00028 #include "tao/PortableServer/POA_Policy_Set.h"
00029 #include "tao/PortableServer/POAManagerC.h"
00030 
00031 #include "tao/Adapter.h"
00032 #include "tao/Adapter_Factory.h"
00033 #include "tao/Server_Strategy_Factory.h"
00034 #include "tao/LocalObject.h"
00035 
00036 #include "ace/Reverse_Lock_T.h"
00037 #include "ace/Condition_Thread_Mutex.h"
00038 #include "ace/Map_T.h"
00039 
00040 #include "tao/PortableServer/Servant_Location.h"
00041 
00042 #if defined(_MSC_VER)
00043 #pragma warning(push)
00044 #pragma warning(disable:4250)
00045 #endif /* _MSC_VER */
00046 
00047 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00048 
00049 class TAO_Root_POA;
00050 class TAO_POA_Manager;
00051 class TAO_TSS_Resources;
00052 class TAO_Transport;
00053 class TAO_Servant_Dispatcher;
00054 class TAO_POAManager_Factory;
00055 
00056 namespace TAO
00057 {
00058   namespace Portable_Server
00059   {
00060     class Non_Servant_Upcall;
00061     class Servant_Upcall;
00062     class POA_Current_Impl;
00063     class Temporary_Creation_Time;
00064   }
00065 }
00066 
00067 /**
00068  * @class TAO_Object_Adapter
00069  *
00070  * @brief Defines the Object Adapter abstraction.
00071  *
00072  * This class will be used as a facade for the POAs in a server
00073  */
00074 class TAO_PortableServer_Export TAO_Object_Adapter
00075   : public TAO_Adapter
00076 {
00077 public:
00078 
00079   friend class TAO_Root_POA;
00080 
00081   typedef PortableServer::ObjectId poa_name;
00082   typedef PortableServer::ObjectId_var poa_name_var;
00083   typedef PortableServer::ObjectId_out poa_name_out;
00084 
00085   /// Constructor.
00086   TAO_Object_Adapter (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters,
00087                       TAO_ORB_Core &orb_core);
00088 
00089   /// Destructor.
00090   ~TAO_Object_Adapter (void);
00091 
00092   int dispatch_servant (const TAO::ObjectKey &key,
00093                         TAO_ServerRequest &req,
00094                         CORBA::Object_out forward_to);
00095 
00096   int locate_servant (const TAO::ObjectKey &key);
00097 
00098   TAO_SERVANT_LOCATION find_servant (const TAO::ObjectKey &key,
00099                                      PortableServer::Servant &servant);
00100 
00101   int find_poa (const poa_name &system_name,
00102                 CORBA::Boolean activate_it,
00103                 CORBA::Boolean root,
00104                 const TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time,
00105                 TAO_Root_POA *&poa);
00106 
00107   int bind_poa (const poa_name &folded_name,
00108                 TAO_Root_POA *poa,
00109                 poa_name_out system_name);
00110 
00111   int unbind_poa (TAO_Root_POA *poa,
00112                   const poa_name &folded_name,
00113                   const poa_name &system_name);
00114 
00115   int activate_poa (const poa_name &folded_name,
00116                     TAO_Root_POA *&poa);
00117 
00118   ACE_Lock &lock (void);
00119 
00120   TAO_SYNCH_MUTEX &thread_lock (void);
00121 
00122   ACE_Reverse_Lock<ACE_Lock> &reverse_lock (void);
00123 
00124   /// Access the root poa.
00125   TAO_Root_POA *root_poa (void) const;
00126 
00127   /// Access to ORB Core.
00128   TAO_ORB_Core &orb_core (void) const;
00129 
00130   /// Wait for non-servant upcalls to complete.
00131   void wait_for_non_servant_upcalls_to_complete (void);
00132 
00133   /// Non-exception throwing version.
00134   void wait_for_non_servant_upcalls_to_complete_no_throw (void);
00135 
00136   static CORBA::ULong transient_poa_name_size (void);
00137 
00138   /// Return the validator.
00139   TAO_Policy_Validator &validator (void);
00140 
00141   int enable_locking() const;
00142 
00143   /// Return the set of default policies.
00144   TAO_POA_Policy_Set &default_poa_policies (void);
00145 
00146   /// Set the servant dispatcher method.  Ownership is transferred to
00147   /// this Object Adapter.  Note: This should only be called
00148   /// at initialization.
00149   void servant_dispatcher (TAO_Servant_Dispatcher *dispatcher);
00150 
00151   /// Initialize the default set of POA policies.
00152   void init_default_policies (TAO_POA_Policy_Set &policies
00153                              );
00154 
00155   // = The TAO_Adapter methods, please check tao/Adapter.h for the
00156   // documentation
00157   virtual void open (void);
00158   virtual void close (int wait_for_completion);
00159   virtual void check_close (int wait_for_completion);
00160   virtual int priority (void) const;
00161   virtual int dispatch (TAO::ObjectKey &key,
00162                         TAO_ServerRequest &request,
00163                         CORBA::Object_out forward_to);
00164   virtual const char *name (void) const;
00165   virtual CORBA::Object_ptr root (void);
00166   virtual CORBA::Object_ptr create_collocated_object (TAO_Stub *,
00167                                                       const TAO_MProfile &);
00168 
00169   virtual CORBA::Long initialize_collocated_object (TAO_Stub *);
00170 
00171 protected:
00172 
00173   int locate_servant_i (const TAO::ObjectKey &key);
00174 
00175   TAO_SERVANT_LOCATION find_servant_i (const TAO::ObjectKey &key,
00176                                        PortableServer::Servant &servant);
00177 
00178   void dispatch_servant_i (const TAO::ObjectKey &key,
00179                            TAO_ServerRequest &req,
00180                            void *context);
00181 
00182   void locate_poa (const TAO::ObjectKey &key,
00183                    PortableServer::ObjectId &id,
00184                    TAO_Root_POA *&poa                  );
00185 
00186   int find_transient_poa (const poa_name &system_name,
00187                           CORBA::Boolean root,
00188                           const TAO::Portable_Server::Temporary_Creation_Time &poa_creation_time,
00189                           TAO_Root_POA *&poa);
00190 
00191   int find_persistent_poa (const poa_name &system_name, TAO_Root_POA *&poa);
00192 
00193   int bind_transient_poa (TAO_Root_POA *poa, poa_name_out system_name);
00194 
00195   int bind_persistent_poa (const poa_name &folded_name,
00196                            TAO_Root_POA *poa,
00197                            poa_name_out system_name);
00198 
00199   int unbind_transient_poa (const poa_name &system_name);
00200 
00201   int unbind_persistent_poa (const poa_name &folded_name,
00202                              const poa_name &system_name);
00203 
00204   static ACE_Lock *create_lock (int enable_locking,
00205                                 TAO_SYNCH_MUTEX &thread_lock);
00206 
00207   virtual void do_dispatch (TAO_ServerRequest& req,
00208                             TAO::Portable_Server::Servant_Upcall& upcall);
00209 
00210 public:
00211 
00212   /**
00213    * @class Hint_Strategy
00214    *
00215    * @brief Base class for POA active hint strategy.
00216    *
00217    * This class also provides for common structures used by all
00218    * the derived classes.
00219    */
00220   class TAO_PortableServer_Export Hint_Strategy
00221   {
00222   public:
00223 
00224     virtual ~Hint_Strategy (void);
00225 
00226     virtual int find_persistent_poa (const poa_name &system_name,
00227                                      TAO_Root_POA *&poa) = 0;
00228 
00229     virtual int bind_persistent_poa (const poa_name &folded_name,
00230                                      TAO_Root_POA *poa,
00231                                      poa_name_out system_name) = 0;
00232 
00233     virtual int unbind_persistent_poa (const poa_name &folded_name,
00234                                        const poa_name &system_name) = 0;
00235 
00236     void object_adapter (TAO_Object_Adapter *oa);
00237 
00238   protected:
00239 
00240     TAO_Object_Adapter *object_adapter_;
00241   };
00242 
00243   /**
00244    * @class Active_Hint_Strategy
00245    *
00246    * @brief This class uses active demux hint for POA active hint
00247    * strategy.
00248    *
00249    * This class will append an active hint to the POA name,
00250    * making the POA lookups fast and predictable.
00251    */
00252   class TAO_PortableServer_Export Active_Hint_Strategy : public Hint_Strategy
00253   {
00254   public:
00255 
00256     Active_Hint_Strategy (CORBA::ULong map_size);
00257 
00258     virtual ~Active_Hint_Strategy (void);
00259 
00260     virtual int find_persistent_poa (const poa_name &system_name,
00261                                      TAO_Root_POA *&poa);
00262 
00263     virtual int bind_persistent_poa (const poa_name &folded_name,
00264                                      TAO_Root_POA *poa,
00265                                      poa_name_out system_name);
00266 
00267     virtual int unbind_persistent_poa (const poa_name &folded_name,
00268                                        const poa_name &system_name);
00269 
00270   protected:
00271 
00272     typedef ACE_Active_Map_Manager_Adapter<
00273     poa_name,
00274       TAO_Root_POA *,
00275       TAO_Preserve_Original_Key_Adapter> persistent_poa_system_map;
00276 
00277     persistent_poa_system_map persistent_poa_system_map_;
00278   };
00279 
00280   friend class Active_Hint_Strategy;
00281 
00282   /**
00283    * @class No_Hint_Strategy
00284    *
00285    * @brief This class doesn't use any hints for POA active hint
00286    * strategy.
00287    *
00288    * This class will simply use the POA names as is. And since
00289    * no hint is added, the IORs will be smaller.
00290    */
00291   class TAO_PortableServer_Export No_Hint_Strategy : public Hint_Strategy
00292   {
00293   public:
00294 
00295     virtual ~No_Hint_Strategy (void);
00296 
00297     virtual int find_persistent_poa (const poa_name &system_name,
00298                                      TAO_Root_POA *&poa);
00299 
00300     virtual int bind_persistent_poa (const poa_name &folded_name,
00301                                      TAO_Root_POA *poa,
00302                                      poa_name_out system_name);
00303 
00304     virtual int unbind_persistent_poa (const poa_name &folded_name,
00305                                        const poa_name &system_name);
00306 
00307   };
00308 
00309   friend class No_Hint_Strategy;
00310 
00311 protected:
00312 
00313   Hint_Strategy *hint_strategy_;
00314 
00315   /// Base class of the id map.
00316   typedef ACE_Map<
00317   poa_name,
00318     TAO_Root_POA *> transient_poa_map;
00319 
00320 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00321   /// Id hash map.
00322   typedef ACE_Hash_Map_Manager_Ex_Adapter<
00323   poa_name,
00324     TAO_Root_POA *,
00325     TAO_ObjectId_Hash,
00326     ACE_Equal_To<poa_name>,
00327     TAO_Incremental_Key_Generator> transient_poa_hash_map;
00328 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00329 
00330 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00331   /// Id linear map.
00332   typedef ACE_Map_Manager_Adapter<
00333   poa_name,
00334     TAO_Root_POA *,
00335     TAO_Incremental_Key_Generator> transient_poa_linear_map;
00336 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00337 
00338   /// Id active map.
00339   typedef ACE_Active_Map_Manager_Adapter<
00340   poa_name,
00341     TAO_Root_POA *,
00342     TAO_Ignore_Original_Key_Adapter> transient_poa_active_map;
00343 
00344   /// Base class of the name map.
00345   typedef ACE_Map<
00346   poa_name,
00347     TAO_Root_POA *> persistent_poa_name_map;
00348 
00349   /// Id hash map.
00350   typedef ACE_Hash_Map_Manager_Ex_Adapter<
00351   poa_name,
00352     TAO_Root_POA *,
00353     TAO_ObjectId_Hash,
00354     ACE_Equal_To<PortableServer::ObjectId>,
00355     ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_hash_map;
00356 
00357 #if (TAO_HAS_MINIMUM_POA_MAPS == 0)
00358   /// Id linear map.
00359   typedef ACE_Map_Manager_Adapter<
00360   poa_name,
00361     TAO_Root_POA *,
00362     ACE_Noop_Key_Generator<poa_name> > persistent_poa_name_linear_map;
00363 #endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
00364 
00365   /// Strategy for dispatching a request to a servant.
00366   TAO_Servant_Dispatcher *servant_dispatcher_;
00367 
00368   /// Persistent POA map
00369   persistent_poa_name_map *persistent_poa_name_map_;
00370 
00371   /// Transient POA map
00372   transient_poa_map *transient_poa_map_;
00373 
00374 protected:
00375 
00376   static CORBA::ULong transient_poa_name_size_;
00377 
00378   static void set_transient_poa_name_size (const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters);
00379 
00380   TAO_ORB_Core &orb_core_;
00381 
00382   int enable_locking_;
00383 
00384   TAO_SYNCH_MUTEX thread_lock_;
00385 
00386   ACE_Lock *lock_;
00387 
00388   ACE_Reverse_Lock<ACE_Lock> reverse_lock_;
00389 
00390 public:
00391 
00392   /**
00393    * @class poa_name_iterator
00394    *
00395    * @brief Iterator for a folded poa name.
00396    */
00397   class poa_name_iterator
00398   {
00399   public:
00400 
00401     /// Constructor.
00402     poa_name_iterator (int begin,
00403                        CORBA::ULong size,
00404                        const CORBA::Octet *folded_buffer);
00405 
00406     /// Comparison operators.
00407     bool operator== (const poa_name_iterator &rhs) const;
00408     bool operator!= (const poa_name_iterator &rhs) const;
00409 
00410     /// Dereference operator.
00411     ACE_CString operator* () const;
00412 
00413     /// Prefix advance.
00414     poa_name_iterator &operator++ (void);
00415 
00416   protected:
00417 
00418     CORBA::ULong size_;
00419     CORBA::ULong position_;
00420     const CORBA::Octet *folded_buffer_;
00421     CORBA::ULong last_separator_;
00422   };
00423 
00424   /**
00425    * @class iteratable_poa_name
00426    *
00427    * @brief This class allows iteration over a folded poa name.
00428    */
00429   class iteratable_poa_name
00430   {
00431   public:
00432 
00433     typedef poa_name_iterator iterator;
00434 
00435     iteratable_poa_name (const poa_name &folded_name);
00436 
00437     iterator begin (void) const;
00438     iterator end (void) const;
00439 
00440   protected:
00441 
00442     const poa_name &folded_name_;
00443   };
00444 
00445   friend class TAO::Portable_Server::Non_Servant_Upcall;
00446 
00447   friend class TAO::Portable_Server::Servant_Upcall;
00448 
00449 public:
00450 
00451   /// Pointer to the non-servant upcall in progress.  If no non-servant
00452   /// upcall is in progress, this pointer is zero.
00453   TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress (void) const;
00454 
00455 private:
00456 
00457   /// Helper method to get collocated servant
00458   TAO_ServantBase *get_collocated_servant (const TAO_MProfile &mp);
00459 
00460 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00461   static void release_poa_manager_factory (TAO_POAManager_Factory *factory);
00462 #endif
00463 private:
00464 
00465   /// Condition variable for waiting on non-servant upcalls to end.
00466   TAO_SYNCH_CONDITION non_servant_upcall_condition_;
00467 
00468   /// Pointer to the non-servant upcall in progress.  If no non-servant
00469   /// upcall is in progress, this pointer is zero.
00470   TAO::Portable_Server::Non_Servant_Upcall *non_servant_upcall_in_progress_;
00471 
00472   /// Current nesting level of non_servant_upcalls.
00473   unsigned int non_servant_upcall_nesting_level_;
00474 
00475   /// Id of thread making the non-servant upcall.
00476   ACE_thread_t non_servant_upcall_thread_;
00477 
00478   /// The Root POA
00479   TAO_Root_POA *root_;
00480 
00481 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00482   /// The POAManager factory.
00483   TAO_POAManager_Factory *poa_manager_factory_;
00484 #else
00485   /// The POAManager object reference.
00486   PortableServer::POAManager_var the_poa_manager_;
00487 #endif
00488 
00489   /// The default validator and the beginning of the chain of
00490   /// policy validators.
00491   TAO_POA_Default_Policy_Validator default_validator_;
00492 
00493   /// Save a list of default policies that should be included in
00494   /// every POA (unless overridden).
00495   TAO_POA_Policy_Set default_poa_policies_;
00496 };
00497 
00498 TAO_END_VERSIONED_NAMESPACE_DECL
00499 
00500 #if defined(_MSC_VER)
00501 #pragma warning(pop)
00502 #endif /* _MSC_VER */
00503 
00504 #if defined (__ACE_INLINE__)
00505 # include "tao/PortableServer/Object_Adapter.inl"
00506 #endif /* __ACE_INLINE__ */
00507 
00508 #include /**/ "ace/post.h"
00509 
00510 #endif /* TAO_OBJECT_ADAPTER_H */

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7