Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes

TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT > Class Template Reference

The Transport Cache Manager for TAO. More...

#include <Transport_Cache_Manager_T.h>

Collaboration diagram for TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Find_Result { CACHE_FOUND_NONE, CACHE_FOUND_CONNECTING, CACHE_FOUND_BUSY, CACHE_FOUND_AVAILABLE }
 

results of a find

More...
typedef TT transport_type
typedef TRDT transport_descriptor_type
typedef PSTRAT purging_strategy
typedef Cache_ExtId_T
< transport_descriptor_type > 
Cache_ExtId
typedef Cache_IntId_T
< transport_type > 
Cache_IntId
typedef
ACE_Hash_Map_Manager_Ex
< Cache_ExtId, Cache_IntId,
ACE_Hash< Cache_ExtId >
, ACE_Equal_To< Cache_ExtId >
, ACE_Null_Mutex
HASH_MAP
typedef HASH_MAP::iterator HASH_MAP_ITER
typedef ACE_Hash_Map_Entry
< Cache_ExtId, Cache_IntId
HASH_MAP_ENTRY
typedef TAO_Condition
< TAO_SYNCH_MUTEX > 
CONDITION

Public Member Functions

 Transport_Cache_Manager_T (int percent, purging_strategy *purging_strategy, size_t cache_maximum, bool locked, const char *orbid)
 Constructor.
 ~Transport_Cache_Manager_T (void)
 Destructor.
int cache_transport (transport_descriptor_type *prop, transport_type *transport, Cache_Entries_State state=ENTRY_IDLE_AND_PURGABLE)
 Add the transport to the cache.
Find_Result find_transport (transport_descriptor_type *prop, transport_type *&transport, size_t &busy_count)
int purge (void)
 Remove entries from the cache depending upon the strategy.
int purge_entry (HASH_MAP_ENTRY *&entry)
 Purge the entry from the Cache Map.
void mark_invalid (HASH_MAP_ENTRY *entry)
 Mark the entry as invalid for use but keep it in cache.
void mark_connected (HASH_MAP_ENTRY *entry, bool state)
 Mark the entry as connected.
int make_idle (HASH_MAP_ENTRY *entry)
 Make the entry idle and ready for use.
void set_entry_state (HASH_MAP_ENTRY *entry, TAO::Cache_Entries_State state)
 Modify the state setting on the provided entry.
int update_entry (HASH_MAP_ENTRY *&entry)
int close (Connection_Handler_Set &handlers)
bool blockable_client_transports (Connection_Handler_Set &handlers)
size_t current_size (void) const
 Return the current size of the cache.
size_t total_size (void) const
 Return the total size of the cache.
HASH_MAPmap (void)
 Return the underlying cache map.

Private Types

typedef HASH_MAP_ENTRY ** DESCRIPTOR_SET

Private Member Functions

Find_Result find (transport_descriptor_type *prop, transport_type *&transport, size_t &busy_count)
int bind_i (Cache_ExtId &ext_id, Cache_IntId &int_id)
Find_Result find_i (transport_descriptor_type *prop, transport_type *&transport, size_t &busy_count)
int make_idle_i (HASH_MAP_ENTRY *entry)
 Non-locking version and actual implementation of make_idle ().
int close_i (Connection_Handler_Set &handlers)
 Non-locking version and actual implementation of close ().
int purge_entry_i (HASH_MAP_ENTRY *&entry)
 Purge the entry from the Cache Map.
void mark_invalid_i (HASH_MAP_ENTRY *entry)
 Mark the entry as invalid for use but keep it in cache.
bool is_entry_available_i (const HASH_MAP_ENTRY &entry)
bool is_entry_connecting_i (const HASH_MAP_ENTRY &entry)
bool is_entry_purgable_i (HASH_MAP_ENTRY &entry)
void sort_set (DESCRIPTOR_SET &entries, int size)
 Sort the list of entries.
int fill_set_i (DESCRIPTOR_SET &sorted_set)
bool blockable_client_transports_i (Connection_Handler_Set &handlers)
 Non-locking version of blockable_client_transports ().

Static Private Member Functions

static int cpscmp (const void *a, const void *b)
 Used by qsort.

Private Attributes

int percent_
 The percentage of the cache to purge at one time.
purging_strategy * purging_strategy_
 The underlying connection purging strategy.
HASH_MAP cache_map_
 The hash map that has the connections.
TAO_SYNCH_MUTEX cache_map_mutex_
ACE_Lockcache_lock_
 The lock that is used by the cache map.
size_t cache_maximum_
 Maximum size of the cache.

Detailed Description

template<typename TT, typename TRDT, typename PSTRAT>
class TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >

