#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 | |
static 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.
TAO_Persistent_Naming_Context::TAO_Persistent_Naming_Context | ( | PortableServer::POA_ptr | poa, | |
const char * | poa_id, | |||
TAO_Persistent_Context_Index * | context_index | |||
) |
Constructor. MUST be followed up by <init> to allocate the underlying data structure from persistent storage!
Definition at line 239 of file Persistent_Naming_Context.cpp.
References ACE_NEW, TAO_Hash_Naming_Context::context_, TAO_Persistent_Context_Index::orb(), and persistent_context_.
00243 : TAO_Hash_Naming_Context (poa, 00244 poa_id), 00245 counter_ (0), 00246 persistent_context_ (0), 00247 index_ (context_index) 00248 { 00249 ACE_NEW (this->persistent_context_, 00250 TAO_Persistent_Bindings_Map (context_index->orb ())); 00251 00252 // Set the superclass pointer. 00253 context_ = persistent_context_; 00254 }
TAO_Persistent_Naming_Context::TAO_Persistent_Naming_Context | ( | PortableServer::POA_ptr | poa, | |
const char * | poa_id, | |||
TAO_Persistent_Context_Index * | context_index, | |||
HASH_MAP * | map, | |||
ACE_UINT32 * | counter | |||
) |
Constructor that takes in preallocated data structure and takes ownership of it. This constructor is for 'recreating' servants from persistent state.
Definition at line 256 of file Persistent_Naming_Context.cpp.
References ACE_NEW, TAO_Persistent_Context_Index::allocator(), TAO_Hash_Naming_Context::context_, index_, TAO_Persistent_Context_Index::orb(), persistent_context_, and TAO_Persistent_Bindings_Map::set().
00261 : TAO_Hash_Naming_Context (poa, 00262 poa_id), 00263 counter_ (counter), 00264 persistent_context_ (0), 00265 index_ (context_index) 00266 { 00267 ACE_NEW (this->persistent_context_, 00268 TAO_Persistent_Bindings_Map (context_index->orb ())); 00269 00270 // Set the superclass pointer. 00271 context_ = persistent_context_; 00272 00273 persistent_context_->set (map, index_->allocator ()); 00274 }
TAO_Persistent_Naming_Context::~TAO_Persistent_Naming_Context | ( | void | ) | [virtual] |
Destructor.
Definition at line 282 of file Persistent_Naming_Context.cpp.
References ACE_String_Base< CHAR >::c_str(), TAO_Persistent_Bindings_Map::destroy(), index_, persistent_context_, TAO_Hash_Naming_Context::poa_id_, and TAO_Persistent_Context_Index::unbind().
00283 { 00284 // Perform appropriate cleanup based on the destruction level specified. 00285 00286 if (this->destroyed_ > 1) 00287 { 00288 // Remove ourselves from context index. 00289 index_->unbind (poa_id_.c_str ()); 00290 // Remove the underlying data structure from persistent storage. 00291 persistent_context_->destroy (); 00292 } 00293 else if (this->destroyed_ == 1) 00294 // Remove the underlying data structure from persistent storage. 00295 persistent_context_->destroy (); 00296 }
int TAO_Persistent_Naming_Context::init | ( | size_t | hash_table_size = ACE_DEFAULT_MAP_SIZE |
) |
Allocate the underlying data structure from persistent storage. Returns 0 on success and -1 on failure.
Definition at line 277 of file Persistent_Naming_Context.cpp.
References TAO_Persistent_Context_Index::allocator(), index_, TAO_Persistent_Bindings_Map::open(), and persistent_context_.
Referenced by make_new_context().
00278 { 00279 return persistent_context_->open (hash_table_size, index_->allocator ()); 00280 }
void TAO_Persistent_Naming_Context::list | ( | CORBA::ULong | how_many, | |
CosNaming::BindingList_out & | bl, | |||
CosNaming::BindingIterator_out & | bi | |||
) | [virtual] |
Returns at most the requested number of bindings <how_many> in <bl>. If the naming context contains additional bindings, they are returned with a BindingIterator. In the naming context does not contain any additional bindings <bi> returned as null.
Implements TAO_Naming_Context_Impl.
Definition at line 399 of file Persistent_Naming_Context.cpp.
References ACE_GUARD_THROW_EX, ACE_NEW_THROW_EX, TAO_Hash_Naming_Context::context_, counter_, TAO_Bindings_Map::current_size(), TAO_Hash_Naming_Context::interface_, TAO_Hash_Naming_Context::lock_, TAO_Persistent_Bindings_Map::map(), persistent_context_, TAO_Hash_Naming_Context::poa_, ACE_OS::sprintf(), and TAO_SYNCH_RECURSIVE_MUTEX.
00402 { 00403 // Allocate nil out parameters in case we won't be able to complete 00404 // the operation. 00405 bi = CosNaming::BindingIterator::_nil (); 00406 ACE_NEW_THROW_EX (bl, 00407 CosNaming::BindingList (0), 00408 CORBA::NO_MEMORY ()); 00409 00410 // Obtain a lock before we proceed with the operation. 00411 ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, 00412 ace_mon, 00413 this->lock_, 00414 CORBA::INTERNAL ()); 00415 00416 // Check to make sure this object didn't have <destroy> method 00417 // invoked on it. 00418 if (this->destroyed_) 00419 throw CORBA::OBJECT_NOT_EXIST (); 00420 00421 // Dynamically allocate hash map iterator. 00422 HASH_MAP::ITERATOR *hash_iter = 0; 00423 ACE_NEW_THROW_EX (hash_iter, 00424 HASH_MAP::ITERATOR 00425 (*persistent_context_->map ()), 00426 CORBA::NO_MEMORY ()); 00427 00428 // Store <hash_iter temporarily in auto pointer, in case we'll have 00429 // some failures and throw an exception. 00430 ACE_Auto_Basic_Ptr<HASH_MAP::ITERATOR> temp (hash_iter); 00431 00432 // Silliness below is required because of broken old g++!!! E.g., 00433 // without it, we could have just said HASH_MAP::ITERATOR everywhere we use ITER_DEF. 00434 typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ITERATOR ITER_DEF; 00435 typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_ExtId, TAO_Persistent_IntId>::ENTRY ENTRY_DEF; 00436 00437 // Typedef to the type of BindingIterator servant for ease of use. 00438 typedef TAO_Bindings_Iterator<ITER_DEF, ENTRY_DEF> ITER_SERVANT; 00439 00440 // A pointer to BindingIterator servant. 00441 ITER_SERVANT *bind_iter = 0; 00442 00443 // Number of bindings that will go into the BindingList. 00444 CORBA::ULong n; 00445 00446 // Calculate number of bindings that will go into bl. 00447 if (this->context_->current_size () > how_many) 00448 n = how_many; 00449 else 00450 n = static_cast<CORBA::ULong> (this->context_->current_size ()); 00451 00452 // Use hash iterator to populate a BindingList with bindings. 00453 bl->length (n); 00454 00455 ENTRY_DEF *hash_entry = 0; 00456 00457 for (CORBA::ULong i = 0; i < n; i++) 00458 { 00459 hash_iter->next (hash_entry); 00460 hash_iter->advance (); 00461 00462 if (ITER_SERVANT::populate_binding (hash_entry, bl[i]) == 0) 00463 throw CORBA::NO_MEMORY(); 00464 } 00465 00466 // Now we are done with the BindingsList, and we can follow up on 00467 // the iterator business. 00468 00469 // If we do not need to pass back BindingIterator. 00470 if (this->context_->current_size () <= how_many) 00471 return; 00472 else 00473 { 00474 // Create a BindingIterator for return. 00475 ACE_NEW_THROW_EX (bind_iter, 00476 ITER_SERVANT (this, hash_iter, this->poa_.in (), this->lock_), 00477 CORBA::NO_MEMORY ()); 00478 00479 // Release <hash_iter> from auto pointer, and start using the 00480 // reference counting to control our servant. 00481 temp.release (); 00482 PortableServer::ServantBase_var iter = bind_iter; 00483 00484 // Increment reference count on this Naming Context, so it doesn't get 00485 // deleted before the BindingIterator servant gets deleted. 00486 interface_->_add_ref (); 00487 00488 // Register with the POA. 00489 char poa_id[BUFSIZ]; 00490 ACE_OS::sprintf (poa_id, 00491 "%s_%d", 00492 this->poa_id_.c_str (), 00493 (*this->counter_)++); 00494 PortableServer::ObjectId_var id = 00495 PortableServer::string_to_ObjectId (poa_id); 00496 00497 this->poa_->activate_object_with_id (id.in (), 00498 bind_iter); 00499 00500 bi = bind_iter->_this (); 00501 } 00502 }
CosNaming::NamingContext_ptr TAO_Persistent_Naming_Context::make_new_context | ( | PortableServer::POA_ptr | poa, | |
const char * | poa_id, | |||
size_t | context_size, | |||
TAO_Persistent_Context_Index * | ind | |||
) | [static] |
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., <new_context>), and from outside (e.g., Naming_Utils.cpp).
Definition at line 305 of file Persistent_Naming_Context.cpp.
References ACE_NEW_THROW_EX, TAO_Persistent_Context_Index::bind(), ACE_String_Base< CHAR >::c_str(), 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().
00309 { 00310 // Store the stub we will return here. 00311 CosNaming::NamingContext_var result; 00312 00313 // Put together a servant for the new Naming Context. 00314 00315 TAO_Persistent_Naming_Context *context_impl = 0; 00316 ACE_NEW_THROW_EX (context_impl, 00317 TAO_Persistent_Naming_Context (poa, 00318 poa_id, 00319 ind), 00320 CORBA::NO_MEMORY ()); 00321 00322 // Put <context_impl> into the auto pointer temporarily, in case next 00323 // allocation fails. 00324 ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); 00325 00326 if (context_impl->init (context_size) == -1) 00327 throw CORBA::NO_MEMORY (); 00328 00329 // Insure appropriate cleanup in case of exception conditions ahead. 00330 context_impl->set_cleanup_level (1); 00331 00332 // Register with the index of Naming Contexts. 00333 if (ind->bind (context_impl->poa_id_.c_str (), 00334 context_impl->counter_, 00335 context_impl->persistent_context_->map ()) == -1) 00336 throw CORBA::INTERNAL (); 00337 00338 // Insure appropriate cleanup in case of exception conditions ahead. 00339 context_impl->set_cleanup_level (2); 00340 00341 TAO_Naming_Context *context = 0; 00342 ACE_NEW_THROW_EX (context, 00343 TAO_Naming_Context (context_impl), 00344 CORBA::NO_MEMORY ()); 00345 00346 // Let <implementation> know about it's <interface>. 00347 context_impl->interface (context); 00348 00349 // Release auto pointer, and start using reference counting to 00350 // control our servant. 00351 temp.release (); 00352 PortableServer::ServantBase_var s = context; 00353 00354 // Register the new context with the POA. 00355 PortableServer::ObjectId_var id = 00356 PortableServer::string_to_ObjectId (poa_id); 00357 00358 poa->activate_object_with_id (id.in (), 00359 context); 00360 00361 result = context->_this (); 00362 00363 // Everything went smoothly, without errors - we don't need any cleanup. 00364 context_impl->set_cleanup_level (0); 00365 00366 return result._retn (); 00367 }
CosNaming::NamingContext_ptr TAO_Persistent_Naming_Context::new_context | ( | void | ) | [virtual] |
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 370 of file Persistent_Naming_Context.cpp.
References ACE_GUARD_THROW_EX, counter_, index_, make_new_context(), persistent_context_, ACE_OS::sprintf(), TAO_SYNCH_RECURSIVE_MUTEX, and TAO_Persistent_Bindings_Map::total_size().
00371 { 00372 ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX, 00373 ace_mon, 00374 this->lock_, 00375 CORBA::INTERNAL ()); 00376 00377 // Check to make sure this object didn't have <destroy> method 00378 // invoked on it. 00379 if (this->destroyed_) 00380 throw CORBA::OBJECT_NOT_EXIST (); 00381 00382 // Generate a POA id for the new context. 00383 char poa_id[BUFSIZ]; 00384 ACE_OS::sprintf (poa_id, 00385 "%s_%d", 00386 this->poa_id_.c_str (), 00387 (*this->counter_)++); 00388 00389 CosNaming::NamingContext_var result = 00390 make_new_context (this->poa_.in (), 00391 poa_id, 00392 this->persistent_context_->total_size (), 00393 this->index_); 00394 00395 return result._retn (); 00396 }
void TAO_Persistent_Naming_Context::set_cleanup_level | ( | int | level | ) | [protected] |
Set <destroyed_> flag (inherited from TAO_Hash_Naming_Context) to <level>. Legal values for <destroyed_> 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 <index_> (e.g., if the context had <destroy> method invoked and needs to be completely removed from existence).
Definition at line 299 of file Persistent_Naming_Context.cpp.
References TAO_Hash_Naming_Context::destroyed_.
Referenced by make_new_context().
00300 { 00301 this->destroyed_ = level; 00302 }
ACE_UINT32* TAO_Persistent_Naming_Context::counter_ [protected] |
Counter used for generation of POA ids for children Naming Contexts.
Definition at line 248 of file Persistent_Naming_Context.h.
Referenced by list(), make_new_context(), and 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.
Referenced by init(), new_context(), TAO_Persistent_Naming_Context(), and ~TAO_Persistent_Naming_Context().
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().