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 (ACE_ENV_SINGLE_ARG_DECL)
virtual void list (CORBA::ULong how_many, CosNaming::BindingList_out &bl, CosNaming::BindingIterator_out &bi ACE_ENV_ARG_DECL)

Static Public Member Functions

CosNaming::NamingContext_ptr make_new_context (PortableServer::POA_ptr poa, const char *poa_id, size_t context_size ACE_ENV_ARG_DECL)

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

References ACE_NEW, and transient_context_.

00129   : TAO_Hash_Naming_Context (poa,
00130                              poa_id),
00131     counter_ (0),
00132     transient_context_ (0)
00133 {
00134   ACE_NEW (this->transient_context_,
00135            TAO_Transient_Bindings_Map (hash_table_size));
00136 
00137   context_ = transient_context_;
00138 }

TAO_Transient_Naming_Context::~TAO_Transient_Naming_Context void   )  [virtual]
 

Destructor.

Definition at line 140 of file Transient_Naming_Context.cpp.

00141 {
00142 }


Member Function Documentation

void TAO_Transient_Naming_Context::list CORBA::ULong  how_many,
CosNaming::BindingList_out &  bl,
CosNaming::BindingIterator_out &bi  ACE_ENV_ARG_DECL
[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 230 of file Transient_Naming_Context.cpp.

References ACE_CHECK, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_GUARD_THROW_EX, ACE_NEW_THROW_EX, ACE_THROW, 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_.

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

CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::make_new_context PortableServer::POA_ptr  poa,
const char *  poa_id,
size_t context_size  ACE_ENV_ARG_DECL
[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 145 of file Transient_Naming_Context.cpp.

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

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

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

CosNaming::NamingContext_ptr TAO_Transient_Naming_Context::new_context ACE_ENV_SINGLE_ARG_DECL   )  [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 197 of file Transient_Naming_Context.cpp.

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

00198 {
00199   ACE_GUARD_THROW_EX (TAO_SYNCH_RECURSIVE_MUTEX,
00200                       ace_mon,
00201                       this->lock_,
00202                       CORBA::INTERNAL ());
00203   ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
00204 
00205   // Check to make sure this object didn't have <destroy> method
00206   // invoked on it.
00207   if (this->destroyed_)
00208     ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (),
00209                       CosNaming::NamingContext::_nil ());
00210 
00211   // Generate a POA id for the new context.
00212   char poa_id[BUFSIZ];
00213   ACE_OS::sprintf (poa_id,
00214                    "%s_%d",
00215                    this->poa_id_.c_str (),
00216                    this->counter_++);
00217 
00218   // Create a new context.
00219   CosNaming::NamingContext_var result =
00220     make_new_context (this->poa_.in (),
00221                       poa_id,
00222                       this->transient_context_->total_size ()
00223                       ACE_ENV_ARG_PARAMETER);
00224   ACE_CHECK_RETURN (CosNaming::NamingContext::_nil ());
00225 
00226   return result._retn ();
00227 }


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 189 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 198 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 Thu Nov 9 13:57:53 2006 for TAO_CosNaming by doxygen 1.3.6