The Transport Cache Manager for TAO.

This class provides interfaces associating a TAO_Cache_ExtId & TAO_Cache_IntId. This class is wrapper around the ACE_Hash_Map_Manager class which is used as a container to Cache the connections. This class protects the entries with a lock. The map is updated only by holding the lock. The more compelling reason to have the lock in this class and not in the Hash_Map is that, we do quite a bit of work in this class for which we need a lock.

Definition at line 62 of file Transport_Cache_Manager_T.h.


Member Typedef Documentation

template<typename TT , typename TRDT , typename PSTRAT >
typedef Cache_ExtId_T<transport_descriptor_type> TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::Cache_ExtId

Definition at line 78 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef Cache_IntId_T<transport_type> TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::Cache_IntId

Definition at line 79 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef TAO_Condition<TAO_SYNCH_MUTEX> TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::CONDITION

Definition at line 95 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef HASH_MAP_ENTRY** TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::DESCRIPTOR_SET [private]

Definition at line 235 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef ACE_Hash_Map_Manager_Ex<Cache_ExtId, Cache_IntId, ACE_Hash<Cache_ExtId>, ACE_Equal_To<Cache_ExtId>, ACE_Null_Mutex> TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::HASH_MAP

Definition at line 87 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef ACE_Hash_Map_Entry<Cache_ExtId, Cache_IntId> TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::HASH_MAP_ENTRY

Definition at line 93 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef HASH_MAP::iterator TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::HASH_MAP_ITER

Definition at line 89 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef PSTRAT TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::purging_strategy

Definition at line 67 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef TRDT TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::transport_descriptor_type

Definition at line 66 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
typedef TT TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::transport_type

Definition at line 65 of file Transport_Cache_Manager_T.h.


Member Enumeration Documentation

template<typename TT , typename TRDT , typename PSTRAT >
enum TAO::Transport_Cache_Manager_T::Find_Result

results of a find

Enumerator:
CACHE_FOUND_NONE 
CACHE_FOUND_CONNECTING 
CACHE_FOUND_BUSY 
CACHE_FOUND_AVAILABLE 

Definition at line 70 of file Transport_Cache_Manager_T.h.

    {
      CACHE_FOUND_NONE,
      CACHE_FOUND_CONNECTING,
      CACHE_FOUND_BUSY,
      CACHE_FOUND_AVAILABLE
    };


Constructor & Destructor Documentation

template<typename TT , typename TRDT , typename PSTRAT >
TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::Transport_Cache_Manager_T ( int  percent,
purging_strategy *  purging_strategy,
size_t  cache_maximum,
bool  locked,
const char *  orbid 
)

Constructor.

Definition at line 32 of file Transport_Cache_Manager_T.cpp.

    : percent_ (percent)
    , purging_strategy_ (purging_strategy)
    , cache_map_ (cache_maximum)
    , cache_lock_ (0)
    , cache_maximum_ (cache_maximum)
#if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
    , purge_monitor_ (0)
    , size_monitor_ (0)
#endif /* TAO_HAS_MONITOR_POINTS==1 */
  {
    if (locked)
      {
        ACE_NEW (this->cache_lock_,
                 ACE_Lock_Adapter <TAO_SYNCH_MUTEX> (this->cache_map_mutex_));
      }
    else
      {
        ACE_NEW (this->cache_lock_,
                 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>);
      }

#if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
    ACE_NEW (this->purge_monitor_,
             ACE::Monitor_Control::Size_Monitor);
    ACE_NEW (this->size_monitor_,
             ACE::Monitor_Control::Size_Monitor);

    ACE_CString purge_name ("Connection_Cache_Purge_");
    ACE_CString size_name ("Connection_Cache_Size_");

    purge_name += orbid;
    size_name += orbid;

    this->purge_monitor_->name (purge_name.c_str ());
    this->size_monitor_->name (size_name.c_str ());

    this->purge_monitor_->add_to_registry ();
    this->size_monitor_->add_to_registry ();
#else
  ACE_UNUSED_ARG (orbid);
#endif /* TAO_HAS_MONITOR_POINTS==1 */
  }

template<typename TT , typename TRDT , typename PSTRAT >
TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::~Transport_Cache_Manager_T ( void   ) 

Destructor.

Definition at line 82 of file Transport_Cache_Manager_T.cpp.

  {
    delete this->cache_lock_;
    this->cache_lock_ = 0;

    delete this->purging_strategy_;
    this->purging_strategy_ = 0;

#if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
    this->purge_monitor_->remove_from_registry ();
    this->size_monitor_->remove_from_registry ();
    this->purge_monitor_->remove_ref ();
    this->size_monitor_->remove_ref ();
#endif /* TAO_HAS_MONITOR_POINTS==1 */
  }


