diff options
author | oci <oci@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-05-18 19:27:05 +0000 |
---|---|---|
committer | oci <oci@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-05-18 19:27:05 +0000 |
commit | 0661dd27de83c0eea45fe67c3a7cd668362d53d4 (patch) | |
tree | 141dfe6e8587b0adf7cb25ebc8b330222b3048cc | |
parent | 8d3d2962261c5d593e40ee773564ded7bed60a52 (diff) | |
download | ATCD-0661dd27de83c0eea45fe67c3a7cd668362d53d4.tar.gz |
ChangeLogTag: Fri May 18 14:23:22 2001 Chad Elliott <elliott_c@ociweb.com>
40 files changed, 573 insertions, 803 deletions
diff --git a/TAO/ChangeLogs/ChangeLog-02a b/TAO/ChangeLogs/ChangeLog-02a index adf7b2c84b1..a936f3653a4 100644 --- a/TAO/ChangeLogs/ChangeLog-02a +++ b/TAO/ChangeLogs/ChangeLog-02a @@ -1,3 +1,52 @@ +Fri May 18 14:23:22 2001 Chad Elliott <elliott_c@ociweb.com> + + * examples/PluggableUDP/DIOP/DIOP_Connection_Handler.cpp: + * orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp: + * orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp: + * orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp: + * tao/Acceptor_Impl.cpp: + * tao/Cache_Entries.cpp: + * tao/Cache_Entries.h: + * tao/Cache_Entries.inl: + * tao/Connection_Purging_Strategy.cpp: + * tao/Connection_Purging_Strategy.h: + * tao/Connection_Purging_Strategy.inl: + * tao/IIOP_Connection_Handler.cpp: + * tao/IIOP_Connector.cpp: + * tao/LRU_Connection_Purging_Strategy.cpp: + * tao/LRU_Connection_Purging_Strategy.h: + * tao/ORB_Core.cpp: + * tao/ORB_Core.h: + * tao/ORB_Core.i: + * tao/Transport.cpp: + * tao/Transport_Cache_Manager.cpp: + * tao/Transport_Cache_Manager.h: + * tao/Transport_Cache_Manager.inl: + * tao/default_resource.cpp: + * tao/Strategies/FIFO_Connection_Purging_Strategy.cpp: + * tao/Strategies/FIFO_Connection_Purging_Strategy.h: + * tao/Strategies/LFU_Connection_Purging_Strategy.cpp: + * tao/Strategies/LFU_Connection_Purging_Strategy.h: + * tao/Strategies/NULL_Connection_Purging_Strategy.cpp: + * tao/Strategies/NULL_Connection_Purging_Strategy.h: + * tao/Strategies/SHMIOP_Connection_Handler.cpp: + * tao/Strategies/SHMIOP_Connector.cpp: + * tao/Strategies/UIOP_Connection_Handler.cpp: + * tao/Strategies/UIOP_Connector.cpp: + * tao/Strategies/advanced_resource.cpp: + * tests/BiDirectional/test_i.cpp: + * tests/BiDirectional_NestedUpcall/test_i.cpp: + + Merged most of the Connection Purging code into the + Transport_Cache_Manger to simplify things and to reduce the + footprint size. + + * tests/Connection_Purging/client.fifo.conf: + * tests/Connection_Purging/client.lfu.conf: + * tests/Connection_Purging/client.lru.conf: + + Fix the usage of a deprecated option. + Fri May 18 12:23:31 2001 Frank Hunleth <fhunleth@cs.wustl.edu> * examples/PluggableUDP/DIOP/DIOP_Connector.cpp: diff --git a/TAO/examples/PluggableUDP/DIOP/DIOP_Connection_Handler.cpp b/TAO/examples/PluggableUDP/DIOP/DIOP_Connection_Handler.cpp index dd7cf1beb2e..a5bf8eb3025 100644 --- a/TAO/examples/PluggableUDP/DIOP/DIOP_Connection_Handler.cpp +++ b/TAO/examples/PluggableUDP/DIOP/DIOP_Connection_Handler.cpp @@ -8,7 +8,7 @@ #include "tao/CDR.h" #include "tao/Messaging_Policy_i.h" #include "tao/Server_Strategy_Factory.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "tao/Base_Transport_Property.h" #include "DIOP_Connection_Handler.h" @@ -274,8 +274,8 @@ TAO_DIOP_Connection_Handler::add_transport_to_cache (void) TAO_Base_Transport_Property prop (&endpoint); // Add the handler to Cache - return this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - this->transport ()); + return this->orb_core ()->transport_cache ()->cache_transport (&prop, + this->transport ()); } // @@ Frank: Hopefully this isn't needed diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp index 5052822e66a..f6a23bdbdfc 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp @@ -10,7 +10,7 @@ #include "tao/Environment.h" #include "tao/Base_Transport_Property.h" #include "tao/IIOP_Endpoint.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "ace/Strategies_T.h" @@ -159,8 +159,8 @@ TAO_IIOP_SSL_Connector::connect (TAO_Transport_Descriptor_Interface *desc, TAO_Transport *base_transport = 0; // Check the Cache first for connections - if (this->orb_core ()->purging_strategy ()->find_in_cache (desc, - base_transport) == 0) + if (this->orb_core ()->transport_cache ()->cache_transport (desc, + base_transport) == 0) { if (TAO_debug_level > 5) ACE_DEBUG ((LM_DEBUG, @@ -176,7 +176,7 @@ TAO_IIOP_SSL_Connector::connect (TAO_Transport_Descriptor_Interface *desc, ACE_TEXT ("making a new connection \n"))); // Purge connections (if necessary) - this->orb_core ()->purging_strategy ()->purge (); + this->orb_core ()->transport_cache ()->purge (); // @@ This needs to change in the next round when we implement a // policy that will not allow new connections when a connection @@ -227,8 +227,8 @@ TAO_IIOP_SSL_Connector::connect (TAO_Transport_Descriptor_Interface *desc, base_transport = TAO_Transport::_duplicate (svc_handler->transport ()); // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (desc, - base_transport); + this->orb_core ()->transport_cache ()->cache_transport (desc, + base_transport); if (retval != 0 && TAO_debug_level > 0) { diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp index f536347b121..8ed0bb56cf9 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp @@ -13,7 +13,7 @@ #include "tao/Messaging_Policy_i.h" #include "tao/Server_Strategy_Factory.h" #include "tao/IIOP_Endpoint.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #if !defined (__ACE_INLINE__) @@ -253,8 +253,8 @@ TAO_SSLIOP_Connection_Handler::add_transport_to_cache (void) TAO_Base_Transport_Property prop (&endpoint); // Add the handler to Cache - return this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - this->transport ()); + return this->orb_core ()->transport_cache ()->cache_transport (&prop, + this->transport ()); } diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp index 78a843576db..ddfbefac10d 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp @@ -9,7 +9,7 @@ #include "tao/ORB_Core.h" #include "tao/Client_Strategy_Factory.h" #include "tao/Environment.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "ace/Auto_Ptr.h" ACE_RCSID (TAO_SSLIOP, @@ -207,8 +207,8 @@ TAO_SSLIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, TAO_Transport *base_transport = 0; // Check the Cache first for connections - if (this->orb_core ()->purging_strategy ()->find_in_cache (desc, - base_transport) == 0) + if (this->orb_core ()->transport_cache ()->cache_transport (desc, + base_transport) == 0) { if (TAO_debug_level > 5) ACE_DEBUG ((LM_DEBUG, @@ -224,7 +224,7 @@ TAO_SSLIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, ACE_TEXT ("making a new connection \n"))); // Purge connections (if necessary) - this->orb_core ()->purging_strategy ()->purge (); + this->orb_core ()->transport_cache ()->purge (); // @@ This needs to change in the next round when we implement a // policy that will not allow new connections when a connection @@ -275,8 +275,8 @@ TAO_SSLIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, base_transport = TAO_Transport::_duplicate (svc_handler->transport ()); // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (desc, - base_transport); + this->orb_core ()->transport_cache ()->cache_transport (desc, + base_transport); if (retval != 0 && TAO_debug_level > 0) { diff --git a/TAO/tao/Acceptor_Impl.cpp b/TAO/tao/Acceptor_Impl.cpp index 896d50aa2d0..208ee97a8bc 100644 --- a/TAO/tao/Acceptor_Impl.cpp +++ b/TAO/tao/Acceptor_Impl.cpp @@ -29,7 +29,7 @@ #include "tao/ORB_Table.h" #include "tao/Server_Strategy_Factory.h" #include "tao/Connector_Registry.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "ace/Object_Manager.h" @@ -58,7 +58,7 @@ TAO_Creation_Strategy<SVC_HANDLER>::make_svc_handler (SVC_HANDLER *&sh) if (sh == 0) { // Purge connections (if necessary) - this->orb_core_->purging_strategy ()->purge (); + this->orb_core_->transport_cache ()->purge (); ACE_NEW_RETURN (sh, SVC_HANDLER (this->orb_core_, diff --git a/TAO/tao/Cache_Entries.cpp b/TAO/tao/Cache_Entries.cpp index 9c7e17f0273..f58a7dc2bca 100644 --- a/TAO/tao/Cache_Entries.cpp +++ b/TAO/tao/Cache_Entries.cpp @@ -12,7 +12,8 @@ ACE_RCSID(tao, Cache_Entries, "$Id$") TAO_Cache_IntId::TAO_Cache_IntId (TAO_Transport *transport) : transport_ (TAO_Transport::_duplicate (transport)), - recycle_state_ (ACE_RECYCLABLE_UNKNOWN) + recycle_state_ (ACE_RECYCLABLE_UNKNOWN), + purging_order_ (0) { } @@ -26,6 +27,7 @@ TAO_Cache_IntId::operator= (const TAO_Cache_IntId &rhs) { if (this != &rhs) { this->recycle_state_ = rhs.recycle_state_; + this->purging_order_ = rhs.purging_order_; TAO_Transport* old_transport = this->transport_; this->transport_ = TAO_Transport::_duplicate (rhs.transport_); diff --git a/TAO/tao/Cache_Entries.h b/TAO/tao/Cache_Entries.h index fc497013272..be74717c805 100644 --- a/TAO/tao/Cache_Entries.h +++ b/TAO/tao/Cache_Entries.h @@ -94,13 +94,21 @@ public: */ TAO_Transport *relinquish_transport (void); -private: + /// Return the order for the purging strategy + unsigned long purging_order (void) const; + + /// Allow the purging strategy to set the order + void purging_order(unsigned long value); +private: /// The transport that needs to be cached. TAO_Transport *transport_; /// The state of the handle ACE_Recyclable_State recycle_state_; + + /// Used by the LRU, LFU and FIFO Connection Purging Strategies + unsigned long purging_order_; }; diff --git a/TAO/tao/Cache_Entries.inl b/TAO/tao/Cache_Entries.inl index 1e6bbc118fb..2ff9c520e1f 100644 --- a/TAO/tao/Cache_Entries.inl +++ b/TAO/tao/Cache_Entries.inl @@ -4,14 +4,16 @@ ACE_INLINE TAO_Cache_IntId::TAO_Cache_IntId (void) : transport_ (0), - recycle_state_ (ACE_RECYCLABLE_UNKNOWN) + recycle_state_ (ACE_RECYCLABLE_UNKNOWN), + purging_order_ (0) { } ACE_INLINE TAO_Cache_IntId::TAO_Cache_IntId (const TAO_Cache_IntId &rhs) : transport_ (0), - recycle_state_ (ACE_RECYCLABLE_UNKNOWN) + recycle_state_ (ACE_RECYCLABLE_UNKNOWN), + purging_order_ (0) { *this = rhs; } @@ -61,6 +63,18 @@ TAO_Cache_IntId::relinquish_transport (void) return val; } +ACE_INLINE unsigned long +TAO_Cache_IntId::purging_order (void) const +{ + return this->purging_order_; +} + +ACE_INLINE void +TAO_Cache_IntId::purging_order (unsigned long value) +{ + this->purging_order_ = value; +} + /*******************************************************/ ACE_INLINE TAO_Cache_ExtId::TAO_Cache_ExtId (void) diff --git a/TAO/tao/Connection_Purging_Strategy.cpp b/TAO/tao/Connection_Purging_Strategy.cpp index 30c22fda712..01f0bfa8500 100644 --- a/TAO/tao/Connection_Purging_Strategy.cpp +++ b/TAO/tao/Connection_Purging_Strategy.cpp @@ -1,8 +1,6 @@ // $Id$ #include "tao/Connection_Purging_Strategy.h" -#include "tao/Resource_Factory.h" -#include "tao/Transport.h" #if !defined (__ACE_INLINE__) # include "tao/Connection_Purging_Strategy.inl" @@ -10,217 +8,15 @@ ACE_RCSID(tao, Connection_Purging_Strategy, "$Id$") -TAO_Connection_Purging_Strategy::TAO_Connection_Purging_Strategy ( - TAO_Resource_Factory* rf) - : cache_maximum_ (rf->cache_maximum ()), - percent_(rf->purge_percentage ()), - lock_(rf->create_cached_connection_lock ()), - cache_manager_ () -{ - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_Connection_Purging_Strategy::") - ACE_TEXT ("TAO_Connection_Purging_Strategy\n"))); - } -} - - TAO_Connection_Purging_Strategy::~TAO_Connection_Purging_Strategy (void) { - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_Connection_Purging_Strategy::") - ACE_TEXT ("~TAO_Connection_Purging_Strategy\n"))); - } - delete lock_; -} - - -void -TAO_Connection_Purging_Strategy::close_entries(DESCRIPTOR_SET& sorted_set) -{ - const int sorted_size = sorted_set.size (); - const int amount = (sorted_size * this->percent ()) / 100; - - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("Purging %d of %d cache entries\n"), - amount, - sorted_size)); - } - - for(int i = 0; i < sorted_size; i++) - { - TAO_DESCRIPTOR_INTERFACE* prop = sorted_set[i]; - if (i < amount) - { - TAO_PURGING_CACHE_ITEM* item = 0; - if (this->cache_manager ().find_transport (prop, item) == 0) - { - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("Idle item found in ") - ACE_TEXT ("cache: 0x%x\n"), - item)); - } - - // Eventually calls purge_from_cache() on the cache - // which will call remove_item_i() on us. - item->close_connection (); - } - } - delete prop; - } -} - - -// ====================================================================== - -TAO_ULong_Connection_Purging_Strategy::TAO_ULong_Connection_Purging_Strategy ( - TAO_Resource_Factory* rf) - : TAO_Connection_Purging_Strategy (rf) -{ -} - - -TAO_ULong_Connection_Purging_Strategy::~TAO_ULong_Connection_Purging_Strategy () -{ } int -TAO_ULong_Connection_Purging_Strategy::fill_set_i (DESCRIPTOR_SET& sorted_set) +TAO_Connection_Purging_Strategy::cache_maximum (void) const { - int current_size = this->tracking_map_.current_size (); - int amount = current_size - this->cache_maximum (); - - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_ULong_Connection_Purging_Strategy") - ACE_TEXT ("::fill_set_i - %d %d\n"), - current_size, - this->cache_maximum ())); - } - - if (amount >= 0) - { - // I could not use ACE_Array_Base<HASH_MAP_ENTRY*> because - // the compiler kept complaining about HASH_MAP_ENTRY not having - // a default construtor. - HASH_MAP_ENTRY** entries; - ACE_NEW_RETURN(entries, HASH_MAP_ENTRY*[current_size], 0); - sorted_set.size (current_size); - - int i; - HASH_MAP_ITER iter = this->tracking_map_.begin (); - for (i = 0; i < current_size; i++) - { - entries[i] = &(*iter); - iter++; - } - - this->sort_set (entries, current_size); - - for(i = 0; i < current_size; i++) - { - // The owner of the sorted_set array accepts responsibility - // for deleting the memory allocated here. - sorted_set[i] = entries[i]->ext_id_.property ()->duplicate (); - } - - delete [] entries; - } - - return (amount >= 0); -} - - -void -TAO_ULong_Connection_Purging_Strategy::remove_item_i ( - TAO_DESCRIPTOR_INTERFACE* prop) -{ - TAO_Cache_ExtId ext_id (prop); - this->tracking_map_.unbind (ext_id); -} - - -void -TAO_ULong_Connection_Purging_Strategy::remove_all_i () -{ - this->tracking_map_.unbind_all (); -} - - -#if !defined (ACE_LACKS_QSORT) -int -TAO_ULong_Connection_Purging_Strategy::cpscmp(const void* a, const void* b) -{ - const HASH_MAP_ENTRY** left = (const HASH_MAP_ENTRY**)a; - const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b; - - if ((*left)->int_id_ > (*right)->int_id_) - return 1; - - if ((*left)->int_id_ < (*right)->int_id_) - return -1; - - return 0; + return cache_maximum_; } -#endif /* ACE_LACKS_QSORT */ - - -void -TAO_ULong_Connection_Purging_Strategy::sort_set (HASH_MAP_ENTRY**& entries, - int current_size) -{ -#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_ < - entries[i - 1]->int_id_) - { - HASH_MAP_ENTRY* entry = entries[i]; - for(int j = i; j > 0 && - entries[j - 1]->int_id_ > - entry->int_id_; 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 */ -} - - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Array_Base<TAO_Transport_Descriptor_Interface*>; -template class ACE_Hash_Map_Entry<TAO_Cache_ExtId, unsigned long>; -template class ACE_Hash_Map_Manager<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex>; -template class ACE_Hash_Map_Manager_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Base_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Array_Base<TAO_Transport_Descriptor_Interface*> -#pragma instantiate ACE_Hash_Map_Entry<TAO_Cache_ExtId, unsigned long> -#pragma instantiate ACE_Hash_Map_Manager<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Manager_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/Connection_Purging_Strategy.h b/TAO/tao/Connection_Purging_Strategy.h index c5d67e0828e..26197f8ac66 100644 --- a/TAO/tao/Connection_Purging_Strategy.h +++ b/TAO/tao/Connection_Purging_Strategy.h @@ -12,179 +12,45 @@ #define TAO_PURGING_STRATEGY_H #include "ace/pre.h" -// @@ Chad : Please add the PRAGMA stuff.. -// @@ Chad : As a matter of consistency place the keyword void for -// functions with no arguments.. +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "tao/Transport_Cache_Manager.h" // Data member -#include "tao/debug.h" // Debug used in the .inl -#include "ace/Array_Base.h" // Template definition +#include "corbafwd.h" -class TAO_Resource_Factory; +class TAO_Cache_IntId; -typedef TAO_Transport_Cache_Manager TAO_PURGING_CACHE_MANAGER; -typedef TAO_Transport_Descriptor_Interface TAO_DESCRIPTOR_INTERFACE; -typedef TAO_Transport TAO_PURGING_CACHE_ITEM; -typedef TAO_Transport_Cache_Manager::HASH_MAP_ENTRY TAO_PURGING_MAP_ENTRY; +// **************************************************************** + +/** + * @class TAO_Connection_Purging_Strategy + * + * @brief The base class for all purging strategies + * + * This class is used by the Transport_Cache_Manager to maintain + * ordering information on each Transport that is created. + */ class TAO_Export TAO_Connection_Purging_Strategy { public: /// The constructor - TAO_Connection_Purging_Strategy (TAO_Resource_Factory* rf); + TAO_Connection_Purging_Strategy (int cache_maximum); /// The destructor - virtual ~TAO_Connection_Purging_Strategy (); - - /// Get the purging percentage - int percent (void) const; - - /// Set the purging percentage - void percent (int pvalue); - - /// Maximum number of entries in the connection cache - int cache_maximum (void) const; - - /// Remove connections based on the underlying strategy - int purge (void); - - /** - * Pass-through methods to provide access to the cache manager. - * Use these methods to update information about each item. - */ - //@{ - /// Add the item to the cache. The item has the property - /// definition based on which caching can be done. - int add_to_cache (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item); - - /// Check the cache to see whether the item exists - /// in the cache and return it. - int find_in_cache (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM*& item); - - /// Purge the entry from the cache - int purge_from_cache (TAO_PURGING_MAP_ENTRY*& entry); + virtual ~TAO_Connection_Purging_Strategy (void); - /// Make the entry idle and ready for use. - int make_idle (TAO_PURGING_MAP_ENTRY*& entry); + /// Return the maximum number of cache entries + virtual int cache_maximum (void) const; - /// Mark the entry as invalid for use but keep it in cache. - void mark_invalid (TAO_PURGING_MAP_ENTRY*& entry); - - /// Initialize the cache with <size> elements. - int open_cache (TAO_ORB_Core* orb_core, - size_t size = ACE_DEFAULT_MAP_SIZE); - - /// Close the underlying cache manager and return the handle set - /// that have been registered with the reactor - int close_cache (ACE_Handle_Set &reactor_registered, - TAO_EventHandlerSet &unregistered); - - /// Return the total size of the TAO_PURGING_CACHE_MANAGER. - size_t total_size (void) const; - //@} - -protected: - typedef ACE_Array_Base<TAO_DESCRIPTOR_INTERFACE*> DESCRIPTOR_SET; - - /// Accessor for the cache manager - TAO_PURGING_CACHE_MANAGER& cache_manager (void); - - /// Look through the sorted set and close the connection on - /// the required number of items in the set. - void close_entries (DESCRIPTOR_SET& sorted_set); - - // Sub-classes must implement these methods - virtual int fill_set_i (DESCRIPTOR_SET& sorted_set) = 0; - virtual void update_item_i (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item) = 0; - virtual void remove_item_i (TAO_DESCRIPTOR_INTERFACE* prop) = 0; - virtual void remove_all_i (void) = 0; + /// Sub-classes must implement these methods + virtual void update_item (TAO_Cache_IntId& int_id) = 0; private: - - /// The maximum number of entries in the cache + /// The maximum number of cach entries int cache_maximum_; - - /// The percentage of the cache that will be purged - int percent_; - - /// The lock for the underlying stratgy - ACE_Lock* lock_; - - /// The caching implementation - TAO_PURGING_CACHE_MANAGER cache_manager_; }; - -// @@ Chad: Such defintions dont help us in anyway. Do they?? - -#include "ace/Hash_Map_Manager_T.h" // Template definition - -// @@ Chad: Class description Please.. -// BTW, I dont see a need for a step in the hierarchy.. Can -// you please let me know what is the need for this one step -// in the hierarchy? - Bala -// @@ Chad: If you think this step is required, you may want to put it -// in a seperate file. -// @@ Chad: Why cant all the _i () implementations go in the base -// class? -// @@ Chad: IMHO, we are having too many maps. Remember foot print? -// Can you think of a way to get the info into the Transport map - -class TAO_Export TAO_ULong_Connection_Purging_Strategy: public TAO_Connection_Purging_Strategy -{ -public: - /// The constructor - TAO_ULong_Connection_Purging_Strategy (TAO_Resource_Factory* rf); - - /// The destructor - virtual ~TAO_ULong_Connection_Purging_Strategy (void); - -protected: - - typedef unsigned long ATTRIBUTE_TYPE; - typedef ACE_Hash_Map_Manager <TAO_Cache_ExtId, - ATTRIBUTE_TYPE, - ACE_Null_Mutex> - HASH_MAP; - - /// Fill sorted_set in with the TAO_DESCRIPTOR_INTERFACE's in a - /// sorted order. - virtual int fill_set_i (DESCRIPTOR_SET& sorted_set); - - /// Removes the entry from the tracking_map_ when purge_from_cache() - /// is called. - virtual void remove_item_i (TAO_DESCRIPTOR_INTERFACE* prop); - - /// Remove all entries from tracking_map_ - virtual void remove_all_i (void); - - HASH_MAP& tracking_map (void); - -private: - - typedef ACE_Hash_Map_Iterator <TAO_Cache_ExtId, - ATTRIBUTE_TYPE, - ACE_Null_Mutex> - HASH_MAP_ITER; - typedef ACE_Hash_Map_Entry <TAO_Cache_ExtId, - ATTRIBUTE_TYPE> - HASH_MAP_ENTRY; - -#if !defined(ACE_LACKS_QSORT) - /// Used by qsort - static int cpscmp(const void* a, const void* b); -#endif - - /// Sort the list of entries - void sort_set (HASH_MAP_ENTRY**& entries, int size); - - HASH_MAP tracking_map_; -}; - - #if defined (__ACE_INLINE__) # include "tao/Connection_Purging_Strategy.inl" #endif /* __ACE_INLINE__ */ diff --git a/TAO/tao/Connection_Purging_Strategy.inl b/TAO/tao/Connection_Purging_Strategy.inl index db755dbae0c..b0bc5b7b8f0 100644 --- a/TAO/tao/Connection_Purging_Strategy.inl +++ b/TAO/tao/Connection_Purging_Strategy.inl @@ -1,179 +1,9 @@ // $Id$ - -ACE_INLINE int -TAO_Connection_Purging_Strategy::percent () const -{ - return this->percent_; -} - - -ACE_INLINE void -TAO_Connection_Purging_Strategy::percent (int pvalue) -{ - if (pvalue > 100) - { - pvalue = 100; - } - else if (pvalue < 0) - { - pvalue = 0; - } - this->percent_ = pvalue; -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::cache_maximum () const -{ - return this->cache_maximum_; -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::purge () +ACE_INLINE +TAO_Connection_Purging_Strategy::TAO_Connection_Purging_Strategy ( + int cache_maximum) + : cache_maximum_ (cache_maximum) { - int need_to_purge = 0; - DESCRIPTOR_SET sorted_set; - - // We must use a small scope, since we can't call close_entries() - // if we are holding the lock. - { - ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0); - need_to_purge = this->fill_set_i (sorted_set); - } - - // Only call close_entries () if need_to_purge. It takes control of - // sorted_set and cleans up any allocated memory. If !need_to_purge, - // then there is nothing to de-allocate. - if (need_to_purge) - { - this->close_entries (sorted_set); - } - - return 0; } - -ACE_INLINE int -TAO_Connection_Purging_Strategy::add_to_cache (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item) -{ - if (TAO_debug_level > 0) - { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_Connection_Purging_Strategy") - ACE_TEXT ("::add_to_cache (0x%x, 0x%x)\n"), - prop, item)); - } - int status = this->cache_manager_.cache_transport (prop, item); - - if (status == 0) - { - // Update the item usage information - ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0); - this->update_item_i (prop, item); - } - - return status; -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::find_in_cache ( - TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM*& item) -{ - int status = this->cache_manager_.find_transport (prop, item); - - if (status == 0) - { - // Update the item usage information - ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0); - this->update_item_i (prop, item); - } - - return status; -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::purge_from_cache ( - TAO_PURGING_MAP_ENTRY*& entry) -{ - if (TAO_debug_level > 0) - { - // @@ Chad: Please see how big the ACE_DEBUG expands too. Do you - // think the compilers can inline such a big macros. I dont - // believe so... - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") - ACE_TEXT ("TAO_Connection_Purging_Strategy") - ACE_TEXT ("::purge_from_cache (0x%x)\n"), - entry)); - } - - // Usa a small scope. No need to hold our lock while - // the cache_manager purges it's entry. - { - ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0); - this->remove_item_i (entry->ext_id_.property ()); - } - - return this->cache_manager_.purge_entry (entry); -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::make_idle (TAO_PURGING_MAP_ENTRY*& entry) -{ - return this->cache_manager_.make_idle (entry); -} - - -ACE_INLINE void -TAO_Connection_Purging_Strategy::mark_invalid (TAO_PURGING_MAP_ENTRY*& entry) -{ - this->cache_manager_.mark_invalid (entry); -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::open_cache (TAO_ORB_Core* orb_core, - size_t size) -{ - return this->cache_manager_.open (orb_core, size); -} - - -ACE_INLINE int -TAO_Connection_Purging_Strategy::close_cache ( - ACE_Handle_Set &reactor_registered, - TAO_EventHandlerSet &unregistered) -{ - { - ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0); - this->remove_all_i (); - } - return this->cache_manager_.close (reactor_registered, unregistered); -} - - -ACE_INLINE size_t -TAO_Connection_Purging_Strategy::total_size () const -{ - return this->cache_manager_.total_size (); -} - - -ACE_INLINE TAO_PURGING_CACHE_MANAGER& -TAO_Connection_Purging_Strategy::cache_manager () -{ - return this->cache_manager_; -} - - -ACE_INLINE TAO_ULong_Connection_Purging_Strategy::HASH_MAP& -TAO_ULong_Connection_Purging_Strategy::tracking_map () -{ - return this->tracking_map_; -} diff --git a/TAO/tao/IIOP_Connection_Handler.cpp b/TAO/tao/IIOP_Connection_Handler.cpp index 1029fae9680..c05a558efd3 100644 --- a/TAO/tao/IIOP_Connection_Handler.cpp +++ b/TAO/tao/IIOP_Connection_Handler.cpp @@ -10,7 +10,7 @@ #include "tao/Server_Strategy_Factory.h" #include "tao/IIOP_Transport.h" #include "tao/IIOP_Endpoint.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "tao/Base_Transport_Property.h" #if !defined (__ACE_INLINE__) @@ -267,8 +267,8 @@ TAO_IIOP_Connection_Handler::add_transport_to_cache (void) TAO_Base_Transport_Property prop (&endpoint); // Add the handler to Cache - return this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - this->transport ()); + return this->orb_core ()->transport_cache ()->cache_transport (&prop, + this->transport ()); } int diff --git a/TAO/tao/IIOP_Connector.cpp b/TAO/tao/IIOP_Connector.cpp index ddc3d34c51a..6b61524507c 100644 --- a/TAO/tao/IIOP_Connector.cpp +++ b/TAO/tao/IIOP_Connector.cpp @@ -12,7 +12,7 @@ #include "ace/Auto_Ptr.h" #include "tao/Base_Transport_Property.h" #include "tao/Protocols_Hooks.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "ace/Strategies_T.h" #include "ace/SOCK_Connector.h" @@ -159,7 +159,7 @@ TAO_IIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, // Check the Cache first for connections // If transport found, reference count is incremented on assignment - if (this->orb_core ()->purging_strategy ()->find_in_cache (desc, + if (this->orb_core ()->transport_cache ()->find_transport (desc, base_transport) == 0) { if (TAO_debug_level > 2) @@ -176,7 +176,7 @@ TAO_IIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, ACE_TEXT ("making a new connection\n"))); // Purge connections (if necessary) - this->orb_core ()->purging_strategy ()->purge (); + this->orb_core ()->transport_cache ()->purge (); // @@ This needs to change in the next round when we implement a // policy that will not allow new connections when a connection @@ -228,8 +228,8 @@ TAO_IIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, base_transport = TAO_Transport::_duplicate (svc_handler->transport ()); // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (desc, - base_transport); + this->orb_core ()->transport_cache ()->cache_transport (desc, + base_transport); if (retval != 0 && TAO_debug_level > 0) { @@ -374,8 +374,8 @@ TAO_IIOP_Connector::preconnect (const char *preconnects) // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - handlers[slot]->transport ()); + this->orb_core ()->transport_cache ()->cache_transport (&prop, + handlers[slot]->transport ()); successes++; if (retval != 0 && TAO_debug_level > 4) diff --git a/TAO/tao/LRU_Connection_Purging_Strategy.cpp b/TAO/tao/LRU_Connection_Purging_Strategy.cpp index cc1ea84f08f..3cc795cfeec 100644 --- a/TAO/tao/LRU_Connection_Purging_Strategy.cpp +++ b/TAO/tao/LRU_Connection_Purging_Strategy.cpp @@ -1,28 +1,26 @@ // $Id$ #include "LRU_Connection_Purging_Strategy.h" +#include "Cache_Entries.h" ACE_RCSID(tao, LRU_Connection_Purging_Strategy, "$Id$") TAO_LRU_Connection_Purging_Strategy::TAO_LRU_Connection_Purging_Strategy ( - TAO_Resource_Factory* rf) - : TAO_ULong_Connection_Purging_Strategy (rf), + int cache_maximum) + : TAO_Connection_Purging_Strategy (cache_maximum), order_ (0) { } -TAO_LRU_Connection_Purging_Strategy::~TAO_LRU_Connection_Purging_Strategy () +TAO_LRU_Connection_Purging_Strategy::~TAO_LRU_Connection_Purging_Strategy (void) { } void -TAO_LRU_Connection_Purging_Strategy::update_item_i ( - TAO_DESCRIPTOR_INTERFACE *prop, - TAO_PURGING_CACHE_ITEM* /* item */) +TAO_LRU_Connection_Purging_Strategy::update_item (TAO_Cache_IntId& int_id) { - TAO_Cache_ExtId ext_id (prop); - ATTRIBUTE_TYPE int_id (this->order_++); - this->tracking_map ().rebind(ext_id, int_id); + int_id.purging_order (this->order_++); } + diff --git a/TAO/tao/LRU_Connection_Purging_Strategy.h b/TAO/tao/LRU_Connection_Purging_Strategy.h index 6851255b648..37acbbda712 100644 --- a/TAO/tao/LRU_Connection_Purging_Strategy.h +++ b/TAO/tao/LRU_Connection_Purging_Strategy.h @@ -12,28 +12,40 @@ #define TAO_LRU_PURGING_STRATEGY_H #include "ace/pre.h" -// @@ Chad: PRAMA please... +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + #include "tao/Connection_Purging_Strategy.h" -// @@ Chad:Class description... -class TAO_Export TAO_LRU_Connection_Purging_Strategy: public TAO_ULong_Connection_Purging_Strategy +// **************************************************************** + +/** + * @class TAO_LRU_Connection_Purging_Strategy + * + * @brief The Least Recently Used connection purging strategy + * + * This class maintains it's own count which is applied to the + * item passed in. This way, the least recently used transport + * has the smallest ordering number and will therefore be purged + * first. + */ + +class TAO_Export TAO_LRU_Connection_Purging_Strategy: public TAO_Connection_Purging_Strategy { public: /// The constructor - TAO_LRU_Connection_Purging_Strategy (TAO_Resource_Factory* rf); + TAO_LRU_Connection_Purging_Strategy (int cache_maximum); /// The destructor - virtual ~TAO_LRU_Connection_Purging_Strategy (); - -protected: + virtual ~TAO_LRU_Connection_Purging_Strategy (void); /// Called when accessing an item from the cache - virtual void update_item_i (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item); + virtual void update_item (TAO_Cache_IntId& int_id); private: - - ATTRIBUTE_TYPE order_; + /// The ordering information for each transport in the cache + unsigned long order_; }; #include "ace/post.h" diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp index 0a1e072cebb..6702c7d3c13 100644 --- a/TAO/tao/ORB_Core.cpp +++ b/TAO/tao/ORB_Core.cpp @@ -13,7 +13,7 @@ #include "Stub.h" #include "Reactor_Registry.h" #include "Leader_Follower.h" -#include "Connection_Purging_Strategy.h" +#include "Transport_Cache_Manager.h" #include "Connector_Registry.h" #include "Acceptor_Registry.h" @@ -166,7 +166,7 @@ TAO_ORB_Core::TAO_ORB_Core (const char *orbid) #endif /* TAO_HAS_INTERCEPTORS == 1 */ ior_interceptors_ (), parser_registry_ (), - purging_strategy_ (0), + transport_cache_ (0), bidir_adapter_ (0), bidir_giop_policy_ (0) , flushing_strategy_ (0) @@ -221,7 +221,7 @@ TAO_ORB_Core::TAO_ORB_Core (const char *orbid) TAO_ORB_Core::~TAO_ORB_Core (void) { delete this->flushing_strategy_; - delete this->purging_strategy_; + delete this->transport_cache_; ACE_OS::free (this->orbid_); @@ -1035,19 +1035,10 @@ TAO_ORB_Core::init (int &argc, char *argv[], CORBA::Environment &ACE_TRY_ENV) this->flushing_strategy_ = trf->create_flushing_strategy (); // Create the purging strategy - this->purging_strategy_ = trf->create_purging_strategy (); + ACE_NEW_RETURN(this->transport_cache_, + TAO_Transport_Cache_Manager(trf), + -1); - // We were unable to load the correct purging strategy - if (this->purging_strategy_ == 0) - { - ACE_THROW_RETURN (CORBA::INITIALIZE ( - CORBA::SystemException::_tao_minor_code ( - TAO_ORB_CORE_INIT_LOCATION_CODE, - 0), - CORBA::COMPLETED_NO), - -1); - - } // Now that we have a complete list of available protocols and their // related factory objects, set default policies and initialize the // registries! @@ -1080,7 +1071,15 @@ TAO_ORB_Core::init (int &argc, char *argv[], CORBA::Environment &ACE_TRY_ENV) // Open the Transport Cache // @@ This seems to be a nice place to configure the transport // cache for the number of allowed entries - this->purging_strategy_->open_cache (this); + if (this->transport_cache_->open (this) == -1) + { + ACE_THROW_RETURN (CORBA::INITIALIZE ( + CORBA::SystemException::_tao_minor_code ( + TAO_ORB_CORE_INIT_LOCATION_CODE, + 0), + CORBA::COMPLETED_NO), + -1); + } // Look for BiDirectional library here. If the user has svc.conf // file, load the library at this point. @@ -1221,9 +1220,9 @@ TAO_ORB_Core::fini (void) // Close the transport cache and return the handle set that needs // to be de-registered from the reactor. - if (this->purging_strategy_ != 0) + if (this->transport_cache_ != 0) { - this->purging_strategy_->close_cache (handle_set, unregistered); + this->transport_cache_->close (handle_set, unregistered); } // Shutdown all open connections that are registered with the ORB @@ -3137,7 +3136,7 @@ TAO_ORB_Core_TSS_Resources::TAO_ORB_Core_TSS_Resources (void) output_cdr_msgblock_allocator_ (0), input_cdr_dblock_allocator_ (0), input_cdr_buffer_allocator_ (0), - purging_strategy_ (0), + transport_cache_ (0), event_loop_thread_ (0), client_leader_thread_ (0), leader_follower_condition_variable_ (0), @@ -3170,8 +3169,8 @@ TAO_ORB_Core_TSS_Resources::~TAO_ORB_Core_TSS_Resources (void) this->input_cdr_buffer_allocator_->remove (); delete this->input_cdr_buffer_allocator_; - // UNIMPLEMENTED delete this->purging_strategy__; - this->purging_strategy_ = 0; + // UNIMPLEMENTED delete this->transport_cache__; + this->transport_cache_ = 0; delete this->leader_follower_condition_variable_; this->leader_follower_condition_variable_ = 0; diff --git a/TAO/tao/ORB_Core.h b/TAO/tao/ORB_Core.h index d7665a11667..8fce4325e8a 100644 --- a/TAO/tao/ORB_Core.h +++ b/TAO/tao/ORB_Core.h @@ -55,7 +55,7 @@ class TAO_Connector_Registry; class TAO_Resource_Factory; class TAO_Client_Strategy_Factory; class TAO_Server_Strategy_Factory; -class TAO_Connection_Purging_Strategy; +class TAO_Transport_Cache_Manager; class TAO_TSS_Resources; class TAO_Reactor_Registry; @@ -141,7 +141,7 @@ public: /// This is is just a place holder, in the future the transport /// cache will be separated from the connectors and it will be a /// (potentially) TSS object. - TAO_Connection_Purging_Strategy *purging_strategy_; + TAO_Transport_Cache_Manager *transport_cache_; /// Counter for how (nested) calls this thread has made to run the /// event loop. @@ -872,8 +872,8 @@ public: /// otherwise 0. int open (CORBA::Environment &ACE_TRY_ENV); - /// Return the underlying purging strategy - TAO_Connection_Purging_Strategy *purging_strategy (void); + /// Return the underlying transport cache + TAO_Transport_Cache_Manager *transport_cache (void); /// Call the bidir_giop library to parse the policy. int parse_bidir_policy (CORBA::Policy_ptr policy, @@ -1253,8 +1253,8 @@ protected: /// The IOR parser registry. TAO_Parser_Registry parser_registry_; - /// TAO's connection purging strategy - TAO_Connection_Purging_Strategy* purging_strategy_; + /// TAO's connection cache + TAO_Transport_Cache_Manager* transport_cache_; /// BiDirectional GIOP factory TAO_BiDir_Adapter *bidir_adapter_; diff --git a/TAO/tao/ORB_Core.i b/TAO/tao/ORB_Core.i index b80c9e3a01a..c564ccec09b 100644 --- a/TAO/tao/ORB_Core.i +++ b/TAO/tao/ORB_Core.i @@ -22,10 +22,10 @@ TAO_ORB_Core::_decr_refcnt (void) return 0; } -ACE_INLINE TAO_Connection_Purging_Strategy * -TAO_ORB_Core::purging_strategy (void) +ACE_INLINE TAO_Transport_Cache_Manager * +TAO_ORB_Core::transport_cache (void) { - return this->purging_strategy_; + return this->transport_cache_; } diff --git a/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.cpp b/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.cpp index b22b9825493..90155a43237 100644 --- a/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.cpp +++ b/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.cpp @@ -1,34 +1,31 @@ // $Id$ #include "FIFO_Connection_Purging_Strategy.h" +#include "tao/Cache_Entries.h" ACE_RCSID(tao, FIFO_Connection_Purging_Strategy, "$Id$") TAO_FIFO_Connection_Purging_Strategy::TAO_FIFO_Connection_Purging_Strategy ( - TAO_Resource_Factory* rf) - : TAO_ULong_Connection_Purging_Strategy (rf), + int cache_maximum) + : TAO_Connection_Purging_Strategy (cache_maximum), order_ (0) { } -TAO_FIFO_Connection_Purging_Strategy::~TAO_FIFO_Connection_Purging_Strategy () +TAO_FIFO_Connection_Purging_Strategy::~TAO_FIFO_Connection_Purging_Strategy (void) { } void -TAO_FIFO_Connection_Purging_Strategy::update_item_i ( - TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item) +TAO_FIFO_Connection_Purging_Strategy::update_item (TAO_Cache_IntId& int_id) { - ACE_UNUSED_ARG (item); - TAO_Cache_ExtId ext_id (prop); - ATTRIBUTE_TYPE int_id (this->order_); - if (this->tracking_map ().find (ext_id, int_id) != 0) + // FIFO, so only update the purging order if this + // item has not been cached yet. + if (int_id.purging_order () == 0) { - this->tracking_map ().bind(ext_id, int_id); - this->order_++; + int_id.purging_order (++(this->order_)); } } diff --git a/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.h b/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.h index fb43fc77533..48ccaa768b5 100644 --- a/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.h +++ b/TAO/tao/Strategies/FIFO_Connection_Purging_Strategy.h @@ -12,28 +12,42 @@ #define TAO_FIFO_PURGING_STRATEGY_H #include "ace/pre.h" +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + #include "strategies_export.h" #include "tao/Connection_Purging_Strategy.h" +// **************************************************************** + +/** + * @class TAO_FIFO_Connection_Purging_Strategy + * + * @brief The First In First Out connection purging strategy + * + * This class maintains it's own count which is only applied to the + * item passed if it has not yet been cached. This way, each successive + * transport has a larger ordering number than the previous. This will + * cause the first transport to be purged first. + */ + class TAO_Strategies_Export TAO_FIFO_Connection_Purging_Strategy: - public TAO_ULong_Connection_Purging_Strategy + public TAO_Connection_Purging_Strategy { public: /// The constructor - TAO_FIFO_Connection_Purging_Strategy (TAO_Resource_Factory* rf); + TAO_FIFO_Connection_Purging_Strategy (int cache_maximum); /// The destructor - virtual ~TAO_FIFO_Connection_Purging_Strategy (); - -protected: + virtual ~TAO_FIFO_Connection_Purging_Strategy (void); /// Called when accessing an item from the cache - virtual void update_item_i (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item); + virtual void update_item (TAO_Cache_IntId& int_id); private: - - ATTRIBUTE_TYPE order_; + /// The ordering information for each transport in the cache + unsigned long order_; }; #include "ace/post.h" diff --git a/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.cpp b/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.cpp index 1971900b2c1..9280d34e176 100644 --- a/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.cpp +++ b/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.cpp @@ -1,33 +1,25 @@ // $Id$ #include "LFU_Connection_Purging_Strategy.h" +#include "tao/Cache_Entries.h" ACE_RCSID(tao, LFU_Connection_Purging_Strategy, "$Id$") TAO_LFU_Connection_Purging_Strategy::TAO_LFU_Connection_Purging_Strategy ( - TAO_Resource_Factory* rf) - : TAO_ULong_Connection_Purging_Strategy (rf) + int cache_maximum) +: TAO_Connection_Purging_Strategy (cache_maximum) { } -TAO_LFU_Connection_Purging_Strategy::~TAO_LFU_Connection_Purging_Strategy () +TAO_LFU_Connection_Purging_Strategy::~TAO_LFU_Connection_Purging_Strategy (void) { } void -TAO_LFU_Connection_Purging_Strategy::update_item_i ( - TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item) +TAO_LFU_Connection_Purging_Strategy::update_item (TAO_Cache_IntId& int_id) { - ACE_UNUSED_ARG (item); - TAO_Cache_ExtId ext_id (prop); - ATTRIBUTE_TYPE int_id (0); - if (this->tracking_map ().find (ext_id, int_id) == 0) - { - int_id++; - } - this->tracking_map ().rebind(ext_id, int_id); + int_id.purging_order (int_id.purging_order () + 1); } diff --git a/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.h b/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.h index b260f1b17d4..fe830620274 100644 --- a/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.h +++ b/TAO/tao/Strategies/LFU_Connection_Purging_Strategy.h @@ -12,25 +12,37 @@ #define TAO_LFU_PURGING_STRATEGY_H #include "ace/pre.h" +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + #include "strategies_export.h" #include "tao/Connection_Purging_Strategy.h" +// **************************************************************** + +/** + * @class TAO_LFU_Connection_Purging_Strategy + * + * @brief The Least Frequently Used connection purging strategy + * + * This class increments the order information on each item passed + * in. This way, the least frequently used transport has the + * smallest ordering number and will therefore be purged first. + */ + class TAO_Strategies_Export TAO_LFU_Connection_Purging_Strategy: - public TAO_ULong_Connection_Purging_Strategy + public TAO_Connection_Purging_Strategy { public: /// The constructor - TAO_LFU_Connection_Purging_Strategy (TAO_Resource_Factory* rf); + TAO_LFU_Connection_Purging_Strategy (int cache_maximum); /// The destructor - virtual ~TAO_LFU_Connection_Purging_Strategy (); - -protected: + virtual ~TAO_LFU_Connection_Purging_Strategy (void); /// Called when accessing an item from the cache - virtual void update_item_i (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item); - + virtual void update_item (TAO_Cache_IntId& int_id); }; #include "ace/post.h" diff --git a/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.cpp b/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.cpp index 7ab7a6cb427..02f4e587974 100644 --- a/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.cpp +++ b/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.cpp @@ -5,46 +5,27 @@ ACE_RCSID(tao, NULL_Connection_Purging_Strategy, "$Id$") TAO_NULL_Connection_Purging_Strategy::TAO_NULL_Connection_Purging_Strategy ( - TAO_Resource_Factory* rf) - : TAO_Connection_Purging_Strategy (rf) + int cache_maximum) + : TAO_Connection_Purging_Strategy (cache_maximum) { } -TAO_NULL_Connection_Purging_Strategy::~TAO_NULL_Connection_Purging_Strategy () +TAO_NULL_Connection_Purging_Strategy::~TAO_NULL_Connection_Purging_Strategy (void) { } -int -TAO_NULL_Connection_Purging_Strategy::fill_set_i (DESCRIPTOR_SET& sorted_set) -{ - ACE_UNUSED_ARG (sorted_set); - return 0; -} - - void -TAO_NULL_Connection_Purging_Strategy::update_item_i ( - TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item) +TAO_NULL_Connection_Purging_Strategy::update_item (TAO_Cache_IntId& int_id) { - ACE_UNUSED_ARG (prop); - ACE_UNUSED_ARG (item); + ACE_UNUSED_ARG (int_id); } -void -TAO_NULL_Connection_Purging_Strategy::remove_item_i ( - TAO_DESCRIPTOR_INTERFACE* prop) -{ - ACE_UNUSED_ARG (prop); -} - - -void -TAO_NULL_Connection_Purging_Strategy::remove_all_i () +int +TAO_NULL_Connection_Purging_Strategy::cache_maximum (void) const { + return -1; } - diff --git a/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.h b/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.h index 67a00e4d0e4..fe8260ceb67 100644 --- a/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.h +++ b/TAO/tao/Strategies/NULL_Connection_Purging_Strategy.h @@ -12,33 +12,38 @@ #define TAO_NULL_PURGING_STRATEGY_H #include "ace/pre.h" +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + #include "strategies_export.h" #include "tao/Connection_Purging_Strategy.h" +// **************************************************************** + +/** + * @class TAO_NULL_Connection_Purging_Strategy + * + * @brief The null connection purging strategy + * + * This class does not do anything. + */ + class TAO_Strategies_Export TAO_NULL_Connection_Purging_Strategy: public TAO_Connection_Purging_Strategy { public: /// The constructor - TAO_NULL_Connection_Purging_Strategy (TAO_Resource_Factory* rf); + TAO_NULL_Connection_Purging_Strategy (int cache_maximum); /// The destructor - virtual ~TAO_NULL_Connection_Purging_Strategy (); - -protected: - /// Does nothing. - virtual int fill_set_i (DESCRIPTOR_SET& sorted_set); - - /// Does nothing. - virtual void update_item_i (TAO_DESCRIPTOR_INTERFACE* prop, - TAO_PURGING_CACHE_ITEM* item); - - /// Does nothing. - virtual void remove_item_i (TAO_DESCRIPTOR_INTERFACE* prop); + virtual ~TAO_NULL_Connection_Purging_Strategy (void); /// Does nothing. - virtual void remove_all_i (); + virtual void update_item (TAO_Cache_IntId& int_id); + /// Returns -1 to signify no maximum + virtual int cache_maximum (void) const; }; #include "ace/post.h" diff --git a/TAO/tao/Strategies/SHMIOP_Connection_Handler.cpp b/TAO/tao/Strategies/SHMIOP_Connection_Handler.cpp index 3df9b6e6ee3..fd7fb9db6e6 100644 --- a/TAO/tao/Strategies/SHMIOP_Connection_Handler.cpp +++ b/TAO/tao/Strategies/SHMIOP_Connection_Handler.cpp @@ -14,7 +14,7 @@ #include "tao/GIOP_Message_Lite.h" #include "tao/Server_Strategy_Factory.h" #include "tao/Base_Transport_Property.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #include "SHMIOP_Endpoint.h" #if !defined (__ACE_INLINE__) @@ -243,8 +243,8 @@ TAO_SHMIOP_Connection_Handler::add_transport_to_cache (void) TAO_Base_Transport_Property prop (&endpoint); // Add the handler to Cache - return this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - this->transport ()); + return this->orb_core ()->transport_cache ()->cache_transport (&prop, + this->transport ()); } diff --git a/TAO/tao/Strategies/SHMIOP_Connector.cpp b/TAO/tao/Strategies/SHMIOP_Connector.cpp index b8277c19a9d..238d1fe4ad1 100644 --- a/TAO/tao/Strategies/SHMIOP_Connector.cpp +++ b/TAO/tao/Strategies/SHMIOP_Connector.cpp @@ -13,7 +13,7 @@ #include "tao/Client_Strategy_Factory.h" #include "tao/Environment.h" #include "ace/Auto_Ptr.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" ACE_RCSID (Strategies, SHMIOP_Connector, @@ -165,7 +165,7 @@ TAO_SHMIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, // Check the Cache first for connections // If transport found, reference count is incremented on assignment - if (this->orb_core ()->purging_strategy ()->find_in_cache (desc, + if (this->orb_core ()->transport_cache ()->find_transport (desc, base_transport) == 0) { if (TAO_debug_level > 5) @@ -182,7 +182,7 @@ TAO_SHMIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, ACE_TEXT ("making a new connection \n"))); // Purge connections (if necessary) - this->orb_core ()->purging_strategy ()->purge (); + this->orb_core ()->transport_cache ()->purge (); // @@ This needs to change in the next round when we implement a // policy that will not allow new connections when a connection @@ -236,8 +236,8 @@ TAO_SHMIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, base_transport = TAO_Transport::_duplicate (svc_handler->transport ()); // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (desc, - svc_handler->transport ()); + this->orb_core ()->transport_cache ()->cache_transport (desc, + svc_handler->transport ()); if (retval != 0 && TAO_debug_level > 0) { @@ -369,8 +369,8 @@ TAO_SHMIOP_Connector::preconnect (const char *preconnects) // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - handlers[slot]->transport ()); + this->orb_core ()->transport_cache ()->cache_transport (&prop, + handlers[slot]->transport ()); successes++; if (retval != 0 && TAO_debug_level > 4) diff --git a/TAO/tao/Strategies/UIOP_Connection_Handler.cpp b/TAO/tao/Strategies/UIOP_Connection_Handler.cpp index e6207eecb2a..4d412f7c870 100644 --- a/TAO/tao/Strategies/UIOP_Connection_Handler.cpp +++ b/TAO/tao/Strategies/UIOP_Connection_Handler.cpp @@ -15,7 +15,7 @@ #include "tao/Messaging_Policy_i.h" #include "tao/Base_Transport_Property.h" #include "tao/GIOP_Message_Lite.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #if !defined (__ACE_INLINE__) # include "UIOP_Connection_Handler.inl" @@ -218,8 +218,8 @@ TAO_UIOP_Connection_Handler::add_transport_to_cache (void) TAO_Base_Transport_Property prop (&endpoint); // Add the handler to Cache - return this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - this->transport ()); + return this->orb_core ()->transport_cache ()->cache_transport (&prop, + this->transport ()); } diff --git a/TAO/tao/Strategies/UIOP_Connector.cpp b/TAO/tao/Strategies/UIOP_Connector.cpp index c1cd7f5940a..9f67e4ddb2c 100644 --- a/TAO/tao/Strategies/UIOP_Connector.cpp +++ b/TAO/tao/Strategies/UIOP_Connector.cpp @@ -13,7 +13,7 @@ #include "ace/Auto_Ptr.h" #include "tao/Protocols_Hooks.h" #include "tao/Base_Transport_Property.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" ACE_RCSID(Strategies, UIOP_Connector, "$Id$") @@ -154,7 +154,7 @@ TAO_UIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, // Check the Cache first for connections // If transport found, reference count is incremented on assignment - if (this->orb_core ()->purging_strategy ()->find_in_cache (desc, + if (this->orb_core ()->transport_cache ()->find_transport (desc, base_transport) == 0) { if (TAO_debug_level > 5) @@ -171,7 +171,7 @@ TAO_UIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, ACE_TEXT ("making a new connection \n"))); // Purge connections (if necessary) - this->orb_core ()->purging_strategy ()->purge (); + this->orb_core ()->transport_cache ()->purge (); // @@ This needs to change in the next round when we implement a // policy that will not allow new connections when a connection @@ -221,8 +221,8 @@ TAO_UIOP_Connector::connect (TAO_Transport_Descriptor_Interface *desc, base_transport = TAO_Transport::_duplicate (svc_handler->transport ()); // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (desc, - base_transport); + this->orb_core ()->transport_cache ()->cache_transport (desc, + base_transport); if (retval != 0 && TAO_debug_level > 0) { @@ -342,8 +342,8 @@ TAO_UIOP_Connector::preconnect (const char *preconnects) // Add the handler to Cache int retval = - this->orb_core ()->purging_strategy ()->add_to_cache (&prop, - handlers[slot]->transport ()); + this->orb_core ()->transport_cache ()->cache_transport (&prop, + handlers[slot]->transport ()); ++successes; if (retval != 0 && TAO_debug_level > 4) diff --git a/TAO/tao/Strategies/advanced_resource.cpp b/TAO/tao/Strategies/advanced_resource.cpp index f0fc6945b91..f3ff108f948 100644 --- a/TAO/tao/Strategies/advanced_resource.cpp +++ b/TAO/tao/Strategies/advanced_resource.cpp @@ -608,22 +608,26 @@ TAO_Advanced_Resource_Factory::create_purging_strategy (void) { case TAO_Resource_Factory::LFU: ACE_NEW_RETURN (strategy, - TAO_LFU_Connection_Purging_Strategy (this), + TAO_LFU_Connection_Purging_Strategy ( + this->cache_maximum ()), 0); break; case TAO_Resource_Factory::FIFO: ACE_NEW_RETURN (strategy, - TAO_FIFO_Connection_Purging_Strategy (this), + TAO_FIFO_Connection_Purging_Strategy ( + this->cache_maximum ()), 0); break; case TAO_Resource_Factory::NOOP: ACE_NEW_RETURN (strategy, - TAO_NULL_Connection_Purging_Strategy (this), + TAO_NULL_Connection_Purging_Strategy ( + this->cache_maximum ()), 0); break; case TAO_Resource_Factory::LRU: ACE_NEW_RETURN (strategy, - TAO_LRU_Connection_Purging_Strategy (this), + TAO_LRU_Connection_Purging_Strategy ( + this->cache_maximum ()), 0); break; default: diff --git a/TAO/tao/Transport.cpp b/TAO/tao/Transport.cpp index 5a4799e7a5f..a7f0083aaf8 100644 --- a/TAO/tao/Transport.cpp +++ b/TAO/tao/Transport.cpp @@ -15,7 +15,7 @@ #include "Synch_Queued_Message.h" #include "Asynch_Queued_Message.h" #include "Flushing_Strategy.h" -#include "Connection_Purging_Strategy.h" +#include "Transport_Cache_Manager.h" #include "debug.h" #include "ace/Message_Block.h" @@ -567,7 +567,7 @@ TAO_Transport::connection_handler_closing (void) // Avoid making the call if we can if (this->cache_map_entry_ != 0) { - this->orb_core_->purging_strategy ()->purge_from_cache ( + this->orb_core_->transport_cache ()->purge_entry ( this->cache_map_entry_); } } @@ -614,26 +614,26 @@ int TAO_Transport::recache_transport (TAO_Transport_Descriptor_Interface *desc) { // First purge our entry - this->orb_core_->purging_strategy ()->purge_from_cache ( + this->orb_core_->transport_cache ()->purge_entry ( this->cache_map_entry_); // Then add ourselves to the cache - return this->orb_core_->purging_strategy ()->add_to_cache (desc, - this); + return this->orb_core_->transport_cache ()->cache_transport (desc, + this); } void TAO_Transport::mark_invalid (void) { // @@ Do we need this method at all?? - this->orb_core_->purging_strategy ()->mark_invalid ( + this->orb_core_->transport_cache ()->mark_invalid ( this->cache_map_entry_); } int TAO_Transport::make_idle (void) { - return this->orb_core_->purging_strategy ()->make_idle ( + return this->orb_core_->transport_cache ()->make_idle ( this->cache_map_entry_); } @@ -682,7 +682,7 @@ TAO_Transport::close_connection (void) ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - Transport::close_connection () - " "Is this redundant?\n")); - this->orb_core_->purging_strategy ()->purge_from_cache ( + this->orb_core_->transport_cache ()->purge_entry ( this->cache_map_entry_); } diff --git a/TAO/tao/Transport_Cache_Manager.cpp b/TAO/tao/Transport_Cache_Manager.cpp index 86fd076016e..2efddd613ad 100644 --- a/TAO/tao/Transport_Cache_Manager.cpp +++ b/TAO/tao/Transport_Cache_Manager.cpp @@ -4,6 +4,8 @@ #include "tao/Transport.h" #include "tao/debug.h" #include "tao/ORB_Core.h" +#include "tao/Resource_Factory.h" +#include "tao/Connection_Purging_Strategy.h" #include "ace/Handle_Set.h" @@ -17,8 +19,11 @@ ACE_RCSID (TAO, "$Id$") -TAO_Transport_Cache_Manager::TAO_Transport_Cache_Manager (void) - : cache_map_ (), +TAO_Transport_Cache_Manager::TAO_Transport_Cache_Manager ( + TAO_Resource_Factory* rf) + : percent_ (rf->purge_percentage ()), + purging_strategy_ (rf->create_purging_strategy ()), + cache_map_ (), cache_lock_ (0) { } @@ -28,12 +33,20 @@ TAO_Transport_Cache_Manager::~TAO_Transport_Cache_Manager (void) { // Delete the lock that we have delete this->cache_lock_; + + // Delete the purging strategy + delete this->purging_strategy_; } int TAO_Transport_Cache_Manager::open (TAO_ORB_Core *orb_core, size_t size) { + if (this->purging_strategy_ == 0) + { + return -1; + } + // Create the cache_lock this->cache_lock_ = orb_core->resource_factory ()->create_cached_connection_lock (); @@ -58,6 +71,10 @@ TAO_Transport_Cache_Manager::bind_i (TAO_Cache_ExtId &ext_id, // 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); + // When it comes for bind we know the transport is going to be busy // and is marked for a partcular thread. So, mark it busy int_id.recycle_state (ACE_RECYCLABLE_BUSY); @@ -126,6 +143,11 @@ TAO_Transport_Cache_Manager::find_transport ( int_id); if (retval == 0) { + // Update the purging strategy information by unbinding + // and then binding + this->unbind (ext_id); + this->bind (ext_id, int_id); + transport = int_id.relinquish_transport (); } @@ -203,13 +225,6 @@ TAO_Transport_Cache_Manager::rebind_i (const TAO_Cache_ExtId &key, } int -TAO_Transport_Cache_Manager::trybind_i (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value) -{ - return this->cache_map_.trybind (key, value); -} - -int TAO_Transport_Cache_Manager::unbind_i (const TAO_Cache_ExtId &key) { return this->cache_map_.unbind (key); @@ -368,6 +383,151 @@ TAO_Transport_Cache_Manager::is_entry_idle (HASH_MAP_ENTRY *&entry) } +#if !defined (ACE_LACKS_QSORT) +int +TAO_Transport_Cache_Manager::cpscmp(const void* a, const void* b) +{ + const HASH_MAP_ENTRY** left = (const HASH_MAP_ENTRY**)a; + const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b; + + if ((*left)->int_id_.purging_order () > (*right)->int_id_.purging_order ()) + return 1; + + if ((*left)->int_id_.purging_order () < (*right)->int_id_.purging_order ()) + return -1; + + return 0; +} +#endif /* ACE_LACKS_QSORT */ + + +void +TAO_Transport_Cache_Manager::sort_set (HASH_MAP_ENTRY**& entries, + int current_size) +{ +#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_.purging_order () < + entries[i - 1]->int_id_.purging_order ()) + { + HASH_MAP_ENTRY* entry = entries[i]; + for(int j = i; j > 0 && + entries[j - 1]->int_id_.purging_order () > + entry->int_id_.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 */ +} + + +int +TAO_Transport_Cache_Manager::fill_set_i (DESCRIPTOR_SET& sorted_set) +{ + int amount = -1; + int cache_maximum = this->purging_strategy_->cache_maximum (); + + // Do we need to worry about cache purging? + if (cache_maximum >= 0) + { + int current_size = this->cache_map_.current_size (); + amount = current_size - cache_maximum; + + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_Transport_Cache_Manager") + ACE_TEXT ("::fill_set_i - %d %d\n"), + current_size, cache_maximum)); + } + + if (amount >= 0) + { + // I could not use ACE_Array_Base<HASH_MAP_ENTRY*> because + // the compiler kept complaining about HASH_MAP_ENTRY not having + // a default construtor. + HASH_MAP_ENTRY** entries; + ACE_NEW_RETURN(entries, HASH_MAP_ENTRY*[current_size], 0); + sorted_set.size (current_size); + + int i; + HASH_MAP_ITER iter = this->cache_map_.begin (); + for (i = 0; i < current_size; i++) + { + entries[i] = &(*iter); + iter++; + } + + this->sort_set (entries, current_size); + + for(i = 0; i < current_size; i++) + { + // The owner of the sorted_set array accepts responsibility + // for deleting the memory allocated here. + sorted_set[i] = entries[i]->ext_id_.property ()->duplicate (); + } + + delete [] entries; + } + } + + return (amount >= 0); +} + + +void +TAO_Transport_Cache_Manager::close_entries(DESCRIPTOR_SET& sorted_set) +{ + const int sorted_size = sorted_set.size (); + const int amount = (sorted_size * this->percent_) / 100; + + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("Purging %d of %d cache entries\n"), + amount, + sorted_size)); + } + + int count = 0; + for(int i = 0; i < sorted_size; i++) + { + TAO_Transport_Descriptor_Interface* prop = sorted_set[i]; + if (count < amount) + { + // Compose the ExternId + TAO_Cache_ExtId ext_id (prop); + TAO_Cache_IntId int_id; + + if (this->find (ext_id, int_id) == 0) + { + TAO_Transport* transport = int_id.relinquish_transport (); + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("Idle transport found in ") + ACE_TEXT ("cache: 0x%x\n"), + transport)); + } + + // Eventually calls purge_entry() on us. + transport->close_connection (); + count++; + } + } + delete prop; + } +} + #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) @@ -385,6 +545,7 @@ template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, TAO_Cache_IntId template class ACE_Unbounded_Set<ACE_Event_Handler*>; template class ACE_Unbounded_Set_Iterator<ACE_Event_Handler*>; template class ACE_Node<ACE_Event_Handler*>; +template class ACE_Array_Base<TAO_Transport_Descriptor_Interface*>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) @@ -402,5 +563,6 @@ template class ACE_Node<ACE_Event_Handler*>; #pragma instantiate ACE_Unbounded_Set<ACE_Event_Handler*> #pragma instantiate ACE_Unbounded_Set_Iterator<ACE_Event_Handler*> #pragma instantiate ACE_Node<ACE_Event_Handler*> +#pragma instantiate ACE_Array_Base<TAO_Transport_Descriptor_Interface*> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/Transport_Cache_Manager.h b/TAO/tao/Transport_Cache_Manager.h index 03e8bac1840..2a4ac389686 100644 --- a/TAO/tao/Transport_Cache_Manager.h +++ b/TAO/tao/Transport_Cache_Manager.h @@ -16,6 +16,7 @@ #include "ace/pre.h" #include "ace/Hash_Map_Manager_T.h" +#include "ace/Array_Base.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) #define ACE_LACKS_PRAGMA_ONCE @@ -33,6 +34,8 @@ class TAO_ORB_Core; class ACE_Handle_Set; +class TAO_Resource_Factory; +class TAO_Connection_Purging_Strategy; typedef ACE_Unbounded_Set<ACE_Event_Handler*> TAO_EventHandlerSet; typedef ACE_Unbounded_Set_Iterator<ACE_Event_Handler*> @@ -78,7 +81,7 @@ public: // == Public methods /// Constructor - TAO_Transport_Cache_Manager (void); + TAO_Transport_Cache_Manager (TAO_Resource_Factory* rf); /// Destructor virtual ~TAO_Transport_Cache_Manager (void); @@ -98,37 +101,6 @@ public: int open (TAO_ORB_Core *orb_core, size_t size = ACE_DEFAULT_MAP_SIZE); - /// Associate <ext_id> with <int_id>. Grabs the lock and calls the - /// implementation function bind_i. - int bind (TAO_Cache_ExtId &ext_id, - TAO_Cache_IntId &int_id); - - /// Lookup entry<key,value> in the cache. Grabs the lock and calls the - /// implementation function find_i. - int find (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value); - - /// Reassociate the <key> with <value>. Grabs the lock and calls the - /// implementation function find_i. - int rebind (const TAO_Cache_ExtId &key, - const TAO_Cache_IntId &value); - - /** - * Associate <key> with <value> if and only if <key> is not in the - * cache. Grabs the lock and calls the implementation function - * find_i. - */ - int trybind (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value); - - /// Remove <key> from the cache. - int unbind (const TAO_Cache_ExtId &key); - - /// Remove <key> from the cache, and return the <value> associated with - /// <key>. - int unbind (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value); - /// Remove entries from the cache depending upon the strategy. int purge (void); @@ -154,6 +126,29 @@ public: private: + /// Associate <ext_id> with <int_id>. Grabs the lock and calls the + /// implementation function bind_i. + int bind (TAO_Cache_ExtId &ext_id, + TAO_Cache_IntId &int_id); + + /// Lookup entry<key,value> in the cache. Grabs the lock and calls the + /// implementation function find_i. + int find (const TAO_Cache_ExtId &key, + TAO_Cache_IntId &value); + + /// Reassociate the <key> with <value>. Grabs the lock and calls the + /// implementation function find_i. + int rebind (const TAO_Cache_ExtId &key, + const TAO_Cache_IntId &value); + + /// Remove <key> from the cache. + int unbind (const TAO_Cache_ExtId &key); + + /// Remove <key> from the cache, and return the <value> associated with + /// <key>. + int unbind (const TAO_Cache_ExtId &key, + TAO_Cache_IntId &value); + /** * Non-Locking version and actual implementation of bind () * call. Calls bind on the Hash_Map_Manager that it holds. If the @@ -178,10 +173,6 @@ private: int rebind_i (const TAO_Cache_ExtId &key, const TAO_Cache_IntId &value); - /// Non-locking version and actual implementation of trybind () call - int trybind_i (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value); - /// Non-locking version and actual implementation of unbind () call int unbind_i (const TAO_Cache_ExtId &key); @@ -223,8 +214,31 @@ private: */ int is_entry_idle (HASH_MAP_ENTRY *&entry); +#if !defined(ACE_LACKS_QSORT) + /// Used by qsort + static int cpscmp(const void* a, const void* b); +#endif + + typedef ACE_Array_Base<TAO_Transport_Descriptor_Interface*> + DESCRIPTOR_SET; + + /// Sort the list of entries + void sort_set (HASH_MAP_ENTRY**& entries, int size); + + /// Fill sorted_set in with the TAO_Transport_Descriptor_Interface's in + /// a sorted order. + virtual int fill_set_i (DESCRIPTOR_SET& sorted_set); + + /// Look through the sorted set and close the connection on + /// the required number of items in the set. + void close_entries (DESCRIPTOR_SET& sorted_set); private: + /// The percentage of the cache to purge at one time + int percent_; + + /// The underlying connection purging strategy + TAO_Connection_Purging_Strategy *purging_strategy_; /// The hash map that has the connections HASH_MAP cache_map_; diff --git a/TAO/tao/Transport_Cache_Manager.inl b/TAO/tao/Transport_Cache_Manager.inl index 49afd1d472d..8cdfd10519a 100644 --- a/TAO/tao/Transport_Cache_Manager.inl +++ b/TAO/tao/Transport_Cache_Manager.inl @@ -30,10 +30,18 @@ TAO_Transport_Cache_Manager::find (const TAO_Cache_ExtId &key, ACE_INLINE int -TAO_Transport_Cache_Manager:: - cache_transport (TAO_Transport_Descriptor_Interface *prop, +TAO_Transport_Cache_Manager::cache_transport ( + TAO_Transport_Descriptor_Interface *prop, TAO_Transport *transport) { + if (TAO_debug_level > 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ") + ACE_TEXT ("TAO_Transport_Cache_Manager") + ACE_TEXT ("::cache_transport (0x%x, 0x%x)\n"), + prop, transport)); + } + // Compose the ExternId & Intid TAO_Cache_ExtId ext_id (prop); TAO_Cache_IntId int_id (transport); @@ -57,18 +65,6 @@ TAO_Transport_Cache_Manager::rebind (const TAO_Cache_ExtId &key, } ACE_INLINE int -TAO_Transport_Cache_Manager::trybind (const TAO_Cache_ExtId &key, - TAO_Cache_IntId &value) -{ - ACE_MT (ACE_GUARD_RETURN (ACE_Lock, - guard, - *this->cache_lock_, - -1)); - - return this->trybind_i (key, value); -} - -ACE_INLINE int TAO_Transport_Cache_Manager::unbind (const TAO_Cache_ExtId &key) { ACE_MT (ACE_GUARD_RETURN (ACE_Lock, @@ -96,6 +92,24 @@ TAO_Transport_Cache_Manager::unbind (const TAO_Cache_ExtId &key, ACE_INLINE int TAO_Transport_Cache_Manager::purge (void) { + int need_to_purge = 0; + DESCRIPTOR_SET sorted_set; + + // We must use a small scope, since we can't call close_entries() + // if we are holding the lock. + { + ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->cache_lock_, 0)); + need_to_purge = this->fill_set_i (sorted_set); + } + + // Only call close_entries () if need_to_purge. It takes control of + // sorted_set and cleans up any allocated memory. If !need_to_purge, + // then there is nothing to de-allocate. + if (need_to_purge) + { + this->close_entries (sorted_set); + } + return 0; } diff --git a/TAO/tao/default_resource.cpp b/TAO/tao/default_resource.cpp index b843fbf2287..d07bf0c5258 100644 --- a/TAO/tao/default_resource.cpp +++ b/TAO/tao/default_resource.cpp @@ -809,7 +809,8 @@ TAO_Default_Resource_Factory::create_purging_strategy (void) if (this->connection_caching_type_ == TAO_Resource_Factory::LRU) { ACE_NEW_RETURN (strategy, - TAO_LRU_Connection_Purging_Strategy (this), + TAO_LRU_Connection_Purging_Strategy ( + this->cache_maximum ()), 0); } else diff --git a/TAO/tests/BiDirectional/test_i.cpp b/TAO/tests/BiDirectional/test_i.cpp index b92fdb1cbc4..a7367c5ab4a 100644 --- a/TAO/tests/BiDirectional/test_i.cpp +++ b/TAO/tests/BiDirectional/test_i.cpp @@ -4,7 +4,7 @@ #include "tao/ORB_Core.h" #include "tao/debug.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #if !defined(__ACE_INLINE__) #include "test_i.i" @@ -63,7 +63,7 @@ Simple_Server_i::call_client (CORBA::Environment &ACE_TRY_ENV) this->callback_->callback_method (ACE_TRY_ENV); ACE_CHECK_RETURN (0); - ACE_ASSERT (this->orb_->orb_core ()->purging_strategy ()->total_size () > 1); + ACE_ASSERT (this->orb_->orb_core ()->transport_cache ()->total_size () > 1); } this->callback_->shutdown (ACE_TRY_ENV); diff --git a/TAO/tests/BiDirectional_NestedUpcall/test_i.cpp b/TAO/tests/BiDirectional_NestedUpcall/test_i.cpp index f732c78b0df..a9e09aac13f 100644 --- a/TAO/tests/BiDirectional_NestedUpcall/test_i.cpp +++ b/TAO/tests/BiDirectional_NestedUpcall/test_i.cpp @@ -3,7 +3,7 @@ #include "test_i.h" #include "tao/ORB_Core.h" #include "tao/debug.h" -#include "tao/Connection_Purging_Strategy.h" +#include "tao/Transport_Cache_Manager.h" #if !defined(__ACE_INLINE__) #include "test_i.i" @@ -48,7 +48,7 @@ Simple_Server_i::test_method (CORBA::Boolean do_callback, this->callback_->callback_method (ACE_TRY_ENV); ACE_CHECK_RETURN (0); - ACE_ASSERT(this->orb_->orb_core ()->purging_strategy ()->total_size () > 1); + ACE_ASSERT(this->orb_->orb_core ()->transport_cache ()->total_size () > 1); } } diff --git a/TAO/tests/Connection_Purging/client.fifo.conf b/TAO/tests/Connection_Purging/client.fifo.conf index 1eddc24886c..3a419861617 100644 --- a/TAO/tests/Connection_Purging/client.fifo.conf +++ b/TAO/tests/Connection_Purging/client.fifo.conf @@ -1,3 +1,3 @@ # $Id$ # -static Advanced_Resource_Factory "-ORBConnectionCachingStrategy fifo -ORBConnectionCacheMax 10 -ORBPurgePercentage 30" +static Advanced_Resource_Factory "-ORBConnectionCachingStrategy fifo -ORBConnectionCacheMax 10 -ORBConnectionCachePurgePercentage 30" diff --git a/TAO/tests/Connection_Purging/client.lfu.conf b/TAO/tests/Connection_Purging/client.lfu.conf index 84f0390fb1f..b6f9f9b6825 100644 --- a/TAO/tests/Connection_Purging/client.lfu.conf +++ b/TAO/tests/Connection_Purging/client.lfu.conf @@ -1,3 +1,3 @@ # $Id$ # -static Advanced_Resource_Factory "-ORBConnectionCachingStrategy lfu -ORBConnectionCacheMax 10 -ORBPurgePercentage 30" +static Advanced_Resource_Factory "-ORBConnectionCachingStrategy lfu -ORBConnectionCacheMax 10 -ORBConnectionCachePurgePercentage 30" diff --git a/TAO/tests/Connection_Purging/client.lru.conf b/TAO/tests/Connection_Purging/client.lru.conf index 52d1e3ee6c7..05d0a821607 100644 --- a/TAO/tests/Connection_Purging/client.lru.conf +++ b/TAO/tests/Connection_Purging/client.lru.conf @@ -1,3 +1,3 @@ # $Id$ # -static Advanced_Resource_Factory "-ORBConnectionCachingStrategy lru -ORBConnectionCacheMax 10 -ORBPurgePercentage 30" +static Advanced_Resource_Factory "-ORBConnectionCachingStrategy lru -ORBConnectionCacheMax 10 -ORBConnectionCachePurgePercentage 30" |