TAO::ObjectKey_Table Class Reference

Table that maintains the set of ObjectKey's seen by the ORB. More...

#include <ObjectKey_Table.h>

Collaboration diagram for TAO::ObjectKey_Table:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ObjectKey_Table (void)
 Default Constructor and destructor..

 ~ObjectKey_Table (void)
int init (TAO_ORB_Core *orb)
int destroy (void)
 Iterates and unbinds the contents of the table.

int bind (const ObjectKey &key, Refcounted_ObjectKey *&key_new)
 Bind the ObjectKey in the table.

int unbind (TAO::Refcounted_ObjectKey *&key)
 Unbind an ObjectKey from the table.


Protected Member Functions

int bind_i (const ObjectKey &key, Refcounted_ObjectKey *&key_new)
 Implementation for bind ().

int unbind_i (Refcounted_ObjectKey *&key)
 Implementation for unbind ().


Private Types

typedef ACE_RB_Tree< TAO::ObjectKey,
TAO::Refcounted_ObjectKey *,
TAO::Less_Than_ObjectKey,
ACE_Null_Mutex
TABLE

Private Attributes

ACE_Locklock_
 Lock for the table.

TABLE table_
 Table that contains the data.


Detailed Description

Table that maintains the set of ObjectKey's seen by the ORB.

The ORB maintains one table for the whole ORB. ObjectKeys generated by the ORB or the ones seen by the ORB from remote ORB's are stored here. The ObjectKeys are stored through a wrapper which encapsulates the refcount on them. This class actually provides the synchronization mechanism for manipulating the reference counts on the object keys provided by the wrapper class.

This class does not offer a find () call with a reason. The call to bind () will return a pointer which is expected to be cached by the client/caller and use the pointer in every invocation.

Note:
This class uses the ACE_RB_Tree to maintain the table of ObjectKeys. The RB_Tree has good insertion and lookup properties. Its Iteration properties are not that good, but we dont need to do much iteration unless we are closing down the table.

The reasons to use RB_Tree are its good dynamic properties. We should try to strategize the class to use either a Hash_Map or a RB_Tree based on some runtime option. For that we need an adapter class in ACE, like an ACE_Lock_Adapter class. We will do that if our instrumentation shows the need for it.

Definition at line 88 of file ObjectKey_Table.h.


Member Typedef Documentation

typedef ACE_RB_Tree<TAO::ObjectKey, TAO::Refcounted_ObjectKey *, TAO::Less_Than_ObjectKey, ACE_Null_Mutex> TAO::ObjectKey_Table::TABLE [private]
 

Definition at line 132 of file ObjectKey_Table.h.


Constructor & Destructor Documentation

TAO::ObjectKey_Table::ObjectKey_Table void   ) 
 

Default Constructor and destructor..

Definition at line 43 of file ObjectKey_Table.cpp.

00044   : lock_ (0)
00045   , table_ ()
00046 {
00047 
00048 }

TAO::ObjectKey_Table::~ObjectKey_Table void   ) 
 

Definition at line 50 of file ObjectKey_Table.cpp.

References ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::close().

00051 {
00052   this->table_.close ();
00053   delete this->lock_;
00054 }


Member Function Documentation

int TAO::ObjectKey_Table::bind const ObjectKey key,
Refcounted_ObjectKey *&  key_new
 

Bind the ObjectKey in the table.

Bind an ObjectKey in the table and return a pointer to the Refcounted_ObjectKey which the client can use. If the ObjectKey is already available in the table, this operation just increments the refcount on the ObjectKey. If the ObjectKey is new it is bounded to the table. Returns a 0 on success and a -1 on failure.

Definition at line 67 of file ObjectKey_Table.cpp.