Member Function Documentation

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::bind_i ( Cache_ExtId ext_id,
Cache_IntId int_id 
) [private]

Non-Locking version and actual implementation of bind () call. Calls bind on the Hash_Map_Manager that it holds. If the bind succeeds, it adds the Hash_Map_Entry in to the Transport for its reference.

Definition at line 116 of file Transport_Cache_Manager_T.cpp.

  {
    if (TAO_debug_level > 4)
       {
         ACE_DEBUG ((LM_INFO,
            ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
            ACE_TEXT ("Transport[%d] @ hash:index{%d:%d}\n"),
            int_id.transport ()->id (),
            ext_id.hash (),
            ext_id.index ()
            ));
       }

    // Get the entry too
    HASH_MAP_ENTRY *entry = 0;

    // Update the purging strategy information while we
    // are holding our lock
    this->purging_strategy_->update_item (int_id.transport ());
    int retval = 0;
    bool more_to_do = true;
    while (more_to_do)
      {
        if (this->cache_map_.current_size () >= cache_maximum_)
          {
            retval = -1;
            if (TAO_debug_level > 0)
              {
                ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
                  ACE_TEXT("ERROR: unable to bind transport, cache is full\n")));
              }
            more_to_do = false;
          }
        else
          {
            retval = this->cache_map_.bind (ext_id, int_id, entry);
            if (retval == 0)
              {
                // The entry has been added to cache succesfully
                // Add the cache_map_entry to the transport
                int_id.transport ()->cache_map_entry (entry);
                more_to_do = false;
              }
            else if (retval == 1)
              {
                if (entry->item ().transport () == int_id.transport ())
                  {
                    // update the cache status
                    // we are already holding the lock, do not call set_entry_state
                    entry->item ().recycle_state (int_id.recycle_state ());
                    if (TAO_debug_level > 9 &&
                        entry->item ().is_connected () != int_id.is_connected ())
                      ACE_DEBUG ((LM_DEBUG,
                                  ACE_TEXT ("TAO (%P|%t) - Transport_Cache_")
                                  ACE_TEXT ("Manager::bind_i, Updating existing ")
                                  ACE_TEXT ("entry sets is_connected to %C\n"),
                                  (int_id.is_connected () ? "true" : "false")));

                    entry->item ().is_connected (int_id.is_connected ());
                    retval = 0;
                    more_to_do = false;
                  }
                else
                {
                  ext_id.index (ext_id.index () + 1);
                  if (TAO_debug_level > 8)
                    {
                      ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
                        ACE_TEXT ("Unable to bind Transport[%d] @ hash:index{%d:%d}. ")
                        ACE_TEXT ("Trying with a new index\n"),
                        int_id.transport ()->id (),
                        ext_id.hash (),
                        ext_id.index ()));
                    }
                }
              }
            else
              {
                if (TAO_debug_level > 0)
                  {
                    ACE_ERROR ((LM_ERROR,
                      ACE_TEXT("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
                      ACE_TEXT("ERROR: unable to bind transport\n")));
                  }
                more_to_do = false;
              }
          }
      }
    if (retval == 0)
      {
        if (TAO_debug_level > 4)
          {
            ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i: ")
              ACE_TEXT ("Success Transport[%d] @ hash:index{%d:%d}. ")
              ACE_TEXT ("Cache size is [%d]\n"),
              int_id.transport ()->id (),
              ext_id.hash (),
              ext_id.index (),
              this->current_size ()
              ));
          }
      }

#if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
    this->size_monitor_->receive (this->current_size ());
#endif /* TAO_HAS_MONITOR_POINTS==1 */

    return retval;
  }

template<typename TT , typename TRDT , typename PSTRAT >
bool TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::blockable_client_transports ( Connection_Handler_Set handlers  ) 

Return a set of connection handlers that belong to transports that have a RW wait strategy. This call is used for a specific use case by the ORB_Core during shutdown. The only way the ORB can wake up threads waiting on these sockets for replies is to iterate over these blockable transports and close the socket handles. Without these the threads will continue to wait there for ever.

Definition at line 115 of file Transport_Cache_Manager_T.inl.

  {
    ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
                              guard,
                              *this->cache_lock_,
                              false));

    return this->blockable_client_transports_i (handlers);
  }

template<typename TT , typename TRDT , typename PSTRAT >
bool TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::blockable_client_transports_i ( Connection_Handler_Set handlers  )  [private]

Non-locking version of blockable_client_transports ().

