#include <Persistent_Context_Index.h>
Collaboration diagram for TAO_Persistent_Context_Index:
Public Types | |
typedef ACE_Hash_Map_With_Allocator< TAO_Persistent_Index_ExtId, TAO_Persistent_Index_IntId > | CONTEXT_INDEX |
Hash map in which we will store info about each Persistent Naming Context. | |
typedef ACE_Hash_Map_With_Allocator< TAO_Persistent_ExtId, TAO_Persistent_IntId > | CONTEXT |
Hash map used by Persistent Naming Context to keep its state. | |
typedef ACE_Allocator_Adapter< ACE_Malloc< ACE_MMAP_MEMORY_POOL, TAO_SYNCH_MUTEX > > | ALLOCATOR |
Allocator we will be using to make the Naming Service persistent. | |
Public Member Functions | |
TAO_Persistent_Context_Index (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) | |
Constructor. | |
int | open (const ACE_TCHAR *file_name, void *base_address=TAO_NAMING_BASE_ADDR) |
int | init (size_t context_size) |
~TAO_Persistent_Context_Index (void) | |
int | bind (const char *poa_id, ACE_UINT32 *&counter, CONTEXT *hash_map) |
int | unbind (const char *poa_id) |
ACE_Allocator * | allocator (void) |
Return allocator. | |
CORBA::ORB_ptr | orb (void) |
Return orb pointer. | |
CosNaming::NamingContext_ptr | root_context (void) |
Private Member Functions | |
int | recreate_all (void) |
int | create_index (void) |
Helper for the method. | |
int | create_index_helper (void *buffer) |
Private Attributes | |
TAO_SYNCH_MUTEX | lock_ |
ALLOCATOR * | allocator_ |
CONTEXT_INDEX * | index_ |
const ACE_TCHAR * | index_file_ |
Name of the memory-mapped file used by . | |
void * | base_address_ |
Base address for the memory-mapped file. | |
CORBA::ORB_var | orb_ |
PortableServer::POA_var | poa_ |
CosNaming::NamingContext_var | root_context_ |
The reference to the root Naming Context. |
This class creates a memory-mapped file, allocates a hash table from that file, and uses the hash table to store POA id, and table and counter pointers for each Persistent Naming Context. There are methods for adding and deleting entries from this hash table as new Persistent Naming Contexts are created and old ones are destroyed. This hash table facilitates Persistent Naming Context servant initialization upon Naming Server start-up.
Definition at line 47 of file Persistent_Context_Index.h.
|
Allocator we will be using to make the Naming Service persistent.
Definition at line 62 of file Persistent_Context_Index.h. |
|
Hash map used by Persistent Naming Context to keep its state.
Definition at line 58 of file Persistent_Context_Index.h. Referenced by bind(). |
|
Hash map in which we will store info about each Persistent Naming Context.
Definition at line 54 of file Persistent_Context_Index.h. Referenced by create_index(), and create_index_helper(). |
|
Constructor.
Definition at line 82 of file Persistent_Context_Index.cpp.
00084 : allocator_ (0), 00085 index_ (0), 00086 index_file_ (0), 00087 base_address_ (0), 00088 orb_ (CORBA::ORB::_duplicate (orb)), 00089 poa_ (PortableServer::POA::_duplicate (poa)) 00090 { 00091 } |
|
Destructor. The memory mapped file that was opened/created is not deleted, since we want it to keep the state of the Naming Service until the next run. Definition at line 93 of file Persistent_Context_Index.cpp. References ACE_OS::free(), and index_file_.
00094 { 00095 delete allocator_; 00096 ACE_OS::free (reinterpret_cast<void *> (const_cast<ACE_TCHAR *> (index_file_))); 00097 } |
|
Return allocator.
Definition at line 100 of file Persistent_Context_Index.cpp. Referenced by TAO_Persistent_Naming_Context::init(), and TAO_Persistent_Naming_Context::TAO_Persistent_Naming_Context().
00101 { 00102 return allocator_; 00103 } |
|
Create an entry for a Persistent Naming Context in , i.e., a context with , and has just been created, and is registering with us. Definition at line 31 of file Persistent_Context_Index.cpp. References ACE_GUARD_RETURN, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), CONTEXT, ACE_OS::strcpy(), ACE_OS::strlen(), and TAO_SYNCH_MUTEX. Referenced by TAO_Persistent_Naming_Context::make_new_context().
00034 { 00035 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1); 00036 00037 // Allocate memory for items to be stored in the table. 00038 size_t poa_id_len = ACE_OS::strlen (poa_id) + 1; 00039 size_t counter_len = sizeof (ACE_UINT32); 00040 char *ptr = (char *) this->allocator_->malloc (poa_id_len + counter_len); 00041 00042 if (ptr == 0) 00043 return -1; 00044 else 00045 { 00046 // Populate memory with data. 00047 counter = reinterpret_cast<ACE_UINT32 *> (ptr); 00048 *counter = 0; 00049 char * poa_id_ptr = ptr + counter_len; 00050 ACE_OS::strcpy (poa_id_ptr, poa_id); 00051 00052 TAO_Persistent_Index_ExtId name (poa_id_ptr); 00053 TAO_Persistent_Index_IntId entry (counter, hash_map); 00054 int result = -1; 00055 00056 // Do a normal bind. This will fail if there's already an 00057 // entry with the same name. 00058 result = this->index_->bind (name, entry, this->allocator_); 00059 00060 if (result == 1) 00061 { 00062 // Entry already existed so bind failed. Free our dynamically 00063 // allocated memory. 00064 this->allocator_->free ((void *) ptr); 00065 return result; 00066 } 00067 00068 if (result == -1) 00069 // Free our dynamically allocated memory. 00070 this->allocator_->free ((void *) ptr); 00071 else 00072 // If bind() succeed, it will automatically sync 00073 // up the map manager entry. However, we must sync up our 00074 // name/value memory. 00075 this->allocator_->sync (ptr, poa_id_len + counter_len); 00076 00077 return result; 00078 } 00079 } |
|
Helper for the method.
Definition at line 232 of file Persistent_Context_Index.cpp. References ACE_OS::access(), ACE_ERROR, ACE_ERROR_RETURN, ACE_NEW_RETURN, CONTEXT_INDEX, create_index_helper(), F_OK, index_file_, LM_ERROR, MAXNAMELEN, MAXPATHLEN, ACE_OS::strlen(), and TAO_NAMING_CONTEXT_INDEX. Referenced by open().
00233 { 00234 // Make sure that the file name is of the legal length. 00235 if (ACE_OS::strlen (index_file_) >= MAXNAMELEN + MAXPATHLEN) 00236 { 00237 errno = ENAMETOOLONG; 00238 return -1; 00239 } 00240 00241 #if !defined (CHORUS) 00242 ACE_MMAP_Memory_Pool::OPTIONS options (base_address_); 00243 #else 00244 // Use base address == 0, don't use a fixed address. 00245 ACE_MMAP_Memory_Pool::OPTIONS options (0, 00246 0, 00247 0, 00248 ACE_CHORUS_LOCAL_NAME_SPACE_T_SIZE); 00249 #endif /* CHORUS */ 00250 00251 // Create the allocator with the appropriate options. The name used 00252 // for the lock is the same as one used for the file. 00253 ACE_NEW_RETURN (this->allocator_, 00254 ALLOCATOR (this->index_file_, 00255 this->index_file_, 00256 &options), 00257 -1); 00258 00259 #if !defined (ACE_LACKS_ACCESS) 00260 // Now check if the backing store has been created successfully. 00261 if (ACE_OS::access (this->index_file_, F_OK) != 0) 00262 ACE_ERROR_RETURN ((LM_ERROR, 00263 "create_index\n"), 00264 -1); 00265 #endif /* ACE_LACKS_ACCESS */ 00266 00267 void *context_index = 0; 00268 00269 // This is the easy case since if we find hash table in the 00270 // memory-mapped file we know it's already initialized. 00271 if (this->allocator_->find (TAO_NAMING_CONTEXT_INDEX, context_index) == 0) 00272 this->index_ = (CONTEXT_INDEX *) context_index; 00273 00274 // Create a new <index_> (because we've just created a new 00275 // memory-mapped file). 00276 else 00277 { 00278 size_t index_size = sizeof (CONTEXT_INDEX); 00279 context_index = this->allocator_->malloc (index_size); 00280 00281 if (context_index == 0 00282 || create_index_helper (context_index) == -1 00283 || this->allocator_->bind (TAO_NAMING_CONTEXT_INDEX, 00284 context_index) == -1) 00285 { 00286 // Attempt to clean up. 00287 ACE_ERROR ((LM_ERROR, 00288 "create_index\n")); 00289 this->allocator_->remove (); 00290 return -1; 00291 } 00292 } 00293 return 0; 00294 } |
|
Helper for method: places hash table into an allocated space. Definition at line 297 of file Persistent_Context_Index.cpp. References CONTEXT_INDEX. Referenced by create_index().
00298 { 00299 this->index_ = new (buffer) CONTEXT_INDEX (this->allocator_); 00300 return 0; 00301 } |
|
If contains no entries (i.e., was just created), create a root Persistent Naming Context servant with table of size , and make an entry for it in the . If contains entries, create a Persistent Naming Context servant for each entry. Return 0 on success and -1 on failure. Definition at line 131 of file Persistent_Context_Index.cpp. References ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_Null_Mutex >::current_size(), TAO_Persistent_Naming_Context::make_new_context(), recreate_all(), root_context_, and TAO_ROOT_NAMING_CONTEXT. Referenced by TAO_Naming_Server::init_new_naming().
00132 { 00133 // Note: in case of an early exit from this (or helper) function due 00134 // to an error condition, we rely on POA to clean up all of the servants 00135 // already registered with it. 00136 00137 // Return value of this function (necessary to keep compilers quiet). 00138 int status = 0; 00139 00140 if (index_->current_size () == 0) 00141 // CASE 1:there are no Naming Contexts registered. We need to create 00142 // one. 00143 { 00144 00145 this->root_context_ = 00146 TAO_Persistent_Naming_Context::make_new_context (poa_.in (), 00147 TAO_ROOT_NAMING_CONTEXT, 00148 context_size, 00149 this); 00150 } 00151 00152 else 00153 // CASE 2:Recreate all Naming Contexts. 00154 status = recreate_all (); 00155 00156 return status; 00157 } |
|
Create ACE_Allocator, open/create memory-mapped file with the specified file name/base address. Find or allocate . Return 0 on success or -1 on failure. Definition at line 118 of file Persistent_Context_Index.cpp. References create_index(), index_file_, and ACE_OS::strdup(). Referenced by TAO_Naming_Server::init_new_naming().
00120 { 00121 this->base_address_ = base_address; 00122 00123 index_file_ = ACE_OS::strdup (file_name); 00124 if (index_file_ == 0) 00125 return -1; 00126 00127 return create_index (); 00128 } |
|
Return orb pointer.
Definition at line 112 of file Persistent_Context_Index.cpp. Referenced by TAO_Persistent_Naming_Context::TAO_Persistent_Naming_Context().
00113 { 00114 return orb_.in (); 00115 } |
|
Helper for the method. Iterates over , and creates a servant for each entry. Definition at line 160 of file Persistent_Context_Index.cpp. References ACE_DEBUG, ACE_NEW_RETURN, LM_DEBUG, ACE_Auto_Basic_Ptr< X >::release(), root_context_, and TAO_debug_level. Referenced by init().
00161 { 00162 CONTEXT_INDEX::ITERATOR *index_iter = 0; 00163 00164 ACE_NEW_RETURN (index_iter, 00165 (CONTEXT_INDEX::ITERATOR) (*index_), 00166 -1); 00167 00168 ACE_Auto_Basic_Ptr<CONTEXT_INDEX::ITERATOR> it (index_iter); 00169 00170 // Because of broken old g++!!! 00171 typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_Index_ExtId, 00172 TAO_Persistent_Index_IntId> IND_DEF; 00173 00174 IND_DEF::ENTRY *entry = 0; 00175 00176 if (TAO_debug_level > 0) 00177 ACE_DEBUG ((LM_DEBUG, "Starting to recreate Naming Contexts from the file... \n")); 00178 00179 // For each entry in <index_>, create a Naming Context servant. 00180 do 00181 { 00182 index_iter->next (entry); 00183 00184 // Put together a servant for the new Naming Context. 00185 00186 TAO_Persistent_Naming_Context *context_impl = 0; 00187 ACE_NEW_RETURN (context_impl, 00188 TAO_Persistent_Naming_Context (poa_.in (), 00189 entry->ext_id_.poa_id_, 00190 this, 00191 entry->int_id_.hash_map_, 00192 entry->int_id_.counter_), 00193 -1); 00194 00195 00196 // Put <context_impl> into the auto pointer temporarily, in case next 00197 // allocation fails. 00198 ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); 00199 00200 TAO_Naming_Context *context = 0; 00201 ACE_NEW_RETURN (context, 00202 TAO_Naming_Context (context_impl), 00203 -1); 00204 00205 // Let <implementation> know about it's <interface>. 00206 context_impl->interface (context); 00207 00208 // Release auto pointer and start using reference counting to 00209 // control our servant. 00210 temp.release (); 00211 PortableServer::ServantBase_var s = context; 00212 00213 // Register with the POA. 00214 PortableServer::ObjectId_var id = 00215 PortableServer::string_to_ObjectId (entry->ext_id_.poa_id_); 00216 00217 this->poa_->activate_object_with_id (id.in (), 00218 context); 00219 00220 CosNaming::NamingContext_var result = context->_this (); 00221 00222 // If this is the root Naming Context, take a note of it. 00223 if (context_impl->root ()) 00224 this->root_context_= result._retn (); 00225 00226 } while (index_iter->advance ()); 00227 00228 return 0; 00229 } |
|
Return a pointer to the root Naming Context (returns a copy - must be deallocated by the user). Definition at line 106 of file Persistent_Context_Index.cpp. References root_context_. Referenced by TAO_Naming_Server::init_new_naming().
00107 { 00108 return CosNaming::NamingContext::_duplicate (root_context_.in ()); 00109 } |
|
Remove an entry for the Persistent Naming Context with from (i.e., this context has just been destroyed). Definition at line 14 of file Persistent_Context_Index.cpp. References ACE_GUARD_RETURN, TAO_Persistent_Index_IntId::counter_, TAO_SYNCH_MUTEX, and ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::unbind(). Referenced by TAO_Persistent_Naming_Context::~TAO_Persistent_Naming_Context().
00015 { 00016 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, -1); 00017 00018 TAO_Persistent_Index_ExtId name (poa_id); 00019 TAO_Persistent_Index_IntId entry; 00020 if (this->index_->unbind (name, entry, this->allocator_) != 0) 00021 return -1; 00022 else 00023 { 00024 // Free up the memory we allocated in bind(). 00025 this->allocator_->free ((void *) (entry.counter_)); 00026 return 0; 00027 } 00028 } |
|
Allocator that deals out memory from a memory-mapped file. We use it here, and in TAO_Persistent_Naming_Context, whenever we deal with data that should be kept in persistent store. Definition at line 142 of file Persistent_Context_Index.h. |
|
Base address for the memory-mapped file.
Definition at line 152 of file Persistent_Context_Index.h. |
|
Hash map where we keep entries for all Persistent Naming Contexts. Definition at line 146 of file Persistent_Context_Index.h. |
|
Name of the memory-mapped file used by .
Definition at line 149 of file Persistent_Context_Index.h. Referenced by create_index(), open(), and ~TAO_Persistent_Context_Index(). |
|
Lock to prevent multiple threads from modifying entries in the simultanneously. Definition at line 135 of file Persistent_Context_Index.h. |
|
ORB. We use it for several object_to_string conversions, and keep it around for Persistent Naming Contexts' use. Definition at line 156 of file Persistent_Context_Index.h. |
|
POA under which to register Persistent Naming Context servants during start-up. Definition at line 160 of file Persistent_Context_Index.h. |
|
The reference to the root Naming Context.
Definition at line 163 of file Persistent_Context_Index.h. Referenced by init(), recreate_all(), and root_context(). |