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

Generated on Sun Jan 27 13:23:42 2008 for TAO_PortableServer by doxygen 1.3.6