Definition at line 439 of file Transport_Cache_Manager_T.cpp.

  {
    HASH_MAP_ITER end_iter = this->cache_map_.end ();

    for (HASH_MAP_ITER iter = this->cache_map_.begin ();
         iter != end_iter;
         ++iter)
      {
        // Get the transport to fill its associated connection's
        // handler.
        bool const retval =
          (*iter).int_id_.transport ()->provide_blockable_handler (h);

        // Do not mark the entry as closed if we don't have a
        // blockable handler added
        if (retval)
          (*iter).int_id_.recycle_state (ENTRY_CLOSED);
      }

    return true;
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::cache_transport ( transport_descriptor_type *  prop,
transport_type *  transport,
Cache_Entries_State  state = ENTRY_IDLE_AND_PURGABLE 
)

Add the transport to the cache.

The transport has the property definition based on which caching can be done. This method sets the cache entry status. By default the status is set to ENTRY_IDLE_AND_PURGABLE

Definition at line 11 of file Transport_Cache_Manager_T.inl.

  {
    // Compose the ExternId & Intid
    Cache_ExtId ext_id (prop);
    int retval = 0;
    {
      ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
                                guard,
                                *this->cache_lock_,
                                -1));
      Cache_IntId int_id (transport);

      // If it has already connected, go directly to the IDLE_BNP state
      if (int_id.is_connected () && state == ENTRY_CONNECTING)
        int_id.recycle_state (ENTRY_IDLE_AND_PURGABLE);
      else
        int_id.recycle_state (state);

      retval = this->bind_i (ext_id, int_id);
    }

    return retval;
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::close ( Connection_Handler_Set handlers  ) 

Close the underlying hash map manager and return any handlers still registered

Definition at line 96 of file Transport_Cache_Manager_T.inl.

  {
    // The cache lock pointer should only be zero if
    // Transport_Cache_Manager_T::open() was never called.  Note that
    // only one thread opens the Transport_Cache_Manager_T at any given
    // time, so it is safe to check for a non-zero lock pointer.
    if (this->cache_lock_ == 0)
      return -1;

    ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
                              guard,
                              *this->cache_lock_,
                              -1));

    return this->close_i (handlers);
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::close_i ( Connection_Handler_Set handlers  )  [private]

Non-locking version and actual implementation of close ().

Definition at line 413 of file Transport_Cache_Manager_T.cpp.

  {
    HASH_MAP_ITER end_iter = this->cache_map_.end ();

    for (HASH_MAP_ITER iter = this->cache_map_.begin ();
         iter != end_iter;
         ++iter)
      {
        // Get the transport to fill its associated connection's handler.
        (*iter).int_id_.transport ()->provide_handler (handlers);

        // Inform the transport that has a reference to the entry in the
        // map that we are *gone* now. So, the transport should not use
        // the reference to the entry that he has, to access us *at any
        // time*.
        (*iter).int_id_.transport ()->cache_map_entry (0);
      }

    // Unbind all the entries in the map
    this->cache_map_.unbind_all ();

    return 0;
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::cpscmp ( const void *  a,
const void *  b 
) [static, private]

Used by qsort.

Definition at line 576 of file Transport_Cache_Manager_T.cpp.

  {
    const HASH_MAP_ENTRY** left  = (const HASH_MAP_ENTRY**)a;
    const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b;

    if ((*left)->int_id_.transport ()->purging_order () <
        (*right)->int_id_.transport ()->purging_order ())
      return -1;

    if ((*left)->int_id_.transport ()->purging_order () >
        (*right)->int_id_.transport ()->purging_order ())
      return 1;

    return 0;
  }

template<typename TT , typename TRDT , typename PSTRAT >
size_t TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::current_size ( void   )  const

Return the current size of the cache.

Definition at line 128 of file Transport_Cache_Manager_T.inl.

  {
    return this->cache_map_.current_size ();
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::fill_set_i ( DESCRIPTOR_SET sorted_set  )  [private]

Fill sorted_set in with the transport_descriptor_type's in a sorted order.

Definition at line 742 of file Transport_Cache_Manager_T.cpp.

  {
    int current_size = 0;
    int const cache_maximum = this->purging_strategy_->cache_maximum ();

    // set sorted_set to 0.  This signifies nothing to purge.
    sorted_set = 0;

    // Do we need to worry about cache purging?
    if (cache_maximum >= 0)
      {
        current_size = static_cast<int> (this->current_size ());

        if (TAO_debug_level > 6)
          {
            ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::fill_set_i, ")
              ACE_TEXT ("current_size = %d, cache_maximum = %d\n"),
              current_size, cache_maximum));
          }

        if (current_size >= cache_maximum)
          {
            ACE_NEW_RETURN (sorted_set, HASH_MAP_ENTRY*[current_size], 0);

            HASH_MAP_ITER iter = this->cache_map_.begin ();

            for (int i = 0; i < current_size; ++i)
              {
                sorted_set[i] = &(*iter);
                ++iter;
              }

            this->sort_set (sorted_set, current_size);
          }
      }

    return current_size;
  }

