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

static 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, TAO_Hash_Naming_Context::context_, 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 <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 218 of file Transient_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_Transient_Bindings_Map::map(), TAO_Hash_Naming_Context::poa_, ACE_OS::sprintf(), TAO_SYNCH_RECURSIVE_MUTEX, and transient_context_.

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

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., <new_context>), 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 #if defined (CORBA_E_MICRO)
00175   PortableServer::ObjectId_var id = poa->activate_object (context);
00176 #else
00177   PortableServer::ObjectId_var id =
00178     PortableServer::string_to_ObjectId (poa_id);
00179 
00180   poa->activate_object_with_id (id.in (), context);
00181 #endif /* CORBA_E_MICRO */
00182 
00183   result = context->_this ();
00184 
00185   return result._retn ();
00186 }

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

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

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


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.

Referenced by list(), and new_context().

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 Tue Feb 2 17:49:12 2010 for TAO_CosNaming by  doxygen 1.4.7