References ACE_GUARD_RETURN, bind_i(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::find(), and TAO::Refcounted_ObjectKey::incr_refcount().

Referenced by TAO_Profile::decode(), TAO_IIOP_Profile::parse_string_i(), and TAO_Profile::TAO_Profile().

00070 {
00071   key_new = 0;
00072 
00073   int retval = 0;
00074 
00075   {
00076     ACE_GUARD_RETURN (ACE_Lock,
00077                       ace_mon,
00078                       *this->lock_,
00079                       0);
00080 
00081     // This is a tradeoff.. We could avoid this two stage process of
00082     // using a find () and then a bind () , which would make things
00083     // efficient. BUT we may have to do allocation upfront and delete if
00084     // bind () returns with an entry. We take one of the routes that
00085     // avoids allocation.
00086     retval = this->table_.find (key,
00087                                 key_new);
00088 
00089     if (retval == -1)
00090       {
00091         return this->bind_i (key,
00092                              key_new);
00093       }
00094 
00095     key_new->incr_refcount ();
00096   }
00097 
00098   return retval;
00099 }

int TAO::ObjectKey_Table::bind_i const ObjectKey key,
Refcounted_ObjectKey *&  key_new
[protected]
 

Implementation for bind ().

Definition at line 146 of file ObjectKey_Table.cpp.

References ACE_NEW_RETURN, ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::bind(), TAO::Refcounted_ObjectKey::decr_refcount(), and TAO::Refcounted_ObjectKey::incr_refcount().

Referenced by bind().

00148 {
00149   ACE_NEW_RETURN (key_new,
00150                   TAO::Refcounted_ObjectKey (key),
00151                   -1);
00152 
00153 
00154 
00155   int retval =  this->table_.bind (key,
00156                                    key_new);
00157 
00158   if (retval != -1)
00159     {
00160       key_new->incr_refcount ();
00161     }
00162   else
00163     {
00164       key_new->decr_refcount ();
00165     }
00166 
00167   return retval;
00168 }

int TAO::ObjectKey_Table::destroy void   ) 
 

Iterates and unbinds the contents of the table.

Definition at line 121 of file ObjectKey_Table.cpp.

References ACE_GUARD_RETURN, ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::begin(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::current_size(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::end(), and ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::unbind().

Referenced by TAO_ORB_Core::fini().

00122 {
00123   if (this->table_.current_size ())
00124     {
00125       ACE_GUARD_RETURN (ACE_Lock,
00126                         ace_mon,
00127                         *this->lock_,
00128                         0);
00129 
00130       TABLE::ITERATOR end_iter = this->table_.end ();
00131       TABLE::ITERATOR start;
00132 
00133       while ((start = this->table_.begin ()) != end_iter)
00134         {
00135           TABLE::ENTRY &ent = (*start);
00136 
00137           ent.item ()->decr_refcount ();
00138           this->table_.unbind (&ent);
00139         }
00140     }
00141 
00142   return 0;
00143 }

int TAO::ObjectKey_Table::init TAO_ORB_Core orb  ) 
 

Initialize method that sets up the underlying lock and other related stuff.

Definition at line 57 of file ObjectKey_Table.cpp.

References TAO_Resource_Factory::create_object_key_table_lock(), and TAO_ORB_Core::resource_factory().

00058 {
00059   /// Create the lock that is needed for internal usage.
00060   this->lock_ =
00061     oc->resource_factory ()->create_object_key_table_lock ();
00062 
00063   return 0;
00064 }

int TAO::ObjectKey_Table::unbind TAO::Refcounted_ObjectKey *&  key  ) 
 

Unbind an ObjectKey from the table.

Definition at line 102 of file ObjectKey_Table.cpp.

References ACE_GUARD_RETURN, TAO::Refcounted_ObjectKey::decr_refcount(), and unbind_i().

Referenced by TAO_Profile::~TAO_Profile().

00104 {
00105   ACE_GUARD_RETURN (ACE_Lock,
00106                     ace_mon,
00107                     *this->lock_,
00108                     0);
00109 
00110   // If the refcount has dropped to 1, just go ahead and unbind it
00111   // from the table.
00112   if (key_new && key_new->decr_refcount () == 1)
00113     {
00114       return this->unbind_i (key_new);
00115     }
00116 
00117   return 0;
00118 }

int TAO::ObjectKey_Table::unbind_i Refcounted_ObjectKey *&  key  )  [protected]
 

Implementation for unbind ().

Definition at line 171 of file ObjectKey_Table.cpp.

References TAO::Refcounted_ObjectKey::decr_refcount(), TAO::Refcounted_ObjectKey::object_key(), and ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::unbind().

Referenced by unbind().

00172 {
00173   TAO::Refcounted_ObjectKey *tmp = 0;
00174 
00175   if (this->table_.unbind (key_new->object_key (),
00176                            tmp) != -1)
00177     {
00178       // @@ Cant do much if the unbind fails.
00179       // Remove our refcount on the ObjectKey
00180       (void) tmp->decr_refcount ();
00181     }
00182 
00183   return 0;
00184 }


Member Data Documentation

ACE_Lock* TAO::ObjectKey_Table::lock_ [private]
 

Lock for the table.

Definition at line 135 of file ObjectKey_Table.h.

TABLE TAO::ObjectKey_Table::table_ [private]
 

Table that contains the data.

Definition at line 138 of file ObjectKey_Table.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 12:26:35 2006 for TAO by doxygen 1.3.6