template<typename TT , typename TRDT , typename PSTRAT >
Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::Find_Result TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::find ( transport_descriptor_type *  prop,
transport_type *&  transport,
size_t &  busy_count 
) [private]

Lookup entry<key,value> in the cache. Grabs the lock and calls the implementation function find_i.

Definition at line 81 of file Transport_Cache_Manager_T.inl.

  {
    ACE_MT (ACE_GUARD_RETURN  (ACE_Lock,
                               guard,
                               *this->cache_lock_,
                               CACHE_FOUND_NONE));

    return this->find_i (prop, transport, busy_count);
  }

template<typename TT , typename TRDT , typename PSTRAT >
Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::Find_Result TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::find_i ( transport_descriptor_type *  prop,
transport_type *&  transport,
size_t &  busy_count 
) [private]

Non-locking version and actual implementation of find () call. This calls the find () on the underlying Hash_Map_Manager. If the find succeeds, it calls the get_idle_transport ().

Definition at line 282 of file Transport_Cache_Manager_T.cpp.

  {
    // Get the entry from the Hash Map
    Find_Result found = CACHE_FOUND_NONE;

    // Make a temporary object. It does not do a copy.
    Cache_ExtId key (prop);
    HASH_MAP_ENTRY *entry = 0;
    busy_count = 0;
    int cache_status = 0;
    HASH_MAP_ENTRY *found_entry = 0;

    // loop until we find a usable transport, or until we've checked
    // all cached entries for this endpoint
    while (found != CACHE_FOUND_AVAILABLE && cache_status == 0)
      {
        entry = 0;
        cache_status = this->cache_map_.find (key, entry);
        if (cache_status == 0 && entry)
          {
            if (this->is_entry_available_i (*entry))
              {
                // Successfully found a transport_type.

                found = CACHE_FOUND_AVAILABLE;
                found_entry = entry;
                entry->item ().recycle_state (ENTRY_BUSY);

                if (TAO_debug_level > 6)
                  {
                    ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::find_i, ")
                      ACE_TEXT ("Found available Transport[%d] @hash:index {%d:%d}\n"),
                      entry->item ().transport ()->id (),
                      entry->ext_id_.hash (),
                      entry->ext_id_.index ()
                      ));
                  }
              }
            else if (this->is_entry_connecting_i (*entry))
              {
                if (TAO_debug_level > 6)
                  {
                    ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::find_i, ")
                      ACE_TEXT ("Found connecting Transport[%d] @hash:index {%d:%d}\n"),
                      entry->item ().transport ()->id (),
                      entry->ext_id_.hash (),
                      entry->ext_id_.index ()
                      ));
                  }
                // if this is the first interesting entry
                if (found != CACHE_FOUND_CONNECTING)
                  {
                    found_entry = entry;
                    found = CACHE_FOUND_CONNECTING;
                  }
              }
            else
              {
                // if this is the first busy entry
                if (found == CACHE_FOUND_NONE && busy_count == 0)
                  {
                    found_entry = entry;
                    found = CACHE_FOUND_BUSY;
                  }
                ++busy_count;
                if (TAO_debug_level > 6)
                  {
                    ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::find_i, ")
                      ACE_TEXT ("Found busy Transport[%d] @hash:index {%d:%d}\n"),
                      entry->item ().transport ()->id (),
                      entry->ext_id_.hash (),
                      entry->ext_id_.index ()
                      ));
                  }
              }
          }

        // Bump the index up
        key.incr_index ();
      }
    if (found_entry != 0)
    {
      transport = found_entry->item ().transport ();
      transport->add_reference ();
      if (found == CACHE_FOUND_AVAILABLE)
        {
          // Update the purging strategy information while we
          // are holding our lock
          this->purging_strategy_->update_item (transport);
        }
    }
    return found;
  }

template<typename TT , typename TRDT , typename PSTRAT >
Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::Find_Result TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::find_transport ( transport_descriptor_type *  prop,
transport_type *&  transport,
size_t &  busy_count 
)

Check the Transport Cache to check whether the connection exists in the Cache and return the connection

