#include <Persistent_Naming_Context.h>
Inheritance diagram for TAO_Persistent_Naming_Context:
Public Types | |
typedef TAO_Persistent_Bindings_Map::HASH_MAP | HASH_MAP |
Underlying data structure - typedef for ease of use. | |
Public Member Functions | |
TAO_Persistent_Naming_Context (PortableServer::POA_ptr poa, const char *poa_id, TAO_Persistent_Context_Index *context_index) | |
int | init (size_t hash_table_size=ACE_DEFAULT_MAP_SIZE) |
TAO_Persistent_Naming_Context (PortableServer::POA_ptr poa, const char *poa_id, TAO_Persistent_Context_Index *context_index, HASH_MAP *map, ACE_UINT32 *counter) | |
virtual | ~TAO_Persistent_Naming_Context (void) |
Destructor. | |
virtual CosNaming::NamingContext_ptr | new_context (void) |
virtual void | list (CORBA::ULong how_many, CosNaming::BindingList_out &bl, CosNaming::BindingIterator_out &bi) |
Static Public Member Functions | |
CosNaming::NamingContext_ptr | make_new_context (PortableServer::POA_ptr poa, const char *poa_id, size_t context_size, TAO_Persistent_Context_Index *ind) |
Protected Member Functions | |
void | set_cleanup_level (int level) |
Protected Attributes | |
ACE_UINT32 * | counter_ |
TAO_Persistent_Bindings_Map * | persistent_context_ |
TAO_Persistent_Context_Index * | index_ |
This class provides a persistent implementation of the NamingContext functionality, i.e., the state is preserved across process boundaries. Derives from TAO_Hash_Naming_Context and uses TAO_Persistent_Bindings_Map to store name to object bindings.
Definition at line 164 of file Persistent_Naming_Context.h.
|
Underlying data structure - typedef for ease of use.
Definition at line 168 of file Persistent_Naming_Context.h. |
|
Constructor. MUST be followed up by to allocate the underlying data structure from persistent storage! Definition at line 253 of file Persistent_Naming_Context.cpp. References ACE_NEW, TAO_Persistent_Context_Index::orb(), and persistent_context_.
00257 : TAO_Hash_Naming_Context (poa, 00258 poa_id), 00259 counter_ (0), 00260 persistent_context_ (0), 00261 index_ (context_index) 00262 { 00263 ACE_NEW (this->persistent_context_, 00264 TAO_Persistent_Bindings_Map (context_index->orb ())); 00265 00266 // Set the superclass pointer. 00267 context_ = persistent_context_; 00268 } |
|
Constructor that takes in preallocated data structure and takes ownership of it. This constructor is for 'recreating' servants from persistent state. Definition at line 270 of file Persistent_Naming_Context.cpp. References ACE_NEW, TAO_Persistent_Context_Index::allocator(), TAO_Persistent_Context_Index::orb(), persistent_context_, and TAO_Persistent_Bindings_Map::set().
00275 : TAO_Hash_Naming_Context (poa, 00276 poa_id), 00277 counter_ (counter), 00278 persistent_context_ (0), 00279 index_ (context_index) 00280 { 00281 ACE_NEW (this->persistent_context_, 00282 TAO_Persistent_Bindings_Map (context_index->orb ())); 00283 00284 // Set the superclass pointer. 00285 context_ = persistent_context_; 00286 00287 persistent_context_->set (map, index_->allocator ()); 00288 } |
|
Destructor.
Definition at line 296 of file Persistent_Naming_Context.cpp. References TAO_Persistent_Bindings_Map::destroy(), persistent_context_, and TAO_Persistent_Context_Index::unbind().
00297 { 00298 // Perform appropriate cleanup based on the destruction level specified. 00299 00300 if (this->destroyed_ > 1) 00301 { 00302 // Remove ourselves from context index. 00303 index_->unbind (poa_id_.c_str ()); 00304 // Remove the underlying data structure from persistent storage. 00305 persistent_context_->destroy (); 00306 } 00307 else if (this->destroyed_ == 1) 00308 // Remove the underlying data structure from persistent storage. 00309 persistent_context_->destroy (); 00310 } |
|
Allocate the underlying data structure from persistent storage. Returns 0 on success and -1 on failure. Definition at line 291 of file Persistent_Naming_Context.cpp. References TAO_Persistent_Context_Index::allocator(), TAO_Persistent_Bindings_Map::open(), and persistent_context_. Referenced by make_new_context().
00292 { 00293 return persistent_context_->open (hash_table_size, index_->allocator ()); 00294 } |
|
Returns at most the requested number of bindings in . If the naming context contains additional bindings, they are returned with a BindingIterator. In the naming context does not contain any additional bindings returned as null. Implements TAO_Naming_Context_Impl. Definition at line 413 of file Persistent_Naming_Context.cpp. References ACE_GUARD_THROW_EX, ACE_NEW_THROW_EX, CosNaming::BindingList, TAO_Bindings_Map::current_size(), TAO_Persistent_Bindings_Map::map(), persistent_context_, ACE_Auto_Basic_Ptr< X >::release(), ACE_OS::sprintf(), and TAO_SYNCH_RECURSIVE_MUTEX.
00416 { 00417 // Allocate nil out parameters in case we won't be able to complete 00418 // the operation. 00419 bi = CosNaming::BindingIterator::_nil (); 00420 ACE_NEW_THROW_EX (bl, 00421 CosNaming::BindingList (0), 00422 CORBA::NO_MEMORY ()); 00423 00424 // Obtain a lock before we proceed with the operation. 00425 ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, 00426 ace_mon, 00427 this->lock_, 00428 CORBA::INTERNAL ()); 00429 00430 // Check to make sure this object didn't have <destroy> method 00431 // invoked on it. 00432 if (this->destroyed_) 00433 throw CORBA::OBJECT_NOT_EXIST (); 00434 00435 // Dynamically allocate hash map iterator. 00436 HASH_MAP::ITERATOR *hash_iter = 0; 00437 ACE_NEW_THROW_EX (hash_iter, 00438 HASH_MAP::ITERATOR 00439 (*persistent_context_->map ()), 00440 CORBA::NO_MEMORY ()); 00441 00442 // Store <hash_iter temporarily in auto pointer, in case we'll have 00443 // some failures and throw an exception. 00444 ACE_Auto_Basic_Ptr<HASH_MAP::ITERATOR> temp (hash_iter); 00445 00446 // Silliness below is required because of broken old g++!!! E.g., 00447 // without it, we could have just said HASH_MAP::ITERATOR everywhere we use ITER_DEF. 00448 typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ITERATOR ITER_DEF; 00449 typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ENTRY ENTRY_DEF; 00450 00451 // Typedef to the type of BindingIterator servant for ease of use. 00452 typedef TAO_Bindings_Iterator<ITER_DEF, ENTRY_DEF> ITER_SERVANT; 00453 00454 // A pointer to BindingIterator servant. 00455 ITER_SERVANT *bind_iter = 0; 00456 00457 // Number of bindings that will go into the BindingList. 00458 CORBA::ULong n; 00459 00460 // Calculate number of bindings that will go into bl. 00461 if (this->context_->current_size () > how_many) 00462 n = how_many; 00463 else 00464 n = static_cast<CORBA::ULong> (this->context_->current_size ()); 00465 00466 // Use hash iterator to populate a BindingList with bindings. 00467 bl->length (n); 00468 00469 ENTRY_DEF *hash_entry = 0; 00470 00471 for (CORBA::ULong i = 0; i < n; i++) 00472 { 00473 hash_iter->next (hash_entry); 00474 hash_iter->advance (); 00475 00476 if (ITER_SERVANT::populate_binding (hash_entry, bl[i]) == 0) 00477 throw CORBA::NO_MEMORY(); 00478 } 00479 00480 // Now we are done with the BindingsList, and we can follow up on 00481 // the iterator business. 00482 00483 // If we do not need to pass back BindingIterator. 00484 if (this->context_->current_size () <= how_many) 00485 return; 00486 else 00487 { 00488 // Create a BindingIterator for return. 00489 ACE_NEW_THROW_EX (bind_iter, 00490 ITER_SERVANT (this, hash_iter, this->poa_.in (), this->lock_), 00491 CORBA::NO_MEMORY ()); 00492 00493 // Release <hash_iter> from auto pointer, and start using the 00494 // reference counting to control our servant. 00495 temp.release (); 00496 PortableServer::ServantBase_var iter = bind_iter; 00497 00498 // Increment reference count on this Naming Context, so it doesn't get 00499 // deleted before the BindingIterator servant gets deleted. 00500 interface_->_add_ref (); 00501 00502 // Register with the POA. 00503 char poa_id[BUFSIZ]; 00504 ACE_OS::sprintf (poa_id, 00505 "%s_%d", 00506 this->poa_id_.c_str (), 00507 (*this->counter_)++); 00508 PortableServer::ObjectId_var id = 00509 PortableServer::string_to_ObjectId (poa_id); 00510 00511 this->poa_->activate_object_with_id (id.in (), 00512 bind_iter); 00513 00514 bi = bind_iter->_this (); 00515 } 00516 } |
|
This utility method factors out the code needed to create a new Persistent Naming Context servant and activate it under the specified POA with the specified id. This function is static so that the code can be used, both from inside the class (e.g., ), and from outside (e.g., Naming_Utils.cpp). Definition at line 319 of file Persistent_Naming_Context.cpp. References ACE_NEW_THROW_EX, TAO_Persistent_Context_Index::bind(), counter_, init(), TAO_Persistent_Bindings_Map::map(), persistent_context_, TAO_Hash_Naming_Context::poa_id_, ACE_Auto_Basic_Ptr< X >::release(), and set_cleanup_level(). Referenced by TAO_Persistent_Context_Index::init(), and new_context().
00323 { 00324 // Store the stub we will return here. 00325 CosNaming::NamingContext_var result; 00326 00327 // Put together a servant for the new Naming Context. 00328 00329 TAO_Persistent_Naming_Context *context_impl = 0; 00330 ACE_NEW_THROW_EX (context_impl, 00331 TAO_Persistent_Naming_Context (poa, 00332 poa_id, 00333 ind), 00334 CORBA::NO_MEMORY ()); 00335 00336 // Put <context_impl> into the auto pointer temporarily, in case next 00337 // allocation fails. 00338 ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); 00339 00340 if (context_impl->init (context_size) == -1) 00341 throw CORBA::NO_MEMORY (); 00342 00343 // Insure appropriate cleanup in case of exception conditions ahead. 00344 context_impl->set_cleanup_level (1); 00345 00346 // Register with the index of Naming Contexts. 00347 if (ind->bind (context_impl->poa_id_.c_str (), 00348 context_impl->counter_, 00349 context_impl->persistent_context_->map ()) == -1) 00350 throw CORBA::INTERNAL (); 00351 00352 // Insure appropriate cleanup in case of exception conditions ahead. 00353 context_impl->set_cleanup_level (2); 00354 00355 TAO_Naming_Context *context = 0; 00356 ACE_NEW_THROW_EX (context, 00357 TAO_Naming_Context (context_impl), 00358 CORBA::NO_MEMORY ()); 00359 00360 // Let <implementation> know about it's <interface>. 00361 context_impl->interface (context); 00362 00363 // Release auto pointer, and start using reference counting to 00364 // control our servant. 00365 temp.release (); 00366 PortableServer::ServantBase_var s = context; 00367 00368 // Register the new context with the POA. 00369 PortableServer::ObjectId_var id = 00370 PortableServer::string_to_ObjectId (poa_id); 00371 00372 poa->activate_object_with_id (id.in (), 00373 context); 00374 00375 result = context->_this (); 00376 00377 // Everything went smoothly, without errors - we don't need any cleanup. 00378 context_impl->set_cleanup_level (0); 00379 00380 return result._retn (); 00381 } |
|
This operation returns a new naming context implemented by the same naming server in which the operation was invoked. The context is not bound. Implements TAO_Naming_Context_Impl. Definition at line 384 of file Persistent_Naming_Context.cpp. References ACE_GUARD_THROW_EX, make_new_context(), persistent_context_, ACE_OS::sprintf(), TAO_SYNCH_RECURSIVE_MUTEX, and TAO_Persistent_Bindings_Map::total_size().
00385 { 00386 ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, 00387 ace_mon, 00388 this->lock_, 00389 CORBA::INTERNAL ()); 00390 00391 // Check to make sure this object didn't have <destroy> method 00392 // invoked on it. 00393 if (this->destroyed_) 00394 throw CORBA::OBJECT_NOT_EXIST (); 00395 00396 // Generate a POA id for the new context. 00397 char poa_id[BUFSIZ]; 00398 ACE_OS::sprintf (poa_id, 00399 "%s_%d", 00400 this->poa_id_.c_str (), 00401 (*this->counter_)++); 00402 00403 CosNaming::NamingContext_var result = 00404 make_new_context (this->poa_.in (), 00405 poa_id, 00406 this->persistent_context_->total_size (), 00407 this->index_); 00408 00409 return result._retn (); 00410 } |
|
Set flag (inherited from TAO_Hash_Naming_Context) to . Legal values for are 0, 1, and 2. The values specify the extent of cleanup that should take place in the context's destructor: '0' - no cleanup (e.g., if the context goes out of scope, but it's state is to remain in persistent storage); '1' - free up the underlying data structure in persistent storage (e.g., if the initialization of this context was only partially completed due to some failures, and we need to roll back); '2' - free up the underlying data structure, and deregister this naming context from its (e.g., if the context had method invoked and needs to be completely removed from existence). Definition at line 313 of file Persistent_Naming_Context.cpp. Referenced by make_new_context().
00314 { 00315 this->destroyed_ = level; 00316 } |
|
Counter used for generation of POA ids for children Naming Contexts. Definition at line 248 of file Persistent_Naming_Context.h. Referenced by make_new_context(). |
|
A pointer to the index object of this naming service: it keeps track of all the naming contexts created. Every time we make a new context or destroy one, we need to make an entry there. Also, we get the allocator needed to initialize us from this guy. Definition at line 265 of file Persistent_Naming_Context.h. |
|
A pointer to the underlying data structure used to store name bindings. While our superclass (TAO_Hash_Naming_Context) also maintains a pointer to the data structure, keeping this pointer around saves us from the need to downcast when invoking non-virtual methods. Definition at line 257 of file Persistent_Naming_Context.h. Referenced by init(), list(), make_new_context(), new_context(), TAO_Persistent_Naming_Context(), and ~TAO_Persistent_Naming_Context(). |