Transient_Naming_Context.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   Transient_Naming_Context.h
00006  *
00007  *  $Id: Transient_Naming_Context.h 76589 2007-01-25 18:04:11Z elliott_c $
00008  *
00009  *  @author Marina Spivak <marina@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_TRANSIENT_NAMING_CONTEXT_H
00015 #define TAO_TRANSIENT_NAMING_CONTEXT_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "orbsvcs/Naming/Hash_Naming_Context.h"
00019 #include "orbsvcs/Naming/Entries.h"
00020 #include "ace/Hash_Map_Manager.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 /**
00030  * @class TAO_Transient_Bindings_Map
00031  *
00032  * @brief Provides hash-table-based transient storage for name to object
00033  * bindings in a Naming Context.
00034  *
00035  * A thin wrapper on top of ACE_Hash_Map_Manager.  Supports
00036  * TAO_Bindings_Map interface.  Used by TAO_Transient_Naming_Context.
00037  */
00038 class TAO_Naming_Serv_Export TAO_Transient_Bindings_Map : public TAO_Bindings_Map
00039 {
00040 public:
00041 
00042   /// Underlying data structure - typedef for ease of use.
00043   typedef ACE_Hash_Map_Manager<TAO_ExtId, TAO_IntId, ACE_Null_Mutex> HASH_MAP;
00044 
00045   // = Initialization and termination methods.
00046 
00047   /// Constructor.
00048   TAO_Transient_Bindings_Map (size_t hash_table_size);
00049 
00050   /// Destructor.
00051   virtual ~TAO_Transient_Bindings_Map (void);
00052 
00053   // = Accessors.
00054 
00055   /// Get a reference to the underlying hash map.
00056   HASH_MAP &map (void);
00057 
00058   /// Return the size of the underlying hash table.
00059   size_t total_size (void);
00060 
00061   /// Return current number of entries (name bindings) in the
00062   /// underlying hash map.
00063   virtual size_t current_size (void);
00064 
00065   // = Name bindings manipulation methods.
00066 
00067   /**
00068    * Add a binding with the specified parameters to the table.
00069    * Return 0 on success and -1 on failure, 1 if there already is a
00070    * binding with <id> and <kind>.
00071    */
00072   virtual int bind (const char *id,
00073                     const char *kind,
00074                     CORBA::Object_ptr obj,
00075                     CosNaming::BindingType type);
00076 
00077   /**
00078    * Overwrite a binding containing <id> and <kind> (or create a new
00079    * one if one doesn't exist) with the specified parameters.  Return
00080    * 0 or 1 on success.  Return -1 or -2 on failure. (-2 is returned
00081    * if the new and old bindings differ in type).
00082    */
00083   virtual int rebind (const char *id,
00084                       const char *kind,
00085                       CORBA::Object_ptr obj,
00086                       CosNaming::BindingType type);
00087 
00088   /**
00089    * Remove a binding containing <id> and <kind> from the table.
00090    * Return 0 on success and -1 on failure.
00091    */
00092   virtual int unbind (const char * id,
00093                       const char * kind);
00094 
00095   /**
00096    * Find the binding containing <id> and <kind> in the table, and
00097    * pass binding's type and object back to the caller by reference.
00098    * Return 0 on success and -1 on failure.  Note: a 'duplicated' object
00099    * reference is assigned to <obj>, so the caller is responsible for
00100    * its deallocation.
00101    */
00102   virtual int find (const char * id,
00103                     const char * kind,
00104                     CORBA::Object_ptr & obj,
00105                     CosNaming::BindingType &type);
00106 
00107 private:
00108 
00109   /// Helper: factors common code from <bind> and <rebind>.
00110   int shared_bind (const char *id,
00111                    const char *kind,
00112                    CORBA::Object_ptr obj,
00113                    CosNaming::BindingType type,
00114                    int rebind);
00115 
00116   /// Hash map used for storage.
00117   HASH_MAP map_;
00118 };
00119 
00120 /**
00121  * @class TAO_Transient_Naming_Context
00122  *
00123  * @brief This class plays a role of a 'ConcreteImplementor' in the
00124  * Bridge pattern architecture of the CosNaming::NamingContext
00125  * implementation.
00126  *
00127  * This class provides a transient implementation of the
00128  * NamingContext functionality, i.e., the state is not preserved
00129  * across process boundaries.  Derives from
00130  * TAO_Hash_Naming_Context and uses TAO_Transient_Bindings_Map to
00131  * store name to object bindings.
00132  */
00133 class TAO_Naming_Serv_Export TAO_Transient_Naming_Context : public TAO_Hash_Naming_Context
00134 {
00135 
00136 public:
00137 
00138   /// Underlying data structure - typedef for ease of use.
00139   typedef TAO_Transient_Bindings_Map::HASH_MAP HASH_MAP;
00140 
00141   // = Initialization and termination methods.
00142 
00143   /// Constructor.
00144   TAO_Transient_Naming_Context (PortableServer::POA_ptr poa,
00145                                 const char *poa_id,
00146                                 size_t hash_table_size
00147                                 = ACE_DEFAULT_MAP_SIZE);
00148 
00149   /// Destructor.
00150   virtual ~TAO_Transient_Naming_Context (void);
00151 
00152   // = Utility methods.
00153   /**
00154    * This utility method factors out the code needed to create a new
00155    * Transient Naming Context servant and activate it under the
00156    * specified POA with the specified id.  This function is static so
00157    * that the code can be used, both from inside the class (e.g., <new_context>),
00158    * and from outside (e.g., Naming_Utils.cpp).
00159    */
00160   static CosNaming::NamingContext_ptr make_new_context (PortableServer::POA_ptr poa,
00161                                                         const char *poa_id,
00162                                                         size_t context_size);
00163 
00164   // = Methods not implemented in TAO_Hash_Naming_Context.
00165 
00166   /**
00167    * This operation returns a new naming context implemented by the
00168    * same naming server in which the operation was invoked.  The
00169    * context is not bound.
00170    */
00171   virtual CosNaming::NamingContext_ptr new_context (void);
00172 
00173   /**
00174    * Returns at most the requested number of bindings <how_many> in
00175    * <bl>.  If the naming context contains additional bindings, they
00176    * are returned with a BindingIterator.  In the naming context does
00177    * not contain any additional bindings <bi> returned as null.
00178    */
00179   virtual void list (CORBA::ULong how_many,
00180                      CosNaming::BindingList_out &bl,
00181                      CosNaming::BindingIterator_out &bi);
00182 
00183 protected:
00184 
00185   /// Counter used for generation of POA ids for children Naming
00186   /// Contexts.
00187   ACE_UINT32 counter_;
00188 
00189   /**
00190    * A pointer to the underlying data structure used to store name
00191    * bindings. While our superclass (TAO_Hash_Naming_Context) also
00192    * maintains a pointer to the data structure, keeping this pointer
00193    * around saves us from the need to downcast when invoking
00194    * non-virtual methods.
00195    */
00196   TAO_Transient_Bindings_Map *transient_context_;
00197 };
00198 
00199 TAO_END_VERSIONED_NAMESPACE_DECL
00200 
00201 #include /**/ "ace/post.h"
00202 #endif /* TAO_TRANSIENT_NAMING_CONTEXT_H */

Generated on Sun Jan 27 16:15:32 2008 for TAO_CosNaming by doxygen 1.3.6