Definition at line 233 of file Transport_Cache_Manager_T.cpp.

  {
    if (prop == 0)
      {
        transport = 0;
        return CACHE_FOUND_NONE;
      }

    Find_Result find_result = this->find (
      prop, transport, busy_count);
    if (find_result != CACHE_FOUND_NONE)
      {
        if (find_result == CACHE_FOUND_AVAILABLE)
          {
            if (transport->wait_strategy ()->non_blocking () == 0 &&
                transport->orb_core ()->client_factory ()->use_cleanup_options ())
              {
                ACE_Event_Handler * const eh =
                  transport->event_handler_i ();

                ACE_Reactor * const r =
                  transport->orb_core ()->reactor ();

                if (eh &&
                    r->remove_handler (eh,
                                       ACE_Event_Handler::READ_MASK |
                                       ACE_Event_Handler::DONT_CALL) == -1)
                  {
                    if (TAO_debug_level > 0)
                      ACE_ERROR ((LM_ERROR,
                                  ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T[%d]")
                                  ACE_TEXT ("::find_transport, remove_handler failed\n"),
                                  transport->id ()));
                  }
                else
                  {
                    transport->wait_strategy ()->is_registered (false);
                  }
              }
          }
      }
    return find_result;
  }

template<typename TT , typename TRDT , typename PSTRAT >
bool TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::is_entry_available_i ( const HASH_MAP_ENTRY entry  )  [private]

Tries to find if the int_id_ in entry is available for use.

Definition at line 497 of file Transport_Cache_Manager_T.cpp.

  {
    Cache_Entries_State entry_state = entry.int_id_.recycle_state ();
    bool result = (entry_state == ENTRY_IDLE_AND_PURGABLE);

    if (result && entry.int_id_.transport () != 0)
    {
      // if it's not connected, it's not available
      result = entry.int_id_.is_connected ();
    }

    if (TAO_debug_level > 8)
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::")
                    ACE_TEXT ("is_entry_available_i[%d], %C state is %C\n"),
                    entry.int_id_.transport () ? entry.int_id_.transport ()->id () : 0,
                    (result ? "true" : "false"),
                    Cache_IntId::state_name (entry_state)));
      }

    return result;
  }

template<typename TT , typename TRDT , typename PSTRAT >
bool TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::is_entry_connecting_i ( const HASH_MAP_ENTRY entry  )  [private]

Tries to find if the int_id_ in entry is connect pending

Definition at line 547 of file Transport_Cache_Manager_T.cpp.

  {
    Cache_Entries_State entry_state = entry.int_id_.recycle_state ();
    bool result = (entry_state == ENTRY_CONNECTING);

    if (!result && entry.int_id_.transport () != 0)
      {
        // if we're not connected, that counts, too.
        // Can this happen?  Not sure <wilsond@ociweb.com>
        result = !entry.int_id_.is_connected ();
      }

    if (TAO_debug_level > 8)
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::")
                    ACE_TEXT ("is_entry_connecting_i[%d], %C, state is %C\n"),
                    entry.int_id_.transport () ? entry.int_id_.transport ()->id () : 0,
                    (result ? "true" : "false"),
                    Cache_IntId::state_name (entry_state)));
      }

    return result;
  }

template<typename TT , typename TRDT , typename PSTRAT >
bool TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::is_entry_purgable_i ( HASH_MAP_ENTRY entry  )  [private]

Tries to find if the int_id_ in entry is purgable

Definition at line 523 of file Transport_Cache_Manager_T.cpp.

  {
    Cache_Entries_State entry_state = entry.int_id_.recycle_state ();
    transport_type* transport = entry.int_id_.transport ();
    bool result = (entry_state == ENTRY_IDLE_AND_PURGABLE ||
                   entry_state == ENTRY_PURGABLE_BUT_NOT_IDLE)
                   && transport->can_be_purged ();

    if (TAO_debug_level > 8)
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::")
                    ACE_TEXT ("is_entry_purgable_i[%d], %C state is %C\n"),
                    entry.int_id_.transport ()->id (),
                    (result ? "true" : "false"),
                    Cache_IntId::state_name (entry_state)));
      }

    return result;
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::make_idle ( HASH_MAP_ENTRY entry  ) 

Make the entry idle and ready for use.

