Persistent_Context_Index.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Persistent_Context_Index.h
00006  *
00007  *  Persistent_Context_Index.h,v 1.25 2006/03/14 06:14:34 jtc Exp
00008  *
00009  *  @author Marina Spivak <marina@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_PERSISTENT_CONTEXT_INDEX_H
00015 #define TAO_PERSISTENT_CONTEXT_INDEX_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "orbsvcs/Naming/Persistent_Entries.h"
00019 #include "orbsvcs/Naming/naming_serv_export.h"
00020 #include "orbsvcs/Naming/nsconf.h"
00021 #include "tao/PortableServer/PortableServer.h"
00022 
00023 #include "ace/Malloc_T.h"
00024 #include "ace/MMAP_Memory_Pool.h"
00025 
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 /**
00029  * @class TAO_Persistent_Context_Index
00030  *
00031  * @brief This class facilitates implementation of Persistent
00032  * Naming Service.  It keeps track, centrally, of several pieces of
00033  * info for each Persistent Naming Context, allowing to perform the
00034  * initialization necessary for each Naming Context to
00035  * restore the state of the Naming Service from persistent storage
00036  * on server start-up.
00037  *
00038  * This class creates a memory-mapped file, allocates a hash
00039  * table from that file, and uses the hash table to store POA id,
00040  * and table and counter pointers for each Persistent Naming
00041  * Context.  There are methods for adding and deleting entries
00042  * from this hash table as new Persistent Naming Contexts are
00043  * created and old ones are destroyed.  This hash table
00044  * facilitates Persistent Naming Context servant initialization
00045  * upon Naming Server start-up.
00046  */
00047 class TAO_Naming_Serv_Export TAO_Persistent_Context_Index
00048 {
00049 public:
00050   // = Some typedefs for convenience.
00051 
00052   /// Hash map in which we will store info about each Persistent Naming Context.
00053   typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_Index_ExtId,
00054     TAO_Persistent_Index_IntId> CONTEXT_INDEX;
00055 
00056   /// Hash map used by Persistent Naming Context to keep its state.
00057   typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId,
00058     TAO_Persistent_IntId> CONTEXT;
00059 
00060   /// Allocator we will be using to make the Naming Service persistent.
00061   typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MMAP_MEMORY_POOL, TAO_SYNCH_MUTEX>
00062   > ALLOCATOR;
00063 
00064   // = Initialization and termination methods.
00065 
00066   /// Constructor.
00067   TAO_Persistent_Context_Index (CORBA::ORB_ptr orb,
00068                                 PortableServer::POA_ptr poa);
00069 
00070   /**
00071    * Create ACE_Allocator, open/create memory-mapped file with the
00072    * specified file name/base address.  Find or allocate <index_>.
00073    * Return 0 on success or -1 on failure.
00074    */
00075   int open (const ACE_TCHAR *file_name,
00076             void * base_address = TAO_NAMING_BASE_ADDR);
00077 
00078   /**
00079    * If <index_> contains no entries (i.e., was just created), create
00080    * a root Persistent Naming Context servant with table of size
00081    * <context_size>, and make an entry for it
00082    * in the <index_>.  If <index_> contains entries, create a
00083    * Persistent Naming Context servant for each entry.  Return 0 on
00084    * success and -1 on failure.
00085    */
00086   int init (size_t context_size);
00087 
00088   /**
00089    * Destructor.  The memory mapped file that was opened/created is
00090    * not deleted, since we want it to keep the state of the Naming
00091    * Service until the next run.
00092    */
00093   ~TAO_Persistent_Context_Index (void);
00094 
00095   // = Methods for adding/removing entries.
00096 
00097   /**
00098    * Create an entry for a Persistent Naming Context in <index_>,
00099    * i.e., a context with <poa_id>, <counter> and <hash_map> has just
00100    * been created, and is registering with us.
00101    */
00102   int bind (const char *poa_id,
00103             ACE_UINT32 *&counter,
00104             CONTEXT *hash_map);
00105 
00106   /// Remove an entry for the Persistent Naming Context with <poa_id>
00107   /// from <index_> (i.e., this context has just been destroyed).
00108   int unbind (const char *poa_id);
00109 
00110   // = Accessors.
00111 
00112   /// Return allocator.
00113   ACE_Allocator *allocator (void);
00114 
00115   /// Return orb pointer.
00116   CORBA::ORB_ptr orb (void);
00117 
00118   /// Return a pointer to the root Naming Context (returns a copy - must be
00119   /// deallocated by the user).
00120   CosNaming::NamingContext_ptr root_context (void);
00121 
00122 private:
00123 
00124   /// Helper for the <init> method.  Iterates over <index_>, and
00125   /// creates a servant for each entry.
00126   int recreate_all (void);
00127 
00128   /// Helper for the <open> method.
00129   int create_index (void);
00130 
00131   /// Helper for <create_index> method: places hash table into an
00132   /// allocated space.
00133   int create_index_helper (void *buffer);
00134 
00135   /// Lock to prevent multiple threads from modifying entries in the
00136   /// <index_> simultanneously.
00137   TAO_SYNCH_MUTEX lock_;
00138 
00139   /**
00140    * Allocator that deals out memory from a memory-mapped file.  We
00141    * use it here, and in TAO_Persistent_Naming_Context, whenever we
00142    * deal with data that should be kept in persistent store.
00143    */
00144   ALLOCATOR *allocator_;
00145 
00146   /// Hash map where we keep entries for all Persistent Naming
00147   /// Contexts.
00148   CONTEXT_INDEX *index_;
00149 
00150   /// Name of the memory-mapped file used by <allocator_>.
00151   const ACE_TCHAR *index_file_;
00152 
00153   /// Base address for the memory-mapped file.
00154   void *base_address_;
00155 
00156   /// ORB.  We use it for several object_to_string conversions, and
00157   /// keep it around for Persistent Naming Contexts' use.
00158   CORBA::ORB_var orb_;
00159 
00160   /// POA under which to register Persistent Naming Context servants
00161   /// during start-up.
00162   PortableServer::POA_var poa_;
00163 
00164   /// The reference to the root Naming Context.
00165   CosNaming::NamingContext_var root_context_;
00166 };
00167 
00168 TAO_END_VERSIONED_NAMESPACE_DECL
00169 
00170 #include /**/ "ace/post.h"
00171 #endif /* TAO_PERSISTENT_CONTEXT_INDEX_H */

Generated on Thu Nov 9 13:57:02 2006 for TAO_CosNaming by doxygen 1.3.6