TAO_Transient_Naming_Context Class Reference

This class plays a role of a 'ConcreteImplementor' in the Bridge pattern architecture of the CosNaming::NamingContext implementation. More...

#include <Transient_Naming_Context.h>

Inheritance diagram for TAO_Transient_Naming_Context:

Inheritance graph
[legend]
Collaboration diagram for TAO_Transient_Naming_Context:

Collaboration graph
[legend]
List of all members.

Public Types

typedef TAO_Transient_Bindings_Map::HASH_MAP HASH_MAP
 Underlying data structure - typedef for ease of use.


Public Member Functions

 TAO_Transient_Naming_Context (PortableServer::POA_ptr poa, const char *poa_id, size_t hash_table_size=ACE_DEFAULT_MAP_SIZE)
 Constructor.

virtual ~TAO_Transient_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)

Protected Attributes

ACE_UINT32 counter_
TAO_Transient_Bindings_Maptransient_context_

Detailed Description

This class plays a role of a 'ConcreteImplementor' in the Bridge pattern architecture of the CosNaming::NamingContext implementation.

This class provides a transient implementation of the NamingContext functionality, i.e., the state is not preserved across process boundaries. Derives from TAO_Hash_Naming_Context and uses TAO_Transient_Bindings_Map to store name to object bindings.

Definition at line 133 of file Transient_Naming_Context.h.


Member Typedef Documentation

typedef TAO_Transient_Bindings_Map::HASH_MAP TAO_Transient_Naming_Context::HASH_MAP
 

Underlying data structure - typedef for ease of use.

Definition at line 139 of file Transient_Naming_Context.h.


Constructor & Destructor Documentation

TAO_Transient_Naming_Context::TAO_Transient_Naming_Context PortableServer::POA_ptr  poa,
const char *  poa_id,
size_t  hash_table_size = ACE_DEFAULT_MAP_SIZE
 

Constructor.

Definition at line 121 of file Transient_Naming_Context.cpp.

References ACE_NEW, and transient_context_.

00124   : TAO_Hash_Naming_Context (poa,
00125                              poa_id),
00126     counter_ (0),
00127     transient_context_ (0)
00128 {
00129   ACE_NEW (this->transient_context_,
00130            TAO_Transient_Bindings_Map (hash_table_size));
00131 
00132   context_ = transient_context_;
00133 }

TAO_Transient_Naming_Context::~TAO_Transient_Naming_Context void   )  [virtual]
 

Destructor.

Definition at line 135 of file Transient_Naming_Context.cpp.

00136 {
00137 }


Member Function Documentation

void TAO_Transient_Naming_Context::list CORBA::ULong  how_many,
CosNaming::BindingList_out &  bl,
CosNaming::BindingIterator_out &  bi
[virtual]
 

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 215 of file Transient_Naming_Context.cpp.

References ACE_GUARD_THROW_EX, ACE_NEW_THROW_EX, CosNaming::BindingList, TAO_Bindings_Map::current_size(), TAO_Transient_Bindings_Map::map(), ACE_Auto_Basic_Ptr< X >::release(), ACE_OS::sprintf(), TAO_SYNCH_RECURSIVE_MUTEX, and transient_context_.

00218 {
00219   // Allocate nil out parameters in case we won't be able to complete
00220   // the operation.
00221   bi = CosNaming::BindingIterator::_nil ();
00222   ACE_NEW_THROW_EX (bl,
00223                     CosNaming::BindingList (0),
00224                     CORBA::NO_MEMORY ());
00225 
00226   // Obtain a lock before we proceed with the operation.
00227   ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00228                       ace_mon,
00229                       this->lock_,
00230                       CORBA::INTERNAL ());
00231 
00232   // Check to make sure this object didn't have <destroy> method
00233   // invoked on it.
00234   if (this->destroyed_)
00235     throw CORBA::OBJECT_NOT_EXIST ();
00236 
00237   // Dynamically allocate iterator for traversing the underlying hash map.
00238   HASH_MAP::ITERATOR *hash_iter = 0;
00239   ACE_NEW_THROW_EX (hash_iter,
00240                     HASH_MAP::ITERATOR (transient_context_->map ()),
00241                     CORBA::NO_MEMORY ());
00242 
00243   // Store <hash_iter temporarily in auto pointer, in case we'll have
00244   // some failures and throw an exception.
00245   ACE_Auto_Basic_Ptr<HASH_MAP::ITERATOR> temp (hash_iter);
00246 
00247   // Silliness below is required because of broken old g++!!!  E.g.,
00248   // without it, we could have just said HASH_MAP::ITERATOR everywhere we use ITER_DEF.
00249   typedef ACE_Hash_Map_Manager<TAO_ExtId, TAO_IntId, ACE_Null_Mutex>::ITERATOR ITER_DEF;
00250   typedef ACE_Hash_Map_Manager<TAO_ExtId, TAO_IntId, ACE_Null_Mutex>::ENTRY ENTRY_DEF;
00251 
00252   // Typedef to the type of BindingIterator servant for ease of use.
00253   typedef TAO_Bindings_Iterator<ITER_DEF, ENTRY_DEF>
00254     ITER_SERVANT;
00255 
00256   // A pointer to BindingIterator servant.
00257   ITER_SERVANT *bind_iter = 0;
00258 
00259   // Number of bindings that will go into the BindingList <bl>.
00260   CORBA::ULong n;
00261 
00262   // Calculate number of bindings that will go into <bl>.
00263   if (this->context_->current_size () > how_many)
00264     n = how_many;
00265   else
00266     n = static_cast<CORBA::ULong> (this->context_->current_size ());
00267 
00268   // Use the hash map iterator to populate <bl> with bindings.
00269   bl->length (n);
00270 
00271   ENTRY_DEF *hash_entry = 0;
00272 
00273   for (CORBA::ULong i = 0; i < n; i++)
00274     {
00275       hash_iter->next (hash_entry);
00276       hash_iter->advance ();
00277 
00278       if (ITER_SERVANT::populate_binding (hash_entry, bl[i]) == 0)
00279           throw CORBA::NO_MEMORY();
00280     }
00281 
00282   // Now we are done with the BindingsList, and we can follow up on
00283   // the BindingIterator business.
00284 
00285   // If we do not need to pass back BindingIterator.
00286   if (this->context_->current_size () <= how_many)
00287     return;
00288   else
00289     {
00290       // Create a BindingIterator for return.
00291       ACE_NEW_THROW_EX (bind_iter,
00292                         ITER_SERVANT (this, hash_iter, this->poa_.in (), this->lock_),
00293                         CORBA::NO_MEMORY ());
00294 
00295       // Release <hash_iter> from auto pointer, and start using
00296       // reference counting to control our servant.
00297       temp.release ();
00298       PortableServer::ServantBase_var iter = bind_iter;
00299 
00300       // Increment reference count on this Naming Context, so it doesn't get
00301       // deleted before the BindingIterator servant gets deleted.
00302       interface_->_add_ref ();
00303 
00304       // Register with the POA.
00305       char poa_id[BUFSIZ];
00306       ACE_OS::sprintf (poa_id,
00307                        "%s_%d",
00308                        this->poa_id_.c_str (),
00309                        this->counter_++);
00310       PortableServer::ObjectId_var id =
00311         PortableServer::string_to_ObjectId (poa_id);
00312 
00313       this->poa_->activate_object_with_id (id.in (),
00314                                            bind_iter);
00315 
00316       bi = bind_iter->_this ();
00317     }
00318 }

CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::make_new_context PortableServer::POA_ptr  poa,
const char *  poa_id,
size_t  context_size
[static]
 

This utility method factors out the code needed to create a new Transient 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 140 of file Transient_Naming_Context.cpp.

References ACE_NEW_THROW_EX, and ACE_Auto_Basic_Ptr< X >::release().

Referenced by TAO_Naming_Server::init_new_naming(), and new_context().

00143 {
00144   // Store the stub we will return here.
00145   CosNaming::NamingContext_var result;
00146 
00147   // Put together a servant for the new Naming Context.
00148 
00149   TAO_Transient_Naming_Context *context_impl = 0;
00150   ACE_NEW_THROW_EX (context_impl,
00151                     TAO_Transient_Naming_Context (poa,
00152                                                   poa_id,
00153                                                   context_size),
00154                     CORBA::NO_MEMORY ());
00155 
00156   // Put <context_impl> into the auto pointer temporarily, in case next
00157   // allocation fails.
00158   ACE_Auto_Basic_Ptr<TAO_Transient_Naming_Context> temp (context_impl);
00159 
00160   TAO_Naming_Context *context = 0;
00161   ACE_NEW_THROW_EX (context,
00162                     TAO_Naming_Context (context_impl),
00163                     CORBA::NO_MEMORY ());
00164 
00165   // Let <implementation> know about it's <interface>.
00166   context_impl->interface (context);
00167 
00168   // Release auto pointer, and start using reference counting to
00169   // control our servant.
00170   temp.release ();
00171   PortableServer::ServantBase_var s = context;
00172 
00173   // Register the new context with the POA.
00174   PortableServer::ObjectId_var id =
00175     PortableServer::string_to_ObjectId (poa_id);
00176 
00177   poa->activate_object_with_id (id.in (),
00178                                 context);
00179 
00180   result = context->_this ();
00181 
00182   return result._retn ();
00183 }

CosNaming::NamingContext_ptr TAO_Transient_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 186 of file Transient_Naming_Context.cpp.

References ACE_GUARD_THROW_EX, make_new_context(), ACE_OS::sprintf(), TAO_SYNCH_RECURSIVE_MUTEX, TAO_Transient_Bindings_Map::total_size(), and transient_context_.

00187 {
00188   ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00189                       ace_mon,
00190                       this->lock_,
00191                       CORBA::INTERNAL ());
00192 
00193   // Check to make sure this object didn't have <destroy> method
00194   // invoked on it.
00195   if (this->destroyed_)
00196     throw CORBA::OBJECT_NOT_EXIST ();
00197 
00198   // Generate a POA id for the new context.
00199   char poa_id[BUFSIZ];
00200   ACE_OS::sprintf (poa_id,
00201                    "%s_%d",
00202                    this->poa_id_.c_str (),
00203                    this->counter_++);
00204 
00205   // Create a new context.
00206   CosNaming::NamingContext_var result =
00207     make_new_context (this->poa_.in (),
00208                       poa_id,
00209                       this->transient_context_->total_size ());
00210 
00211   return result._retn ();
00212 }


Member Data Documentation

ACE_UINT32 TAO_Transient_Naming_Context::counter_ [protected]
 

Counter used for generation of POA ids for children Naming Contexts.

Definition at line 187 of file Transient_Naming_Context.h.

TAO_Transient_Bindings_Map* TAO_Transient_Naming_Context::transient_context_ [protected]
 

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 196 of file Transient_Naming_Context.h.

Referenced by list(), new_context(), and TAO_Transient_Naming_Context().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 16:16:29 2008 for TAO_CosNaming by doxygen 1.3.6