Definition at line 73 of file Transport_Cache_Manager_T.inl.

  {
    ACE_MT (ACE_GUARD_RETURN (ACE_Lock, guard, *this->cache_lock_, -1));
    return this->make_idle_i (entry);
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::make_idle_i ( HASH_MAP_ENTRY entry  )  [private]

Non-locking version and actual implementation of make_idle ().

Definition at line 384 of file Transport_Cache_Manager_T.cpp.

  {
    if (entry == 0)
      return -1;

    entry->item ().recycle_state (ENTRY_IDLE_AND_PURGABLE);

    return 0;
  }

template<typename TT , typename TRDT , typename PSTRAT >
Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::HASH_MAP & TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::map ( void   ) 

Return the underlying cache map.

Definition at line 142 of file Transport_Cache_Manager_T.inl.

  {
    return this->cache_map_;
  }

template<typename TT , typename TRDT , typename PSTRAT >
void TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::mark_connected ( HASH_MAP_ENTRY entry,
bool  state 
)

Mark the entry as connected.

Definition at line 56 of file Transport_Cache_Manager_T.inl.

  {
    ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->cache_lock_));
    if (entry == 0)
      return;

    if (TAO_debug_level > 9 && state != entry->item ().is_connected ())
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T")
                  ACE_TEXT ("::mark_connected, %s Transport[%d]\n"),
                  (state ? ACE_TEXT("true") : ACE_TEXT("false")),
                  entry->item ().transport ()->id ()
                  ));
    entry->item().is_connected (state);
  }

template<typename TT , typename TRDT , typename PSTRAT >
void TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::mark_invalid ( HASH_MAP_ENTRY entry  ) 

Mark the entry as invalid for use but keep it in cache.

Definition at line 48 of file Transport_Cache_Manager_T.inl.

  {
    ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->cache_lock_));
    this->mark_invalid_i (entry);
  }

template<typename TT , typename TRDT , typename PSTRAT >
void TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::mark_invalid_i ( HASH_MAP_ENTRY entry  )  [private]

Mark the entry as invalid for use but keep it in cache.

Definition at line 486 of file Transport_Cache_Manager_T.cpp.

  {
    if (entry != 0)
      {
        // Mark the entry as not usable
        entry->item ().recycle_state (ENTRY_PURGABLE_BUT_NOT_IDLE);
      }
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::purge ( void   ) 

Remove entries from the cache depending upon the strategy.

Definition at line 595 of file Transport_Cache_Manager_T.cpp.

  {
    typedef ACE_Unbounded_Set<transport_type*> transport_set_type;
    transport_set_type transports_to_be_closed;

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

      DESCRIPTOR_SET sorted_set = 0;
      int const sorted_size = this->fill_set_i (sorted_set);

      // Only call close_entries () if sorted_set != 0.  It takes
      // control of sorted_set and cleans up any allocated memory.  If
      // sorted_set == 0, then there is nothing to de-allocate.
      if (sorted_set != 0)
        {
          // BEGIN FORMER close_entries
          // Calculate the number of entries to purge, when we have
          // to purge try to at least to purge minimal of 1 entry
          // which is needed if we have a very small cache maximum
          int const amount = (sorted_size * this->percent_) / 100;

          if (TAO_debug_level > 4)
            {
              ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::purge, ")
                ACE_TEXT ("Trying to purge %d of %d cache entries\n"),
                amount,
                sorted_size));
            }

          int count = 0;

          for (int i = 0; count < amount && i < sorted_size; ++i)
            {
              if (this->is_entry_purgable_i (*sorted_set[i]))
                {
                  transport_type* transport =
                    sorted_set[i]->int_id_.transport ();
                  sorted_set[i]->int_id_.recycle_state (ENTRY_BUSY);
                  transport->add_reference ();

                  if (TAO_debug_level > 4)
                    {
                      ACE_DEBUG ((LM_INFO,
                        ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::purge, ")
                        ACE_TEXT ("Purgable Transport[%d] found in ")
                        ACE_TEXT ("cache\n"),
                        transport->id ()));
                    }

                  if (transports_to_be_closed.insert_tail (transport) != 0)
                    {
                      if (TAO_debug_level > 0)
                        {
                          ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T")
                            ACE_TEXT ("::purge, Unable to add transport[%d] ")
                            ACE_TEXT ("on the to-be-closed set, so ")
                            ACE_TEXT ("it will not be purged\n"),
                            transport->id ()));
                        }
                      transport->remove_reference ();
                    }

                  // Count this as a successful purged entry
                  ++count;
                }
            }

          delete [] sorted_set;
          sorted_set = 0;
          // END FORMER close_entries
        }
    }

    // Now, without the lock held, lets go through and close all the transports.
    if (! transports_to_be_closed.is_empty ())
      {
        typename transport_set_type::iterator it (transports_to_be_closed);
        while (! it.done ())
          {
            transport_type *transport = *it;

            it.advance ();

            if (transport)
              {
                transport->close_connection ();
                transport->remove_reference ();
              }
          }
      }

    if (TAO_debug_level > 4)
      {
        ACE_DEBUG ((LM_INFO,
          ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::purge, ")
          ACE_TEXT ("Cache size after purging is [%d]\n"),
          this->current_size ()
          ));
      }

#if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
    /// The value doesn't matter, all we need is the timestamp,
    /// which is added automatically.
    this->purge_monitor_->receive (static_cast<size_t> (0UL));
    /// And update the size monitor as well.
    this->size_monitor_->receive (this->current_size ());
#endif /* TAO_HAS_MONITOR_POINTS==1 */

    return 0;
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::purge_entry ( HASH_MAP_ENTRY *&  entry  ) 

Purge the entry from the Cache Map.

Definition at line 40 of file Transport_Cache_Manager_T.inl.

  {
    ACE_MT (ACE_GUARD_RETURN (ACE_Lock, guard, *this->cache_lock_, -1));
    return this->purge_entry_i (entry);
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::purge_entry_i ( HASH_MAP_ENTRY *&  entry  )  [private]

Purge the entry from the Cache Map.

Definition at line 464 of file Transport_Cache_Manager_T.cpp.

  {
    int retval = 0;

    if (entry != 0)
      {
        // Remove the entry from the Map
        retval = this->cache_map_.unbind (entry);

        // Set the entry pointer to zero
        entry = 0;

#if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
        this->size_monitor_->receive (this->current_size ());
#endif /* TAO_HAS_MONITOR_POINTS==1 */
      }

    return retval;
  }

template<typename TT , typename TRDT , typename PSTRAT >
void TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::set_entry_state ( HASH_MAP_ENTRY entry,
TAO::Cache_Entries_State  state 
)

Modify the state setting on the provided entry.

Definition at line 100 of file Transport_Cache_Manager_T.cpp.

  {
    ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->cache_lock_));
    if (entry != 0)
      {
        entry->item ().recycle_state (state);
        if (state != ENTRY_UNKNOWN && state != ENTRY_CONNECTING
            && entry->item ().transport ())
          entry->item ().is_connected (
            entry->item ().transport ()->is_connected ());
      }
  }

template<typename TT , typename TRDT , typename PSTRAT >
void TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::sort_set ( DESCRIPTOR_SET entries,
int  size 
) [private]

Sort the list of entries.

Definition at line 712 of file Transport_Cache_Manager_T.cpp.

  {
#if defined (ACE_LACKS_QSORT)
    // Use insertion sort if we don't have qsort
    for(int i = 1; i < current_size; ++i)
      {
        if (entries[i]->int_id_.transport ()->purging_order () <
            entries[i - 1]->int_id_.transport ()->purging_order ())
          {
            HASH_MAP_ENTRY* entry = entries[i];

            for(int j = i; j > 0 &&
                  entries[j - 1]->int_id_.transport ()->purging_order () >
                  entry->item ().transport ()->purging_order (); --j)
              {
                HASH_MAP_ENTRY* holder = entries[j];
                entries[j] = entries[j - 1];
                entries[j - 1] = holder;
              }
          }
      }
#else
    ACE_OS::qsort (entries, current_size,
                   sizeof (HASH_MAP_ENTRY*), (ACE_COMPARE_FUNC)cpscmp);
#endif /* ACE_LACKS_QSORT */
  }

template<typename TT , typename TRDT , typename PSTRAT >
size_t TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::total_size ( void   )  const

Return the total size of the cache.

Definition at line 135 of file Transport_Cache_Manager_T.inl.

  {
    return this->cache_map_.total_size ();
  }

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::update_entry ( HASH_MAP_ENTRY *&  entry  ) 

Mark the entry as touched. This call updates the purging strategy policy information.

Definition at line 396 of file Transport_Cache_Manager_T.cpp.

  {
    ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
                              guard,
                              *this->cache_lock_, -1));

    if (entry == 0)
      return -1;

    purging_strategy *st = this->purging_strategy_;
    (void) st->update_item (entry->item ().transport ());

    return 0;
  }


Member Data Documentation

template<typename TT , typename TRDT , typename PSTRAT >
ACE_Lock* TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::cache_lock_ [private]

The lock that is used by the cache map.

Definition at line 260 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
HASH_MAP TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::cache_map_ [private]

The hash map that has the connections.

Definition at line 255 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
TAO_SYNCH_MUTEX TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::cache_map_mutex_ [private]

Definition at line 257 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
size_t TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::cache_maximum_ [private]

Maximum size of the cache.

Definition at line 263 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
int TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::percent_ [private]

The percentage of the cache to purge at one time.

Definition at line 249 of file Transport_Cache_Manager_T.h.

template<typename TT , typename TRDT , typename PSTRAT >
purging_strategy* TAO::Transport_Cache_Manager_T< TT, TRDT, PSTRAT >::purging_strategy_ [private]

The underlying connection purging strategy.

Definition at line 252 of file Transport_Cache_Manager_T.h.


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