Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes

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 Member Functions

void operator= (const ObjectKey_Table &)
 ObjectKey_Table (const ObjectKey_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 134 of file ObjectKey_Table.h.


Constructor & Destructor Documentation

TAO::ObjectKey_Table::ObjectKey_Table ( void   ) 

Default Constructor and destructor..

Definition at line 37 of file ObjectKey_Table.cpp.

  : lock_ (0)
  , table_ ()
{

}

TAO::ObjectKey_Table::~ObjectKey_Table ( void   ) 

Definition at line 44 of file ObjectKey_Table.cpp.

{
  this->table_.close ();
  delete this->lock_;
}

TAO::ObjectKey_Table::ObjectKey_Table ( const ObjectKey_Table  )  [private]

Member Function Documentation

int TAO::ObjectKey_Table::bind ( const ObjectKey key,
TAO::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 61 of file ObjectKey_Table.cpp.

{
  key_new = 0;

  int retval = 0;

  {
    ACE_GUARD_RETURN (ACE_Lock,
                      ace_mon,
                      *this->lock_,
                      0);

    // This is a tradeoff.. We could avoid this two stage process of
    // using a find () and then a bind () , which would make things
    // efficient. BUT we may have to do allocation upfront and delete if
    // bind () returns with an entry. We take one of the routes that
    // avoids allocation.
    retval = this->table_.find (key,
                                key_new);

    if (retval == -1)
      {
        return this->bind_i (key,
                             key_new);
      }

    (void) key_new->incr_refcount ();
  }

  return retval;
}

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

Implementation for bind ().

Definition at line 140 of file ObjectKey_Table.cpp.

{
  ACE_NEW_RETURN (key_new,
                  TAO::Refcounted_ObjectKey (key),
                  -1);

  int const retval =  this->table_.bind (key, key_new);

  if (retval != -1)
    {
      key_new->incr_refcount ();
    }
  else
    {
      key_new->decr_refcount ();
    }

  return retval;
}

int TAO::ObjectKey_Table::destroy ( void   ) 

Iterates and unbinds the contents of the table.

Definition at line 115 of file ObjectKey_Table.cpp.

{
  if (this->table_.current_size ())
    {
      ACE_GUARD_RETURN (ACE_Lock,
                        ace_mon,
                        *this->lock_,
                        0);

      TABLE::ITERATOR end_iter = this->table_.end ();
      TABLE::ITERATOR start;

      while ((start = this->table_.begin ()) != end_iter)
        {
          TABLE::ENTRY &ent = (*start);

          ent.item ()->decr_refcount ();
          this->table_.unbind (&ent);
        }
    }

  return 0;
}

int TAO::ObjectKey_Table::init ( TAO_ORB_Core orb  ) 

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

Create the lock that is needed for internal usage.

Definition at line 51 of file ObjectKey_Table.cpp.

{
  /// Create the lock that is needed for internal usage.
  this->lock_ =
    oc->resource_factory ()->create_object_key_table_lock ();

  return 0;
}

void TAO::ObjectKey_Table::operator= ( const ObjectKey_Table  )  [private]
int TAO::ObjectKey_Table::unbind ( TAO::Refcounted_ObjectKey *&  key  ) 

Unbind an ObjectKey from the table.

Definition at line 96 of file ObjectKey_Table.cpp.

{
  ACE_GUARD_RETURN (ACE_Lock,
                    ace_mon,
                    *this->lock_,
                    0);

  // If the refcount has dropped to 1, just go ahead and unbind it
  // from the table.
  if (key_new && key_new->decr_refcount () == 1)
    {
      return this->unbind_i (key_new);
    }

  return 0;
}

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

Implementation for unbind ().

Definition at line 162 of file ObjectKey_Table.cpp.

{
  TAO::Refcounted_ObjectKey *tmp = 0;

  if (this->table_.unbind (key_new->object_key (), tmp) != -1)
    {
      // @@ Cant do much if the unbind fails.
      // Remove our refcount on the ObjectKey
      (void) tmp->decr_refcount ();
    }

  return 0;
}


Member Data Documentation

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

Lock for the table.

Definition at line 137 of file ObjectKey_Table.h.

TABLE TAO::ObjectKey_Table::table_ [private]

Table that contains the data.

Definition at line 140 of file ObjectKey_Table.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines