From 5cfb4bb5ed96220ac41075f64c56288f587ea894 Mon Sep 17 00:00:00 2001 From: irfan Date: Mon, 12 Jul 1999 19:20:35 +0000 Subject: ChangeLogTag:Mon Jul 12 13:54:34 1999 Kirthika Parameswaran --- ace/Cache_Map_Manager_T.cpp | 99 ++++++----- ace/Cache_Map_Manager_T.h | 43 ++++- ace/Cache_Map_Manager_T.i | 216 ++++++++++++----------- ace/Cached_Connect_Strategy_T.cpp | 52 ++---- ace/Cached_Connect_Strategy_T.h | 18 +- ace/Caching_Strategies_T.cpp | 350 ++------------------------------------ ace/Caching_Strategies_T.h | 240 ++++++-------------------- ace/Caching_Strategies_T.i | 317 +++++++++++++++++----------------- ace/Caching_Utility_T.cpp | 162 ++++++++++++++++-- ace/Caching_Utility_T.h | 159 ++++++++++++----- ace/Cleanup_Strategies_T.cpp | 37 ++-- ace/Cleanup_Strategies_T.h | 49 +----- ace/Hash_Cache_Map_Manager_T.cpp | 2 +- ace/Hash_Cache_Map_Manager_T.h | 31 ++-- 14 files changed, 752 insertions(+), 1023 deletions(-) (limited to 'ace') diff --git a/ace/Cache_Map_Manager_T.cpp b/ace/Cache_Map_Manager_T.cpp index 376f981e5e4..6d7d0770773 100644 --- a/ace/Cache_Map_Manager_T.cpp +++ b/ace/Cache_Map_Manager_T.cpp @@ -21,17 +21,26 @@ ACE_RCSID(ace, Cache_Map_Manager_T, "$Id$") ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Manager) +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Iterator) ACE_ALLOC_HOOK_DEFINE(ACE_Cache_Map_Reverse_Iterator) -#define T_1 class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES -#define T_2 KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES +#define ACE_T1 class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES + +#else + +#define ACE_T1 class KEY, class VALUE, class MAP, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, MAP, CACHING_STRATEGY, ATTRIBUTES - template -ACE_Cache_Map_Manager::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s, - size_t size, - ACE_Allocator *alloc) +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +template +ACE_Cache_Map_Manager::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s, + size_t size, + ACE_Allocator *alloc) : caching_strategy_ (caching_s) { if (this->open (size, alloc) == -1) @@ -41,29 +50,29 @@ ACE_Cache_Map_Manager::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s, } -template -ACE_Cache_Map_Manager::~ACE_Cache_Map_Manager (void) +template +ACE_Cache_Map_Manager::~ACE_Cache_Map_Manager (void) { this->close (); } -template int -ACE_Cache_Map_Manager::open (size_t length, - ACE_Allocator *alloc) +template int +ACE_Cache_Map_Manager::open (size_t length, + ACE_Allocator *alloc) { return this->map_.open (length, alloc); } -template int -ACE_Cache_Map_Manager::close (void) +template int +ACE_Cache_Map_Manager::close (void) { return this->map_.close (); } -template int -ACE_Cache_Map_Manager::bind (const KEY &key, - const VALUE &value) +template int +ACE_Cache_Map_Manager::bind (const KEY &key, + const VALUE &value) { // Insert an entry which has the and the which // is the combination of the and the attributes of the @@ -97,9 +106,9 @@ ACE_Cache_Map_Manager::bind (const KEY &key, } -template int -ACE_Cache_Map_Manager::rebind (const KEY &key, - const VALUE &value) +template int +ACE_Cache_Map_Manager::rebind (const KEY &key, + const VALUE &value) { CACHE_VALUE cache_value (value, this->caching_strategy_.attributes ()); @@ -134,10 +143,10 @@ ACE_Cache_Map_Manager::rebind (const KEY &key, } -template int -ACE_Cache_Map_Manager::rebind (const KEY &key, - const VALUE &value, - VALUE &old_value) +template int +ACE_Cache_Map_Manager::rebind (const KEY &key, + const VALUE &value, + VALUE &old_value) { CACHE_VALUE cache_value (value, this->caching_strategy_.attributes ()); @@ -181,11 +190,11 @@ ACE_Cache_Map_Manager::rebind (const KEY &key, return rebind_result; } -template int -ACE_Cache_Map_Manager::rebind (const KEY &key, - const VALUE &value, - KEY &old_key, - VALUE &old_value) +template int +ACE_Cache_Map_Manager::rebind (const KEY &key, + const VALUE &value, + KEY &old_key, + VALUE &old_value) { CACHE_VALUE cache_value (value, this->caching_strategy_.attributes ()); @@ -230,9 +239,9 @@ ACE_Cache_Map_Manager::rebind (const KEY &key, return rebind_result; } -template int -ACE_Cache_Map_Manager::trybind (const KEY &key, - VALUE &value) +template int +ACE_Cache_Map_Manager::trybind (const KEY &key, + VALUE &value) { CACHE_VALUE cache_value (value, this->caching_strategy_.attributes ()); @@ -272,9 +281,9 @@ ACE_Cache_Map_Manager::trybind (const KEY &key, return trybind_result; } -template int -ACE_Cache_Map_Manager::find (const KEY &key, - VALUE &value) +template int +ACE_Cache_Map_Manager::find (const KEY &key, + VALUE &value) { // Lookup the key and populate the . CACHE_VALUE cache_value; @@ -311,8 +320,8 @@ ACE_Cache_Map_Manager::find (const KEY &key, return find_result; } -template int -ACE_Cache_Map_Manager::find (const KEY &key) +template int +ACE_Cache_Map_Manager::find (const KEY &key) { // Lookup the key and populate the . CACHE_VALUE cache_value; @@ -349,8 +358,8 @@ ACE_Cache_Map_Manager::find (const KEY &key) } -template int -ACE_Cache_Map_Manager::unbind (const KEY &key) +template int +ACE_Cache_Map_Manager::unbind (const KEY &key) { // Remove the entry from the cache. CACHE_VALUE cache_value; @@ -372,9 +381,9 @@ ACE_Cache_Map_Manager::unbind (const KEY &key) return unbind_result; } -template int -ACE_Cache_Map_Manager::unbind (const KEY &key, - VALUE &value) +template int +ACE_Cache_Map_Manager::unbind (const KEY &key, + VALUE &value) { // Remove the entry from the cache. CACHE_VALUE cache_value; @@ -399,15 +408,15 @@ ACE_Cache_Map_Manager::unbind (const KEY &key, } -template void -ACE_Cache_Map_Manager::dump (void) const +template void +ACE_Cache_Map_Manager::dump (void) const { this->map_.dump (); this->caching_strategy_.dump (); } -#undef T_1 -#undef T_2 +#undef ACE_T1 +#undef ACE_T2 #endif /* ACE_CACHE_MAP_MANAGER_T_C */ diff --git a/ace/Cache_Map_Manager_T.h b/ace/Cache_Map_Manager_T.h index 20dfb3b9e1d..82033b28b09 100644 --- a/ace/Cache_Map_Manager_T.h +++ b/ace/Cache_Map_Manager_T.h @@ -28,13 +28,25 @@ // Forward declaration. class ACE_Allocator; +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + template class ACE_Cache_Map_Iterator; template class ACE_Cache_Map_Reverse_Iterator; -template +#define ACE_T1 class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES + +#else + +#define ACE_T1 class KEY, class VALUE, class MAP, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, MAP, CACHING_STRATEGY, ATTRIBUTES + +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +template class ACE_Cache_Map_Manager { // = TITLE @@ -58,12 +70,11 @@ public: typedef VALUE mapped_type; typedef MAP map_type; typedef CACHING_STRATEGY caching_strategy_type; + +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + typedef ITERATOR_IMPL ITERATOR_IMPLEMENTATION; typedef REVERSE_ITERATOR_IMPL REVERSE_ITERATOR_IMPLEMENTATION; - typedef ACE_Pair CACHE_VALUE; - // The actual value mapped to the key in the map. The - // are used by the strategy and is transparent to the user of this - // class. friend class ACE_Cache_Map_Iterator; friend class ACE_Cache_Map_Reverse_Iterator; @@ -80,6 +91,13 @@ public: typedef REVERSE_ITERATOR reverse_iterator; +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + + typedef ACE_Pair CACHE_VALUE; + // The actual value mapped to the key in the map. The + // are used by the strategy and is transparent to the user of this + // class. + // = Initialization and termination methods. ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_strategy, @@ -168,6 +186,8 @@ public: void dump (void) const; // Dumps the state of the object. +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + // = STL styled iterator factory functions. ITERATOR begin (void); @@ -178,6 +198,8 @@ public: REVERSE_ITERATOR rend (void); // Return reverse iterator. +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + MAP &map (void); // The map managed by the Cache_Map_Manager. @@ -195,11 +217,13 @@ protected: private: // = Disallow these operations. - ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Cache_Map_Manager &)) - ACE_UNIMPLEMENTED_FUNC (ACE_Cache_Map_Manager (const ACE_Cache_Map_Manager &)) + ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Cache_Map_Manager &)) + ACE_UNIMPLEMENTED_FUNC (ACE_Cache_Map_Manager (const ACE_Cache_Map_Manager &)) }; +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + template class ACE_Cache_Map_Iterator { @@ -347,6 +371,11 @@ protected: // belonging to the Cache_Map_Manager. }; +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +#undef ACE_T1 +#undef ACE_T2 + #if defined (__ACE_INLINE__) #include "ace/Cache_Map_Manager_T.i" #endif /* __ACE_INLINE__ */ diff --git a/ace/Cache_Map_Manager_T.i b/ace/Cache_Map_Manager_T.i index 1a199e8bc53..ab90786fe1b 100644 --- a/ace/Cache_Map_Manager_T.i +++ b/ace/Cache_Map_Manager_T.i @@ -1,259 +1,273 @@ /* -*- C++ -*- */ //$Id$ -#define T_1 class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES -#define T_2 KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) -template ACE_INLINE int -ACE_Cache_Map_Manager::purge (void) +#define ACE_T1 class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES + +#else + +#define ACE_T1 class KEY, class VALUE, class MAP, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, MAP, CACHING_STRATEGY, ATTRIBUTES + +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +template ACE_INLINE int +ACE_Cache_Map_Manager::purge (void) { - return this->caching_strategy ().clear_cache (this->map_); + return this->caching_strategy ().caching_utility ().clear_cache (this->map_, + this->caching_strategy ().purge_percent ()); } -template ACE_INLINE size_t -ACE_Cache_Map_Manager::current_size (void) const +template ACE_INLINE size_t +ACE_Cache_Map_Manager::current_size (void) const { return this->map_.current_size (); } -template ACE_INLINE size_t -ACE_Cache_Map_Manager::total_size (void) const +template ACE_INLINE size_t +ACE_Cache_Map_Manager::total_size (void) const { return this->map_.total_size (); } -template ACE_INLINE MAP & -ACE_Cache_Map_Manager::map (void) +template ACE_INLINE MAP & +ACE_Cache_Map_Manager::map (void) { return this->map_; } -template ACE_INLINE CACHING_STRATEGY & -ACE_Cache_Map_Manager::caching_strategy (void) +template ACE_INLINE CACHING_STRATEGY & +ACE_Cache_Map_Manager::caching_strategy (void) { return this->caching_strategy_; } -template ACE_INLINE ACE_Cache_Map_Iterator -ACE_Cache_Map_Manager::begin (void) +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + +template ACE_INLINE ACE_Cache_Map_Iterator +ACE_Cache_Map_Manager::begin (void) { return ITERATOR (this->map_.begin ()); } -template ACE_INLINE ACE_Cache_Map_Iterator -ACE_Cache_Map_Manager::end (void) +template ACE_INLINE ACE_Cache_Map_Iterator +ACE_Cache_Map_Manager::end (void) { return ITERATOR (this->map_.end ()); } -template ACE_INLINE ACE_Cache_Map_Reverse_Iterator -ACE_Cache_Map_Manager::rbegin (void) +template ACE_INLINE ACE_Cache_Map_Reverse_Iterator +ACE_Cache_Map_Manager::rbegin (void) { return REVERSE_ITERATOR (this->map_.rbegin ()); } -template ACE_INLINE ACE_Cache_Map_Reverse_Iterator -ACE_Cache_Map_Manager::rend (void) +template ACE_INLINE ACE_Cache_Map_Reverse_Iterator +ACE_Cache_Map_Manager::rend (void) { return REVERSE_ITERATOR (this->map_.rend ()); } -#undef T_1 -#undef T_2 +#undef ACE_T1 +#undef ACE_T2 -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// -#define T_1 class KEY, class VALUE, class IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES -#define T_2 KEY, VALUE, IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES +#define ACE_T1 class KEY, class VALUE, class IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES -template ACE_INLINE -ACE_Cache_Map_Iterator::ACE_Cache_Map_Iterator (const ACE_Cache_Map_Iterator &rhs) - : iterator_implementation_ (rhs.iterator_implementation_) +template ACE_INLINE +ACE_Cache_Map_Iterator::ACE_Cache_Map_Iterator (const ACE_Cache_Map_Iterator &rhs) + : iterator_implementation_ (rhs.iterator_implementation_) { } -template ACE_INLINE -ACE_Cache_Map_Iterator::~ACE_Cache_Map_Iterator (void) +template ACE_INLINE +ACE_Cache_Map_Iterator::~ACE_Cache_Map_Iterator (void) { } -template ACE_INLINE ACE_Cache_Map_Iterator & -ACE_Cache_Map_Iterator::operator= (const ACE_Cache_Map_Iterator &rhs) +template ACE_INLINE ACE_Cache_Map_Iterator & +ACE_Cache_Map_Iterator::operator= (const ACE_Cache_Map_Iterator &rhs) { this->iterator_implementation_ = rhs.iterator_implementation_; return *this; } -template ACE_INLINE int -ACE_Cache_Map_Iterator::operator== (const ACE_Cache_Map_Iterator &rhs) const +template ACE_INLINE int +ACE_Cache_Map_Iterator::operator== (const ACE_Cache_Map_Iterator &rhs) const { return this->iterator_implementation_ == rhs.iterator_implementation_; } -template ACE_INLINE int -ACE_Cache_Map_Iterator::operator!= (const ACE_Cache_Map_Iterator &rhs) const +template ACE_INLINE int +ACE_Cache_Map_Iterator::operator!= (const ACE_Cache_Map_Iterator &rhs) const { return this->iterator_implementation_ != rhs.iterator_implementation_; } -template ACE_INLINE ACE_Reference_Pair -ACE_Cache_Map_Iterator::operator* (void) const +template ACE_INLINE ACE_Reference_Pair +ACE_Cache_Map_Iterator::operator* (void) const { value_type retn ((*this->iterator_implementation_).ext_id_, (*this->iterator_implementation_).int_id_.first ()); return retn; } -template ACE_INLINE -ACE_Cache_Map_Iterator & -ACE_Cache_Map_Iterator::operator++ (void) +template ACE_INLINE +ACE_Cache_Map_Iterator & +ACE_Cache_Map_Iterator::operator++ (void) { ++this->iterator_implementation_; return *this; } -template ACE_INLINE -ACE_Cache_Map_Iterator -ACE_Cache_Map_Iterator::operator++ (int) +template ACE_INLINE +ACE_Cache_Map_Iterator +ACE_Cache_Map_Iterator::operator++ (int) { - ACE_Cache_Map_Iterator retn = *this; + ACE_Cache_Map_Iterator retn = *this; ++this->iterator_implementation_; return retn; } -template ACE_INLINE -ACE_Cache_Map_Iterator & -ACE_Cache_Map_Iterator::operator-- (void) +template ACE_INLINE +ACE_Cache_Map_Iterator & +ACE_Cache_Map_Iterator::operator-- (void) { --this->iterator_implementation_; return *this; } -template ACE_INLINE -ACE_Cache_Map_Iterator -ACE_Cache_Map_Iterator::operator-- (int) +template ACE_INLINE +ACE_Cache_Map_Iterator +ACE_Cache_Map_Iterator::operator-- (int) { - ACE_Cache_Map_Iterator retn = *this; + ACE_Cache_Map_Iterator retn = *this; --this->iterator_implementation_; return retn; } -template ACE_INLINE void -ACE_Cache_Map_Iterator::dump (void) const +template ACE_INLINE void +ACE_Cache_Map_Iterator::dump (void) const { this->iterator_implementation_.dump (); } -template ACE_INLINE -ACE_Cache_Map_Iterator::ACE_Cache_Map_Iterator (const IMPLEMENTATION &iterator_impl) - : iterator_implementation_ (iterator_impl) +template ACE_INLINE +ACE_Cache_Map_Iterator::ACE_Cache_Map_Iterator (const IMPLEMENTATION &iterator_impl) + : iterator_implementation_ (iterator_impl) { } -template ACE_INLINE IMPLEMENTATION & -ACE_Cache_Map_Iterator::iterator_implementation (void) +template ACE_INLINE IMPLEMENTATION & +ACE_Cache_Map_Iterator::iterator_implementation (void) { return this->iterator_implementation_; } -#undef T_1 -#undef T_2 +#undef ACE_T1 +#undef ACE_T2 -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// -#define T_1 class KEY, class VALUE, class REVERSE_IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES -#define T_2 KEY, VALUE, REVERSE_IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES +#define ACE_T1 class KEY, class VALUE, class REVERSE_IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES +#define ACE_T2 KEY, VALUE, REVERSE_IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator::ACE_Cache_Map_Reverse_Iterator (const ACE_Cache_Map_Reverse_Iterator &rhs) - : reverse_iterator_implementation_ (rhs.reverse_iterator_implementation_) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator::ACE_Cache_Map_Reverse_Iterator (const ACE_Cache_Map_Reverse_Iterator &rhs) + : reverse_iterator_implementation_ (rhs.reverse_iterator_implementation_) { } -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator::~ACE_Cache_Map_Reverse_Iterator (void) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator::~ACE_Cache_Map_Reverse_Iterator (void) { } -template ACE_INLINE ACE_Cache_Map_Reverse_Iterator & -ACE_Cache_Map_Reverse_Iterator::operator= (const ACE_Cache_Map_Reverse_Iterator &rhs) +template ACE_INLINE ACE_Cache_Map_Reverse_Iterator & +ACE_Cache_Map_Reverse_Iterator::operator= (const ACE_Cache_Map_Reverse_Iterator &rhs) { this->reverse_iterator_implementation_ = rhs.reverse_iterator_implementation_; return *this; } -template ACE_INLINE int -ACE_Cache_Map_Reverse_Iterator::operator== (const ACE_Cache_Map_Reverse_Iterator &rhs) const +template ACE_INLINE int +ACE_Cache_Map_Reverse_Iterator::operator== (const ACE_Cache_Map_Reverse_Iterator &rhs) const { return this->reverse_iterator_implementation_ == rhs.reverse_iterator_implementation_; } -template ACE_INLINE int -ACE_Cache_Map_Reverse_Iterator::operator!= (const ACE_Cache_Map_Reverse_Iterator &rhs) const +template ACE_INLINE int +ACE_Cache_Map_Reverse_Iterator::operator!= (const ACE_Cache_Map_Reverse_Iterator &rhs) const { return this->reverse_iterator_implementation_ != rhs.reverse_iterator_implementation_; } -template ACE_INLINE ACE_Reference_Pair -ACE_Cache_Map_Reverse_Iterator::operator* (void) const +template ACE_INLINE ACE_Reference_Pair +ACE_Cache_Map_Reverse_Iterator::operator* (void) const { value_type retv ((*this->reverse_iterator_implementation_).ext_id_, (*this->reverse_iterator_implementation_).int_id_.first ()); return retv; } -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator & -ACE_Cache_Map_Reverse_Iterator::operator++ (void) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator & +ACE_Cache_Map_Reverse_Iterator::operator++ (void) { ++this->reverse_iterator_implementation_; return *this; } -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator -ACE_Cache_Map_Reverse_Iterator::operator++ (int) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator +ACE_Cache_Map_Reverse_Iterator::operator++ (int) { - ACE_Cache_Map_Reverse_Iterator retn = *this; + ACE_Cache_Map_Reverse_Iterator retn = *this; ++this->reverse_iterator_implementation_; return retn; } -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator & -ACE_Cache_Map_Reverse_Iterator::operator-- (void) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator & +ACE_Cache_Map_Reverse_Iterator::operator-- (void) { --this->reverse_iterator_implementation_; return *this; } -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator -ACE_Cache_Map_Reverse_Iterator::operator-- (int) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator +ACE_Cache_Map_Reverse_Iterator::operator-- (int) { - ACE_Cache_Map_Reverse_Iterator retn = *this; + ACE_Cache_Map_Reverse_Iterator retn = *this; --this->reverse_iterator_implementation_; return retn; } -template ACE_INLINE void -ACE_Cache_Map_Reverse_Iterator::dump (void) const +template ACE_INLINE void +ACE_Cache_Map_Reverse_Iterator::dump (void) const { this->reverse_iterator_implementation_.dump (); } -template ACE_INLINE -ACE_Cache_Map_Reverse_Iterator::ACE_Cache_Map_Reverse_Iterator (const REVERSE_IMPLEMENTATION &iterator_impl) - : reverse_iterator_implementation_(iterator_impl) +template ACE_INLINE +ACE_Cache_Map_Reverse_Iterator::ACE_Cache_Map_Reverse_Iterator (const REVERSE_IMPLEMENTATION &iterator_impl) + : reverse_iterator_implementation_(iterator_impl) { } -template ACE_INLINE REVERSE_IMPLEMENTATION & -ACE_Cache_Map_Reverse_Iterator::iterator_implementation (void) +template ACE_INLINE REVERSE_IMPLEMENTATION & +ACE_Cache_Map_Reverse_Iterator::iterator_implementation (void) { return this->reverse_iterator_implementation_; } -#undef T_1 -#undef T_2 +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +#undef ACE_T1 +#undef ACE_T2 diff --git a/ace/Cached_Connect_Strategy_T.cpp b/ace/Cached_Connect_Strategy_T.cpp index 7fb4e9dacef..02f5c98a6e6 100644 --- a/ace/Cached_Connect_Strategy_T.cpp +++ b/ace/Cached_Connect_Strategy_T.cpp @@ -25,7 +25,7 @@ ACE_RCSID(ace, Cached_Connect_Strategy_T, "$Id$") -template + template ACE_Cached_Connect_Strategy_Ex::ACE_Cached_Connect_Strategy_Ex (CACHING_STRATEGY &caching_s, ACE_Creation_Strategy *cre_s, @@ -45,8 +45,9 @@ ACE_Cached_Connect_Strategy_Ex ACE_Cached_Connect_Strategy_Ex::~ACE_Cached_Connect_Strategy_Ex (void) { +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) // Close down all cached service handlers. - for (CONNECTION_CACHE_ITERATOR iter = this->connection_cache_.begin (); + for (CONNECTION_CACHE::ITERATOR iter = this->connection_cache_.begin (); iter != this->connection_cache_.end (); ++iter) { @@ -56,26 +57,7 @@ ACE_Cached_Connect_Strategy_Exclose (); } } -} - -template int -ACE_Cached_Connect_Strategy_Ex::open -(ACE_Creation_Strategy *cre_s, - ACE_Concurrency_Strategy *con_s, - ACE_Recycling_Strategy *rec_s) -{ - int result = this->CCSBASE::open (cre_s, con_s, rec_s); - if (result == -1) - ACE_ERROR_RETURN ((LM_ERROR, - ASYS_TEXT ("%p\n"), - ASYS_TEXT ("Base initialisation failed\n")), - -1); - - if (this->caching_strategy ().open (&this->svc_cleanup_strategy_, - 0) == -1) - return -1; - - return 0; +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ } template int @@ -178,12 +160,12 @@ ACE_Cached_Connect_Strategy_Excached_connect (sh, - remote_addr, - timeout, - local_addr, - reuse_addr, - flags, - perms) == -1) + remote_addr, + timeout, + local_addr, + reuse_addr, + flags, + perms) == -1) { return -1; } @@ -218,12 +200,12 @@ ACE_Cached_Connect_Strategy_Ex int ACE_Cached_Connect_Strategy_Ex::cached_connect (SVC_HANDLER *&sh, - const ACE_PEER_CONNECTOR_ADDR &remote_addr, - ACE_Time_Value *timeout, - const ACE_PEER_CONNECTOR_ADDR &local_addr, - int reuse_addr, - int flags, - int perms) + const ACE_PEER_CONNECTOR_ADDR &remote_addr, + ACE_Time_Value *timeout, + const ACE_PEER_CONNECTOR_ADDR &local_addr, + int reuse_addr, + int flags, + int perms) { // Actively establish the connection. This is a timed blocking // connect. @@ -243,7 +225,7 @@ ACE_Cached_Connect_Strategy_Ex *cre_s, - ACE_Concurrency_Strategy *con_s, - ACE_Recycling_Strategy *rec_s); - // This methods allow you to change the strategies used by the - // cached connector. - virtual int cached_connect (SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, @@ -84,7 +78,7 @@ public: // = Typedefs for managing the map typedef ACE_Refcounted_Hash_Recyclable REFCOUNTED_HASH_RECYCLABLE_ADDRESS; - typedef ACE_Hash_Cache_Map_Manager,ACE_Equal_To, CACHING_STRATEGY, ATTRIBUTES> + typedef ACE_Hash_Cache_Map_Manager, ACE_Equal_To, CACHING_STRATEGY, ATTRIBUTES> CONNECTION_CACHE; typedef ACE_TYPENAME CONNECTION_CACHE::CACHE_ENTRY CONNECTION_CACHE_ENTRY; @@ -92,12 +86,10 @@ public: KEY; typedef ACE_TYPENAME CONNECTION_CACHE::mapped_type VALUE; - typedef ACE_TYPENAME CONNECTION_CACHE::ITERATOR - CONNECTION_CACHE_ITERATOR; // = Cleanup of the svc_handler. - typedef ACE_Svc_Cleanup_Strategy,ACE_Hash_Map_Manager_Ex, ACE_Hash, ACE_Equal_To, MUTEX> > - SVC_CLEANUP_STRATEGY; + typedef ACE_Recyclable_Handler_Cleanup_Strategy,ACE_Hash_Map_Manager_Ex, ACE_Hash, ACE_Equal_To, MUTEX> > + CLEANUP_STRATEGY; typedef ACE_Cached_Connect_Strategy CCSBASE; @@ -153,10 +145,6 @@ protected: CONNECTION_CACHE connection_cache_; // Table that maintains the cache of connected s. - - SVC_CLEANUP_STRATEGY svc_cleanup_strategy_; - // The strategy which controls the destruction and closing of the - // svc_handler. }; #if !defined (ACE_LACKS_INLINE_FUNCTIONS) diff --git a/ace/Caching_Strategies_T.cpp b/ace/Caching_Strategies_T.cpp index 532064ae23e..f36d593ad84 100644 --- a/ace/Caching_Strategies_T.cpp +++ b/ace/Caching_Strategies_T.cpp @@ -15,367 +15,39 @@ ACE_RCSID(ace, Caching_Strategies_T, "$Id$") -template -ACE_Caching_Strategy::~ACE_Caching_Strategy (void) +template +ACE_Caching_Strategy::~ACE_Caching_Strategy (void) { } ////////////////////////////////////////////////////////////////////////////////// -template -ACE_LRU_Caching_Strategy::ACE_LRU_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) +template +ACE_LRU_Caching_Strategy::ACE_LRU_Caching_Strategy (void) : timer_ (0), - purge_percent_ (10), - entries_ (0), - cleanup_strategy_ (0), - delete_cleanup_strategy_ (1), - caching_strategy_utility_ (0), - delete_caching_strategy_utility_ (1) + purge_percent_ (10) { - if (this->open (cleanup_s, - delete_cleanup_strategy, - utility_s, - delete_caching_strategy_utility) == -1) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("%p\n"), - ASYS_TEXT ("ACE_LRU_Caching_Strategy::ACE_LRU_Caching_Strategy"))); - -} - -template -ACE_LRU_Caching_Strategy::~ACE_LRU_Caching_Strategy (void) -{ - if (this->delete_cleanup_strategy_ == 1) - delete this->cleanup_strategy_; - this->delete_cleanup_strategy_ = 0; - this->cleanup_strategy_ = 0; - - if (this->delete_caching_strategy_utility_ == 1) - delete this->caching_strategy_utility_; - this->delete_caching_strategy_utility_ = 0; - this->caching_strategy_utility_ = 0; -} - -template int -ACE_LRU_Caching_Strategy::open (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) -{ - // Initialise the cleanup strategy. - - // First we decide whether we need to clean up. - if (this->cleanup_strategy_ != 0 && - this->delete_cleanup_strategy_ == 1 && - cleanup_s != 0) - { - delete this->cleanup_strategy_; - this->cleanup_strategy_ = 0; - this->delete_cleanup_strategy_ = 0; - } - - if (cleanup_s != 0) - { - this->cleanup_strategy_ = cleanup_s; - this->delete_cleanup_strategy_ = delete_cleanup_strategy; - } - else if (this->cleanup_strategy_ == 0) - { - ACE_NEW_RETURN (this->cleanup_strategy_, - CLEANUP_STRATEGY, - -1); - - this->delete_cleanup_strategy_ = 1; - } - - // Initialise the caching strategy utility. - - // First we decide whether we need to clean up. - if (this->caching_strategy_utility_ != 0 && - this->delete_caching_strategy_utility_ == 1 && - utility_s != 0) - { - delete this->caching_strategy_utility_; - this->caching_strategy_utility_ = 0; - this->delete_caching_strategy_utility_ = 0; - } - - if (utility_s != 0) - { - this->caching_strategy_utility_ = utility_s; - this->delete_caching_strategy_utility_ = delete_caching_strategy_utility; - } - else if (this->caching_strategy_utility_ == 0) - { - ACE_NEW_RETURN (this->caching_strategy_utility_, - CACHING_STRATEGY_UTILITY, - -1); - - this->delete_caching_strategy_utility_ = 1; - } - - return 0; -} - -template int -ACE_LRU_Caching_Strategy::clear_cache (CONTAINER &container) -{ - return this->caching_strategy_utility_->clear_cache (container, - this->cleanup_strategy_, - this->purge_percent_); } //////////////////////////////////////////////////////////////////////////////////////////////// -template -ACE_LFU_Caching_Strategy::ACE_LFU_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) - : purge_percent_ (10), - entries_ (0), - cleanup_strategy_ (0), - delete_cleanup_strategy_ (1), - caching_strategy_utility_ (0), - delete_caching_strategy_utility_ (1) -{ - if (this->open (cleanup_s, - delete_cleanup_strategy, - utility_s, - delete_caching_strategy_utility) == -1) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("%p\n"), - ASYS_TEXT ("ACE_LFU_Caching_Strategy::ACE_LFU_Caching_Strategy"))); - -} - -template -ACE_LFU_Caching_Strategy::~ACE_LFU_Caching_Strategy (void) -{ - if (this->delete_cleanup_strategy_ == 1) - delete this->cleanup_strategy_; - this->delete_cleanup_strategy_ = 0; - this->cleanup_strategy_ = 0; - - if (this->delete_caching_strategy_utility_ == 1) - delete this->caching_strategy_utility_; - this->delete_caching_strategy_utility_ = 0; - this->caching_strategy_utility_ = 0; -} - -template int -ACE_LFU_Caching_Strategy::open (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) -{ - // Initialise the cleanup strategy. - - // First we decide whether we need to clean up. - if (this->cleanup_strategy_ != 0 && - this->delete_cleanup_strategy_ == 1 && - cleanup_s != 0) - { - delete this->cleanup_strategy_; - this->cleanup_strategy_ = 0; - this->delete_cleanup_strategy_ = delete_cleanup_strategy; - } - - if (cleanup_s != 0) - this->cleanup_strategy_ = cleanup_s; - else if (this->cleanup_strategy_ == 0) - { - ACE_NEW_RETURN (this->cleanup_strategy_, - CLEANUP_STRATEGY, - -1); - - this->delete_cleanup_strategy_ = 1; - } - - // Initialise the caching strategy utility. - - // First we decide whether we need to clean up. - if (this->caching_strategy_utility_ != 0 && - this->delete_caching_strategy_utility_ == 1 && - utility_s != 0) - { - delete this->caching_strategy_utility_; - this->caching_strategy_utility_ = 0; - this->delete_caching_strategy_utility_ = delete_caching_strategy_utility; - } - - if (utility_s != 0) - this->caching_strategy_utility_ = utility_s; - else if (this->caching_strategy_utility_ == 0) - { - ACE_NEW_RETURN (this->caching_strategy_utility_, - CACHING_STRATEGY_UTILITY, - -1); - - this->delete_caching_strategy_utility_ = 1; - } - - return 0; -} - -template int -ACE_LFU_Caching_Strategy::clear_cache (CONTAINER &container) +template +ACE_LFU_Caching_Strategy::ACE_LFU_Caching_Strategy (void) + : purge_percent_ (10) { - return this->caching_strategy_utility_->clear_cache (container, - this->cleanup_strategy_, - this->purge_percent_); } - //////////////////////////////////////////////////////////////////////////////////////////////// -template -ACE_FIFO_Caching_Strategy::ACE_FIFO_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) +template +ACE_FIFO_Caching_Strategy::ACE_FIFO_Caching_Strategy (void) : order_ (0), - purge_percent_ (10), - entries_ (0), - cleanup_strategy_ (0), - delete_cleanup_strategy_ (1), - caching_strategy_utility_ (0), - delete_caching_strategy_utility_ (1) -{ - if (this->open (cleanup_s, - delete_cleanup_strategy, - utility_s, - delete_caching_strategy_utility) == -1) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("%p\n"), - ASYS_TEXT ("ACE_FIFO_Caching_Strategy::ACE_FIFO_Caching_Strategy"))); -} - -template -ACE_FIFO_Caching_Strategy::~ACE_FIFO_Caching_Strategy (void) - + purge_percent_ (10) { - if (this->delete_cleanup_strategy_ == 1) - delete this->cleanup_strategy_; - this->delete_cleanup_strategy_ = 0; - this->cleanup_strategy_ = 0; - - if (this->delete_caching_strategy_utility_ == 1) - delete this->caching_strategy_utility_; - this->delete_caching_strategy_utility_ = 0; - this->caching_strategy_utility_ = 0; -} - -template int -ACE_FIFO_Caching_Strategy::open (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) -{ - // Initialise the cleanup strategy. - - // First we decide whether we need to clean up. - if (this->cleanup_strategy_ != 0 && - this->delete_cleanup_strategy_ == 1 && - cleanup_s != 0) - { - delete this->cleanup_strategy_; - this->cleanup_strategy_ = 0; - this->delete_cleanup_strategy_ = delete_cleanup_strategy; - } - - if (cleanup_s != 0) - this->cleanup_strategy_ = cleanup_s; - else if (this->cleanup_strategy_ == 0) - { - ACE_NEW_RETURN (this->cleanup_strategy_, - CLEANUP_STRATEGY, - -1); - - this->delete_cleanup_strategy_ = 1; - } - - // Initialise the caching strategy utility. - - // First we decide whether we need to clean up. - if (this->caching_strategy_utility_ != 0 && - this->delete_caching_strategy_utility_ == 1 && - utility_s != 0) - { - delete this->caching_strategy_utility_; - this->caching_strategy_utility_ = 0; - this->delete_caching_strategy_utility_ = delete_caching_strategy_utility; - } - - if (utility_s != 0) - this->caching_strategy_utility_ = utility_s; - else if (this->caching_strategy_utility_ == 0) - { - ACE_NEW_RETURN (this->caching_strategy_utility_, - CACHING_STRATEGY_UTILITY, - -1); - - this->delete_caching_strategy_utility_ = 1; - } - - return 0; -} - -template int -ACE_FIFO_Caching_Strategy::clear_cache (CONTAINER &container) -{ - return this->caching_strategy_utility_->clear_cache (container, - this->cleanup_strategy_, - this->purge_percent_); } //////////////////////////////////////////////////////////////////////////////////////////////// - -template -ACE_Null_Caching_Strategy::ACE_Null_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) -{ - ACE_UNUSED_ARG (cleanup_s); - ACE_UNUSED_ARG (delete_cleanup_strategy); - ACE_UNUSED_ARG (utility_s); - ACE_UNUSED_ARG (delete_caching_strategy_utility); -} - -template int -ACE_Null_Caching_Strategy::open (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) -{ - ACE_UNUSED_ARG (cleanup_s); - ACE_UNUSED_ARG (delete_cleanup_strategy); - ACE_UNUSED_ARG (utility_s); - ACE_UNUSED_ARG (delete_caching_strategy_utility); - - return 0; -} - -template -ACE_Null_Caching_Strategy::~ACE_Null_Caching_Strategy (void) -{ -} - -template int -ACE_Null_Caching_Strategy::clear_cache (CONTAINER &container) -{ - ACE_UNUSED_ARG (container); - - return 0; -} - -/////////////////////////////////////////////////////////////////////////////////////////////// - ACE_ALLOC_HOOK_DEFINE(ACE_LRU_Caching_Strategy) ACE_ALLOC_HOOK_DEFINE(ACE_LFU_Caching_Strategy) ACE_ALLOC_HOOK_DEFINE(ACE_FIFO_Caching_Strategy) diff --git a/ace/Caching_Strategies_T.h b/ace/Caching_Strategies_T.h index 44b5e31f096..41966b677f0 100644 --- a/ace/Caching_Strategies_T.h +++ b/ace/Caching_Strategies_T.h @@ -25,9 +25,11 @@ #define ACE_LACKS_PRAGMA_ONCE #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "ace/Cleanup_Strategies_T.h" +#if defined(_MSC_VER) +#pragma warning(disable:4503) +#endif /* _MSC_VER */ -template +template class ACE_Caching_Strategy { // = TITLE @@ -42,12 +44,6 @@ public: virtual ~ACE_Caching_Strategy (void); // Destructor. - virtual int open (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1) = 0; - // This method which does the actual initialisation. - virtual ATTRIBUTES attributes (void) = 0; // Accessor method for the timer attributes. @@ -82,9 +78,8 @@ public: // This method acts as a notification about the CONTAINERs rebind // method call - virtual int clear_cache (CONTAINER &container) = 0; - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. + virtual CACHING_UTILITY &caching_utility (void) = 0; + // Purge the cache. virtual void dump (void) const = 0; // Dumps the state of the object. @@ -92,8 +87,8 @@ public: ////////////////////////////////////////////////////////////////////////// -template -class ACE_Caching_Strategy_Adapter : public ACE_Caching_Strategy +template +class ACE_Caching_Strategy_Adapter : public ACE_Caching_Strategy { // = TITLE // This class follows the Adaptor pattern and is used to provide @@ -114,12 +109,6 @@ public: ~ACE_Caching_Strategy_Adapter (void); // Destructor. - int open (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // This method which does the actual initialisation. - ATTRIBUTES attributes (void); // Accessor method for the timer attributes. @@ -154,13 +143,12 @@ public: // This method acts as a notification about the CONTAINERs rebind // method call - int clear_cache (CONTAINER &container); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. - IMPLEMENTATION &implementation (void); // Accessor to the implementation. + CACHING_UTILITY &caching_utility (void); + // Purge the cache. + void dump (void) const; // Dumps the state of the object. @@ -175,7 +163,7 @@ private: ////////////////////////////////////////////////////////////////////////// -template +template class ACE_LRU_Caching_Strategy { // = TITLE @@ -193,7 +181,7 @@ class ACE_LRU_Caching_Strategy // The ATTRIBUTES are the deciding factor for purging of entries // and should logically be included with the VALUE. Some ways of // doing this are: As being a member of the VALUE or VALUE being - // ACE_Pair. The CACHING_STRATEGY_UTILITY is the + // ACE_Pair. The CACHING_UTILITY is the // class which can be plugged in and which decides the entries // to purge. @@ -201,37 +189,18 @@ public: // Traits. typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; // = Initialisation and termination. - ACE_LRU_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // The is the map in which the entries reside. - // The Cleanup_Strategy is the callback class to which the entries - // to be cleaned up will be delegated. The - // flag is needed to decide the ownership of the cleanup strategy. - // Also, the timer attribute is initialed to zero in this constructor. - // And the field denotes the percentage of the entries + ACE_LRU_Caching_Strategy (void); + // The is the map in which the entries reside. The + // timer attribute is initialed to zero in this constructor. And + // the field denotes the percentage of the entries // in the cache which can be purged automagically and by default is - // set to 10%. The ultility which helps the caching strategy in the - // purging of entries needs to be specified. By default a new one - // will be created of type CACHING_STRATEGY_UTILITY and - // decides whether to destroy the - // utility object or not. - - ~ACE_LRU_Caching_Strategy (void); + // set to 10%. // = Operations of the strategy. - int open (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // This method which does the actual initialisation. - ATTRIBUTES attributes (void); // Accessor method for the timer attributes. @@ -268,17 +237,14 @@ public: // This method acts as a notification about the CONTAINERs rebind // method call - int clear_cache (CONTAINER &container); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. + CACHING_UTILITY &caching_utility (void); + // Purge the cache. void dump (void) const; // Dumps the state of the object. private: - typedef ACE_Default_Cleanup_Strategy CLEANUP_STRATEGY; - ATTRIBUTES timer_; // This element is the one which is the deciding factor for purging // of an ITEM. @@ -286,31 +252,14 @@ private: double purge_percent_; // The level about which the purging will happen automagically. - unsigned int entries_; - // The no of entries bound in the cache. - - ACE_Cleanup_Strategy *cleanup_strategy_; - // The cleanup strategy which can be used to destroy the entries of - // the container. - - int delete_cleanup_strategy_; - // The flag which denotes the ownership of the cleanup strategy. - // If 1 then this class itself will destroy the strategy. - - CACHING_STRATEGY_UTILITY *caching_strategy_utility_; + CACHING_UTILITY caching_utility_; // This is the helper class which will decide and expunge entries // from the cache. - - int delete_caching_strategy_utility_; - // The flag which denotes the ownership of the - // caching_strategy_utility. If 1 then this class itself will - // destroy the strategy utility object. - }; ////////////////////////////////////////////////////////////////////////// -template +template class ACE_LFU_Caching_Strategy { // = TITLE @@ -328,7 +277,7 @@ class ACE_LFU_Caching_Strategy // The ATTRIBUTES are the deciding factor for purging of entries // and should logically be included with the VALUE. Some ways of // doing this are: As being a member of the VALUE or VALUE being - // ACE_Pair. The CACHING_STRATEGY_UTILITY is the + // ACE_Pair. The CACHING_UTILITY is the // class which can be plugged in and which decides the entries // to purge. @@ -336,34 +285,15 @@ public: // Traits. typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; // = Initialisation and termination methods. - ACE_LFU_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // The is the map in which the entries reside. - // The Cleanup_Strategy is the callback class to which the entries - // to be cleaned up will be delegated. The - // flag is needed to decide the ownership of the cleanup strategy. - // Also, the timer attribute is initialed to zero in this constructor. - // And the field denotes the percentage of the entries + ACE_LFU_Caching_Strategy (void); + // The is the map in which the entries reside. The + // timer attribute is initialed to zero in this constructor. And + // the field denotes the percentage of the entries // in the cache which can be purged automagically and by default is - // set to 10%.The ultility which helps the caching strategy in the - // purging of entries will be default be the - // ACE_Caching_Strategy_Utility and the - // decides whether to destroy the - // utility or not. - - ~ACE_LFU_Caching_Strategy (void); - - int open (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // This method which does the actual initialisation. + // set to 10%. // = Strategy methods. @@ -401,45 +331,25 @@ public: // This method acts as a notification about the CONTAINERs rebind // method call - - int clear_cache (CONTAINER &container); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. + CACHING_UTILITY &caching_utility (void); + // Purge the cache. void dump (void) const; // Dumps the state of the object. private: - typedef ACE_Default_Cleanup_Strategy CLEANUP_STRATEGY; - double purge_percent_; // The level about which the purging will happen automagically. - unsigned int entries_; - // The no of entries bound in the cache. - - ACE_Cleanup_Strategy *cleanup_strategy_; - // The cleanup strategy which can be used to destroy the entries of - // the container. - - int delete_cleanup_strategy_; - // The flag which denotes the ownership of the cleanup strategy. - // If 1 then this class itself will destroy the strategy. - - CACHING_STRATEGY_UTILITY *caching_strategy_utility_; + CACHING_UTILITY caching_utility_; // This is the helper class which will decide and expunge entries // from the cache. - - int delete_caching_strategy_utility_; - // The flag which denotes the ownership of the - // caching_strategy_utility. If 1 then this class itself will - // destroy the strategy utility object. }; ///////////////////////////////////////////////////////////// -template +template class ACE_FIFO_Caching_Strategy { // = TITLE @@ -455,41 +365,22 @@ class ACE_FIFO_Caching_Strategy // The ATTRIBUTES are the deciding factor for purging of entries // and should logically be included with the VALUE. Some ways of // doing this are: As being a member of the VALUE or VALUE being - // ACE_Pair. The CACHING_STRATEGY_UTILITY is the + // ACE_Pair. The CACHING_UTILITY is the // class which can be plugged in and which decides the entries // to purge. public: typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; // = Initialisation and termination. - ACE_FIFO_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // The is the map in which the entries reside. - // The Cleanup_Strategy is the callback class to which the entries - // to be cleaned up will be delegated. The - // flag is needed to decide the ownership of the cleanup strategy. - // Also, the timer attribute is initialed to zero in this constructor. - // And the field denotes the percentage of the entries + ACE_FIFO_Caching_Strategy (void); + // The is the map in which the entries reside. The + // timer attribute is initialed to zero in this constructor. And + // the field denotes the percentage of the entries // in the cache which can be purged automagically and by default is - // set to 10%.The ultility which helps the caching strategy in the - // purging of entries will be default be the - // ACE_Caching_Strategy_Utility and the - // decides whether to destroy the - // utility or not. - - ~ACE_FIFO_Caching_Strategy (void); - - int open (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // This method which does the actual initialisation. + // set to 10%. // = Strategy methods. @@ -526,17 +417,14 @@ public: const ATTRIBUTES &attr); // Notification for an item getting bound again into the cache. - int clear_cache (CONTAINER &container); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. + CACHING_UTILITY &caching_utility (void); + // Purge the cache. void dump (void) const; // Dumps the state of the object. private: - typedef ACE_Default_Cleanup_Strategy CLEANUP_STRATEGY; - ATTRIBUTES order_; // The order is the deciding factor for the item to be removed from // the cache. @@ -544,29 +432,12 @@ private: double purge_percent_; // The level about which the purging will happen automagically. - unsigned int entries_; - // The no of entries bound in the cache. - - ACE_Cleanup_Strategy *cleanup_strategy_; - // The cleanup strategy which can be used to destroy the entries of - // the container. - - int delete_cleanup_strategy_; - // The flag which denotes the ownership of the cleanup strategy. - // If 1 then this class itself will destroy the strategy. - - CACHING_STRATEGY_UTILITY *caching_strategy_utility_; + CACHING_UTILITY caching_utility_; // This is the helper class which will decide and expunge entries // from the cache. - - int delete_caching_strategy_utility_; - // The flag which denotes the ownership of the - // caching_strategy_utility. If 1 then this class itself will - // destroy the strategy utility object. - }; -template +template class ACE_Null_Caching_Strategy { // = TITLE @@ -581,23 +452,6 @@ public: // = Traits. typedef ATTRIBUTES CACHING_ATTRIBUTES; - typedef CONTAINER CACHE; - - // = Initialisation and termination. - - ACE_Null_Caching_Strategy (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - - ~ACE_Null_Caching_Strategy (void); - - - int open (ACE_Cleanup_Strategy *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // This method which does the actual initialisation. // = Strategy methods. All are NO_OP methods!!! @@ -634,13 +488,17 @@ public: const ATTRIBUTES &attr); // Notification for an item getting bound again into the cache. - int clear_cache (CONTAINER &container); - // This is the method which looks at each ITEM's attributes and - // then decides on the one to remove. + CACHING_UTILITY &caching_utility (void); + // Purge the cache. void dump (void) const; // Dumps the state of the object. +private: + + CACHING_UTILITY caching_utility_; + // This is the helper class which will decide and expunge entries + // from the cache. }; #if defined (__ACE_INLINE__) diff --git a/ace/Caching_Strategies_T.i b/ace/Caching_Strategies_T.i index 8e114434cf2..2cfd63534aa 100644 --- a/ace/Caching_Strategies_T.i +++ b/ace/Caching_Strategies_T.i @@ -3,9 +3,9 @@ ////////////////////////////////////////////////////////////////////////////////// -template ACE_INLINE -ACE_Caching_Strategy_Adapter::ACE_Caching_Strategy_Adapter (IMPLEMENTATION *implementation, - int delete_implementation) +template ACE_INLINE +ACE_Caching_Strategy_Adapter::ACE_Caching_Strategy_Adapter (IMPLEMENTATION *implementation, + int delete_implementation) : implementation_ (implementation), delete_implementation_ (delete_implementation) { @@ -17,100 +17,89 @@ ACE_Caching_Strategy_Adapter ACE_INLINE -ACE_Caching_Strategy_Adapter::~ACE_Caching_Strategy_Adapter (void) +template ACE_INLINE +ACE_Caching_Strategy_Adapter::~ACE_Caching_Strategy_Adapter (void) { if (this->delete_implementation_) - delete this->implementation_; - this->delete_implementation_ = 0; - this->implementation_ = 0; -} - -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::open (ACE_Cleanup_Strategy *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) -{ - return this->implementation_->open (cleanup_s, - delete_cleanup_strategy, - utility_s, - delete_caching_strategy_utility); + { + delete this->implementation_; + this->delete_implementation_ = 0; + this->implementation_ = 0; + } } -template ACE_INLINE ATTRIBUTES -ACE_Caching_Strategy_Adapter::attributes (void) +template ACE_INLINE ATTRIBUTES +ACE_Caching_Strategy_Adapter::attributes (void) { return this->implementation_->attributes (); } -template ACE_INLINE double -ACE_Caching_Strategy_Adapter::purge_percent (void) +template ACE_INLINE double +ACE_Caching_Strategy_Adapter::purge_percent (void) { return this->implementation_->purge_percent (); } -template ACE_INLINE void -ACE_Caching_Strategy_Adapter::purge_percent (double percentage) +template ACE_INLINE void +ACE_Caching_Strategy_Adapter::purge_percent (double percentage) { this->implementation_->purge_percent (percentage); } -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::notify_bind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Caching_Strategy_Adapter::notify_bind (int result, + const ATTRIBUTES &attr) { return this->implementation_->notify_bind (result, attr); } -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::notify_find (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Caching_Strategy_Adapter::notify_find (int result, + ATTRIBUTES &attr) { return this->implementation_->notify_find (result, attr); } -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::notify_unbind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Caching_Strategy_Adapter::notify_unbind (int result, + const ATTRIBUTES &attr) { return this->implementation_->notify_unbind (result, attr); } -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::notify_trybind (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Caching_Strategy_Adapter::notify_trybind (int result, + ATTRIBUTES &attr) { return this->implementation_->notify_trybind (result, attr); } -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::notify_rebind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Caching_Strategy_Adapter::notify_rebind (int result, + const ATTRIBUTES &attr) { return this->implementation_->notify_rebind (result, attr); } -template ACE_INLINE int -ACE_Caching_Strategy_Adapter::clear_cache (CONTAINER &container) +template ACE_INLINE IMPLEMENTATION & +ACE_Caching_Strategy_Adapter::implementation (void) { - return this->implementation_->clear_cache (container); + return *this->implementation_; } -template ACE_INLINE IMPLEMENTATION & -ACE_Caching_Strategy_Adapter::implementation (void) +template ACE_INLINE CACHING_UTILITY & +ACE_Caching_Strategy_Adapter::caching_utility (void) { - return *this->implementation_; + return this->implementation_->caching_utility (); } - -template ACE_INLINE void -ACE_Caching_Strategy_Adapter::dump (void) const +template ACE_INLINE void +ACE_Caching_Strategy_Adapter::dump (void) const { ACE_TRACE ("ACE_Caching_Strategy_Adapter::dump"); @@ -120,42 +109,39 @@ ACE_Caching_Strategy_Adapter ACE_INLINE ATTRIBUTES -ACE_LRU_Caching_Strategy::attributes (void) +template ACE_INLINE ATTRIBUTES +ACE_LRU_Caching_Strategy::attributes (void) { return this->timer_; } -template ACE_INLINE double -ACE_LRU_Caching_Strategy::purge_percent (void) +template ACE_INLINE double +ACE_LRU_Caching_Strategy::purge_percent (void) { return this->purge_percent_; } -template ACE_INLINE void -ACE_LRU_Caching_Strategy::purge_percent (double percentage) +template ACE_INLINE void +ACE_LRU_Caching_Strategy::purge_percent (double percentage) { this->purge_percent_ = percentage; } -template ACE_INLINE int -ACE_LRU_Caching_Strategy::notify_bind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LRU_Caching_Strategy::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); if (result == 0) - { - ++this->timer_; - ++this->entries_; - } + ++this->timer_; return result; } -template ACE_INLINE int -ACE_LRU_Caching_Strategy::notify_find (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LRU_Caching_Strategy::notify_find (int result, + ATTRIBUTES &attr) { if (result == 0) { @@ -166,26 +152,26 @@ ACE_LRU_Caching_Strategy ACE_INLINE int -ACE_LRU_Caching_Strategy::notify_unbind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LRU_Caching_Strategy::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_LRU_Caching_Strategy::notify_trybind (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LRU_Caching_Strategy::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_LRU_Caching_Strategy::notify_rebind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LRU_Caching_Strategy::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); @@ -195,8 +181,14 @@ ACE_LRU_Caching_Strategy ACE_INLINE void -ACE_LRU_Caching_Strategy::dump (void) const +template ACE_INLINE CACHING_UTILITY & +ACE_LRU_Caching_Strategy::caching_utility (void) +{ + return this->caching_utility_; +} + +template ACE_INLINE void +ACE_LRU_Caching_Strategy::dump (void) const { ACE_TRACE ("ACE_LRU_Caching_Strategy::dump"); @@ -207,39 +199,36 @@ ACE_LRU_Caching_Strategy ACE_INLINE ATTRIBUTES -ACE_LFU_Caching_Strategy::attributes (void) +template ACE_INLINE ATTRIBUTES +ACE_LFU_Caching_Strategy::attributes (void) { return 0; } -template ACE_INLINE double -ACE_LFU_Caching_Strategy::purge_percent (void) +template ACE_INLINE double +ACE_LFU_Caching_Strategy::purge_percent (void) { return this->purge_percent_; } -template ACE_INLINE void -ACE_LFU_Caching_Strategy::purge_percent (double percentage) +template ACE_INLINE void +ACE_LFU_Caching_Strategy::purge_percent (double percentage) { this->purge_percent_ = percentage; } -template ACE_INLINE int -ACE_LFU_Caching_Strategy::notify_bind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LFU_Caching_Strategy::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); - if (result == 0) - ++this->entries_; - return result; } -template ACE_INLINE int -ACE_LFU_Caching_Strategy::notify_find (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LFU_Caching_Strategy::notify_find (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); @@ -249,37 +238,40 @@ ACE_LFU_Caching_Strategy ACE_INLINE int -ACE_LFU_Caching_Strategy::notify_trybind (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LFU_Caching_Strategy::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_LFU_Caching_Strategy::notify_rebind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LFU_Caching_Strategy::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); - if (result == 0) - ++this->entries_; - return result; } -template ACE_INLINE int -ACE_LFU_Caching_Strategy::notify_unbind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_LFU_Caching_Strategy::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE void -ACE_LFU_Caching_Strategy::dump (void) const +template ACE_INLINE CACHING_UTILITY & +ACE_LFU_Caching_Strategy::caching_utility (void) +{ + return this->caching_utility_; +} + +template ACE_INLINE void +ACE_LFU_Caching_Strategy::dump (void) const { ACE_TRACE ("ACE_LFU_Caching_Strategy::dump"); @@ -289,84 +281,83 @@ ACE_LFU_Caching_Strategy ACE_INLINE ATTRIBUTES -ACE_FIFO_Caching_Strategy::attributes (void) +template ACE_INLINE ATTRIBUTES +ACE_FIFO_Caching_Strategy::attributes (void) { return this->order_; } -template ACE_INLINE double -ACE_FIFO_Caching_Strategy::purge_percent (void) +template ACE_INLINE double +ACE_FIFO_Caching_Strategy::purge_percent (void) { return this->purge_percent_; } -template ACE_INLINE void -ACE_FIFO_Caching_Strategy::purge_percent (double percentage) +template ACE_INLINE void +ACE_FIFO_Caching_Strategy::purge_percent (double percentage) { this->purge_percent_ = percentage; } -template ACE_INLINE int -ACE_FIFO_Caching_Strategy::notify_bind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_FIFO_Caching_Strategy::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); if (result == 0) - { - ++this->order_; - ++this->entries_; - } + ++this->order_; return result; } -template ACE_INLINE int -ACE_FIFO_Caching_Strategy::notify_find (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_FIFO_Caching_Strategy::notify_find (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_FIFO_Caching_Strategy::notify_unbind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_FIFO_Caching_Strategy::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_FIFO_Caching_Strategy::notify_trybind (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_FIFO_Caching_Strategy::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_FIFO_Caching_Strategy::notify_rebind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_FIFO_Caching_Strategy::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); if (result == 0) - { - ++this->order_; - ++this->entries_; - } + ++this->order_; return result; } +template ACE_INLINE CACHING_UTILITY & +ACE_FIFO_Caching_Strategy::caching_utility (void) +{ + return this->caching_utility_; +} -template ACE_INLINE void -ACE_FIFO_Caching_Strategy::dump (void) const +template ACE_INLINE void +ACE_FIFO_Caching_Strategy::dump (void) const { ACE_TRACE ("ACE_FIFO_Caching_Strategy::dump"); @@ -377,71 +368,77 @@ ACE_FIFO_Caching_Strategy ACE_INLINE ATTRIBUTES -ACE_Null_Caching_Strategy::attributes (void) +template ACE_INLINE ATTRIBUTES +ACE_Null_Caching_Strategy::attributes (void) { return 0; } -template ACE_INLINE double -ACE_Null_Caching_Strategy::purge_percent (void) +template ACE_INLINE double +ACE_Null_Caching_Strategy::purge_percent (void) { return 0; } -template ACE_INLINE void -ACE_Null_Caching_Strategy::purge_percent (double percentage) +template ACE_INLINE void +ACE_Null_Caching_Strategy::purge_percent (double percentage) { ACE_UNUSED_ARG (percentage); } -template ACE_INLINE int -ACE_Null_Caching_Strategy::notify_bind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Null_Caching_Strategy::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_Null_Caching_Strategy::notify_find (int result, - ATTRIBUTES &attr) + +template ACE_INLINE int +ACE_Null_Caching_Strategy::notify_find (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_Null_Caching_Strategy::notify_unbind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Null_Caching_Strategy::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_Null_Caching_Strategy::notify_trybind (int result, - ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Null_Caching_Strategy::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template ACE_INLINE int -ACE_Null_Caching_Strategy::notify_rebind (int result, - const ATTRIBUTES &attr) +template ACE_INLINE int +ACE_Null_Caching_Strategy::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } +template ACE_INLINE CACHING_UTILITY & +ACE_Null_Caching_Strategy::caching_utility (void) +{ + return this->caching_utility_; +} -template ACE_INLINE void -ACE_Null_Caching_Strategy::dump (void) const +template ACE_INLINE void +ACE_Null_Caching_Strategy::dump (void) const { ACE_TRACE ("ACE_Null_Caching_Strategy::dump"); diff --git a/ace/Caching_Utility_T.cpp b/ace/Caching_Utility_T.cpp index 03a95809c22..47f2b34a362 100644 --- a/ace/Caching_Utility_T.cpp +++ b/ace/Caching_Utility_T.cpp @@ -9,7 +9,6 @@ #define ACE_LACKS_PRAGMA_ONCE #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "ace/Cleanup_Strategies_T.h" #include "ace/Strategies.h" #if !defined (__ACE_INLINE__) @@ -20,9 +19,29 @@ ACE_RCSID(ace, Caching_Utility_T, "$Id$") ///////////////////////////////////////////////////////////////////////////////////////////////////// +template +ACE_Pair_Caching_Utility::ACE_Pair_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy, + int delete_cleanup_strategy) + : cleanup_strategy_ (cleanup_strategy), + delete_cleanup_strategy_ (delete_cleanup_strategy) +{ + if (cleanup_strategy == 0) + { + ACE_NEW (this->cleanup_strategy_, + CLEANUP_STRATEGY); + this->delete_cleanup_strategy_ = 1; + } +} + +template +ACE_Pair_Caching_Utility::~ACE_Pair_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} + template int ACE_Pair_Caching_Utility::clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy *cleanup_s, double purge_percent) { // Check that the purge_percent is non-zero. @@ -57,9 +76,9 @@ ACE_Pair_Caching_Utility::clear_cac if (key_to_remove == 0) return 0; - if (cleanup_s->cleanup (container, - key_to_remove, - value_to_remove) == -1) + if (this->cleanup_strategy_->cleanup (container, + key_to_remove, + value_to_remove) == -1) return -1; } @@ -78,7 +97,7 @@ ACE_Pair_Caching_Utility::minimum ( ATTRIBUTES min = (*iter).int_id_.second (); key_to_remove = &(*iter).ext_id_; value_to_remove = &(*iter).int_id_; - + // The iterator moves thru the container searching for the entry // with the lowest ATTRIBUTES. for (++iter; @@ -96,6 +115,71 @@ ACE_Pair_Caching_Utility::minimum ( } //////////////////////////////////////////////////////////////////////////////////////////////////////// +template +ACE_Recyclable_Handler_Caching_Utility::ACE_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy, + int delete_cleanup_strategy) + : cleanup_strategy_ (cleanup_strategy), + delete_cleanup_strategy_ (delete_cleanup_strategy) +{ + if (cleanup_strategy == 0) + { + ACE_NEW (this->cleanup_strategy_, + CLEANUP_STRATEGY); + this->delete_cleanup_strategy_ = 1; + } +} + +template +ACE_Recyclable_Handler_Caching_Utility::~ACE_Recyclable_Handler_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} + +template int +ACE_Recyclable_Handler_Caching_Utility::clear_cache (CONTAINER &container, + double purge_percent) +{ + // Check that the purge_percent is non-zero. + if (purge_percent == 0) + return 0; + + // Get the number of entries in the container. + size_t current_map_size = container.current_size (); + + // Also whether the number of entries in the cache is just one! + // Oops! then there is no way out but exiting. So return an error. + if (current_map_size <= 1) + return 0; + + // Calculate the no of entries to remove from the cache depending + // upon the . + size_t entries_to_remove = size_t ((double (purge_percent) / 100 * current_map_size) + 0.5); + + KEY *key_to_remove = 0; + VALUE *value_to_remove = 0; + + for (size_t i = 0; i < entries_to_remove ; ++i) + { + this->minimum (container, + key_to_remove, + value_to_remove); + + // Simply verifying that the key is non-zero. + // This is important for strategies where the minimum + // entry cant be found due to constraints on the type of entry + // to remove. + if (key_to_remove == 0) + return 0; + + if (this->cleanup_strategy_->cleanup (container, + key_to_remove, + value_to_remove) == -1) + return -1; + } + + return 0; +} template void ACE_Recyclable_Handler_Caching_Utility::minimum (CONTAINER &container, @@ -119,32 +203,55 @@ ACE_Recyclable_Handler_Caching_Utility entry isnt IDLE_AND_PURGABLE continue until you reach // the first entry which can be purged. This is the minimum with - // which you will compare the rest of the purgable entries. + // which you will compare the rest of the purgable entries. if ((*iter).ext_id_.state () == ACE_Recyclable::IDLE_AND_PURGABLE) { if (found == 0) { min = (*iter).int_id_.second (); + key_to_remove = &(*iter).ext_id_; + value_to_remove = &(*iter).int_id_; found = 1; - } - else + } + else { // Ah! an entry with lower ATTTRIBUTES... if (min > (*iter).int_id_.second ()) - min = (*iter).int_id_.second (); + { + min = (*iter).int_id_.second (); + key_to_remove = &(*iter).ext_id_; + value_to_remove = &(*iter).int_id_; + } } - key_to_remove = &(*iter).ext_id_; - value_to_remove = &(*iter).int_id_; } } } //////////////////////////////////////////////////////////////////////////////// +template +ACE_Handler_Caching_Utility::ACE_Handler_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy, + int delete_cleanup_strategy) + : cleanup_strategy_ (cleanup_strategy), + delete_cleanup_strategy_ (delete_cleanup_strategy) +{ + if (cleanup_strategy == 0) + { + ACE_NEW (this->cleanup_strategy_, + CLEANUP_STRATEGY); + this->delete_cleanup_strategy_ = 1; + } +} + +template +ACE_Handler_Caching_Utility::~ACE_Handler_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} template int ACE_Handler_Caching_Utility::clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy *cleanup_s, double purge_percent) { // Check that the purge_percent is non-zero. @@ -172,9 +279,9 @@ ACE_Handler_Caching_Utility::clear_ key_to_remove, value_to_remove); - if (cleanup_s->cleanup (container, - key_to_remove, - value_to_remove) == -1) + if (this->cleanup_strategy_->cleanup (container, + key_to_remove, + value_to_remove) == -1) return -1; } @@ -212,13 +319,32 @@ ACE_Handler_Caching_Utility::minimu //////////////////////////////////////////////////////////////////////////////////////////////////////// +template +ACE_Null_Caching_Utility::ACE_Null_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy, + int delete_cleanup_strategy) + : cleanup_strategy_ (cleanup_strategy), + delete_cleanup_strategy_ (delete_cleanup_strategy) +{ + if (cleanup_strategy == 0) + { + ACE_NEW (this->cleanup_strategy_, + CLEANUP_STRATEGY); + this->delete_cleanup_strategy_ = 1; + } +} + +template +ACE_Null_Caching_Utility::~ACE_Null_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} + template int ACE_Null_Caching_Utility::clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy *cleanup_s, double purge_percent) { ACE_UNUSED_ARG (container); - ACE_UNUSED_ARG (cleanup_s); ACE_UNUSED_ARG (purge_percent); return 0; diff --git a/ace/Caching_Utility_T.h b/ace/Caching_Utility_T.h index 542aabff285..966bca32b9f 100644 --- a/ace/Caching_Utility_T.h +++ b/ace/Caching_Utility_T.h @@ -23,9 +23,7 @@ #define ACE_LACKS_PRAGMA_ONCE #endif /* ACE_LACKS_PRAGMA_ONCE */ -// Forward declaration -template -class ACE_Cleanup_Strategy; +#include "ace/Cleanup_Strategies_T.h" template class ACE_Pair_Caching_Utility @@ -34,34 +32,52 @@ class ACE_Pair_Caching_Utility // Defines a helper class for the Caching Strategies. // // = DESCRIPTION - // This class defines the methods commonly used by the - // different caching strategies. For instance: clear_cache () - // method which decides and purges the entry from the container. - // Note: This class helps in the caching_strategies using a - // container containing entries of > kind. The attributes helps in deciding the - // entries to be purged. + // This class defines the methods commonly used by the different + // caching strategies. For instance: clear_cache () method which + // decides and purges the entry from the container. Note: This + // class helps in the caching_strategies using a container + // containing entries of > + // kind. The attributes helps in deciding the entries to be + // purged. The Cleanup_Strategy is the callback class to which + // the entries to be cleaned up will be delegated. public: + typedef ACE_Cleanup_Strategy CLEANUP_STRATEGY; + + ACE_Pair_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + + // Constructor. + + ~ACE_Pair_Caching_Utility (void); + // Destructor. + int clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy *cleanup_s, double purge_percent); + // Purge entries from the . The Cleanup_Strategy will do // the actual job of cleanup once the entries to be cleaned up are // decided. protected: - virtual void minimum (CONTAINER &container, - KEY *&key_to_remove, - VALUE *&value_to_remove); + void minimum (CONTAINER &container, + KEY *&key_to_remove, + VALUE *&value_to_remove); // Find the entry with minimum caching attributes. + + CLEANUP_STRATEGY *cleanup_strategy_; + // The cleanup strategy which can be used to destroy the entries of + // the container. + + int delete_cleanup_strategy_; + // Whether the cleanup_strategy should be destroyed or not. }; //////////////////////////////////////////////////////////////////////////////// template -class ACE_Recyclable_Handler_Caching_Utility : public ACE_Pair_Caching_Utility +class ACE_Recyclable_Handler_Caching_Utility { // = TITLE // Defines a helper class for the Caching Strategies. @@ -72,13 +88,42 @@ class ACE_Recyclable_Handler_Caching_Utility : public ACE_Pair_Caching_Utility kind. The attributes - // helps in deciding the entries to be purged. + // helps in deciding the entries to be purged. The + // Cleanup_Strategy is the callback class to which the entries to + // be cleaned up will be delegated. + +public: + + typedef ACE_Recyclable_Handler_Cleanup_Strategy CLEANUP_STRATEGY; + typedef ACE_Cleanup_Strategy CLEANUP_STRATEGY_BASE; + + ACE_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + + // Constructor. + + ~ACE_Recyclable_Handler_Caching_Utility (void); + // Destructor. + + int clear_cache (CONTAINER &container, + double purge_percent); + // Purge entries from the . The Cleanup_Strategy will do + // the actual job of cleanup once the entries to be cleaned up are + // decided. + protected: - virtual void minimum (CONTAINER &container, - KEY *&key_to_remove, - VALUE *&value_to_remove); + void minimum (CONTAINER &container, + KEY *&key_to_remove, + VALUE *&value_to_remove); // Find the entry with minimum caching attributes. + + CLEANUP_STRATEGY_BASE *cleanup_strategy_; + // This is the default Cleanup Strategy for this utility. + + int delete_cleanup_strategy_; + // Whether the cleanup_strategy should be destroyed or not. + }; //////////////////////////////////////////////////////////////////////////////////////// @@ -90,17 +135,27 @@ class ACE_Handler_Caching_Utility // Defines a helper class for the Caching Strategies. // // = DESCRIPTION - // This class defines the methods commonly used by the - // different caching strategies. For instance: clear_cache () - // method which decides and purges the entry from the container. - // Note: This class helps in the caching_strategies using a - // container containing entries of kind where the - // HANDLER contains the caching attributes which help in deciding - // the entries to be purged. + // This class defines the methods commonly used by the different + // caching strategies. For instance: clear_cache () method which + // decides and purges the entry from the container. Note: This + // class helps in the caching_strategies using a container + // containing entries of kind where the HANDLER + // contains the caching attributes which help in deciding the + // entries to be purged. The Cleanup_Strategy is the callback + // class to which the entries to be cleaned up will be delegated. public: + typedef ACE_Handler_Cleanup_Strategy CLEANUP_STRATEGY; + typedef ACE_Cleanup_Strategy CLEANUP_STRATEGY_BASE; + + ACE_Handler_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + // Constructor. + + ~ACE_Handler_Caching_Utility (void); + // Destructor. + int clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy *cleanup_s, double purge_percent); // Purge entries from the . The Cleanup_Strategy will do // the actual job of cleanup once the entries to be cleaned up are @@ -108,32 +163,51 @@ public: protected: - virtual void minimum (CONTAINER &container, - KEY *&key_to_remove, - VALUE *&value_to_remove); + void minimum (CONTAINER &container, + KEY *&key_to_remove, + VALUE *&value_to_remove); // Find the entry with minimum caching attributes. This is handler // specific since this utility is to be used very specifically for // handler who have caching_attributes for server side acched // connection management. + + CLEANUP_STRATEGY_BASE *cleanup_strategy_; + // The cleanup strategy which can be used to destroy the entries of + // the container. + + int delete_cleanup_strategy_; + // Whether the cleanup_strategy should be destroyed or not. + }; /////////////////////////////////////////////////////////////////////////// -template +template class ACE_Null_Caching_Utility { // = TITLE // Defines a dummy helper class for the Caching Strategies. // // = DESCRIPTION - // This class defines the methods commonly used by the - // different caching strategies. For instance: clear_cache () - // method which decides and purges the entry from the container. - // Note: This class is be used with the Null_Caching_Strategy. + // This class defines the methods commonly used by the different + // caching strategies. For instance: clear_cache () method which + // decides and purges the entry from the container. Note: This + // class is be used with the Null_Caching_Strategy. The + // Cleanup_Strategy is the callback class to which the entries to + // be cleaned up will be delegated. public: + typedef ACE_Null_Cleanup_Strategy CLEANUP_STRATEGY; + typedef ACE_Cleanup_Strategy CLEANUP_STRATEGY_BASE; + + ACE_Null_Caching_Utility (ACE_Cleanup_Strategy *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + // Constructor. + + ~ACE_Null_Caching_Utility (void); + // Destructor. + int clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy *cleanup_s, double purge_percent); // Purge entries from the . The Cleanup_Strategy will do // the actual job of cleanup once the entries to be cleaned up are @@ -141,13 +215,20 @@ public: protected: - virtual void minimum (CONTAINER &container, - KEY *&key_to_remove, - VALUE *&value_to_remove); + void minimum (CONTAINER &container, + KEY *&key_to_remove, + VALUE *&value_to_remove); // Find the entry with minimum caching attributes. This is handler // specific since this utility is to be used very specifically for // handler who have caching_attributes for server side acched // connection management.Note: Here it is a no-op. + + CLEANUP_STRATEGY_BASE *cleanup_strategy_; + // The cleanup strategy which can be used to destroy the entries of + // the container. + + int delete_cleanup_strategy_; + // Whether the cleanup_strategy should be destroyed or not. }; /////////////////////////////////////////////////////////////////////////// diff --git a/ace/Cleanup_Strategies_T.cpp b/ace/Cleanup_Strategies_T.cpp index b54db63adf3..31be58692a0 100644 --- a/ace/Cleanup_Strategies_T.cpp +++ b/ace/Cleanup_Strategies_T.cpp @@ -17,17 +17,12 @@ ACE_RCSID(ace, Cleanup_Strategies_T, "$Id$") -template -ACE_Cleanup_Strategy::~ACE_Cleanup_Strategy (void) -{ -} - //////////////////////////////////////////////////////////////////////////// template int -ACE_Default_Cleanup_Strategy::cleanup (CONTAINER &container, - KEY *key, - VALUE *value) +ACE_Cleanup_Strategy::cleanup (CONTAINER &container, + KEY *key, + VALUE *value) { ACE_UNUSED_ARG (value); @@ -37,24 +32,25 @@ ACE_Default_Cleanup_Strategy::cleanup (CONTAINER &contain //////////////////////////////////////////////////////////////////////////// template int -ACE_Svc_Cleanup_Strategy::cleanup (CONTAINER &container, - KEY *key, +ACE_Recyclable_Handler_Cleanup_Strategy::cleanup (CONTAINER &container, + KEY *key, VALUE *value) { - (value->first ())->recycler (0, 0); + value->first ()->recycler (0, 0); + + value->first ()->close (); - (value->first ())->close (); - if (container.unbind (*key) == -1) return -1; - - return 0; + + return 0; } ///////////////////////////////////////////////////////////////////////////// + template int -ACE_Handler_Cleanup_Strategy::cleanup (CONTAINER &container, - KEY *key, +ACE_Handler_Cleanup_Strategy::cleanup (CONTAINER &container, + KEY *key, VALUE *value) { // Remove the item from cache only if the handler isnt in use. @@ -68,16 +64,15 @@ ACE_Handler_Cleanup_Strategy::cleanup (CONTAINER &contain } return 0; - } //////////////////////////////////////////////////////////////////////////// + template int -ACE_Null_Cleanup_Strategy::cleanup (CONTAINER &container, - KEY *key, +ACE_Null_Cleanup_Strategy::cleanup (CONTAINER &container, + KEY *key, VALUE *value) { - ACE_UNUSED_ARG (container); ACE_UNUSED_ARG (key); ACE_UNUSED_ARG (value); diff --git a/ace/Cleanup_Strategies_T.h b/ace/Cleanup_Strategies_T.h index 6c266ffc1c5..15c615a9d09 100644 --- a/ace/Cleanup_Strategies_T.h +++ b/ace/Cleanup_Strategies_T.h @@ -25,53 +25,25 @@ template class ACE_Cleanup_Strategy -{ - // = TITLE - // Defines a abstract base class which takes care of winding up - // and destroying the entries in the container. - // - // = DESCRIPTION - // This class is one of the ways to ensure that the cleanup - // can be decoupled from other strategies which need to do it. - // The cleanup method provided needs to be implemented as needed. - - public: - - // = Termination. - - virtual ~ACE_Cleanup_Strategy (void); - - // = The cleanup operation. - - virtual int cleanup (CONTAINER &container, KEY *key, VALUE *value) = 0; - // This pure virtual method is to be used to destroy the entry. - -}; - -////////////////////////////////////////////////////////////////////////// - -template -class ACE_Default_Cleanup_Strategy : public ACE_Cleanup_Strategy { // = TITLE // Defines a default strategy to be followed for cleaning up // entries from a map which is the container. // // = DESCRIPTION - // By defualt the entry to be cleaned up is removed from the + // By default the entry to be cleaned up is removed from the // container. public: - + virtual int cleanup (CONTAINER &container, KEY *key, VALUE *value); // The method which will do the cleanup of the entry in the container. - }; ////////////////////////////////////////////////////////////////////// + template -class ACE_Svc_Cleanup_Strategy : public ACE_Cleanup_Strategy +class ACE_Recyclable_Handler_Cleanup_Strategy : public ACE_Cleanup_Strategy { // = TITLE // Defines a strategy to be followed for cleaning up @@ -84,19 +56,19 @@ class ACE_Svc_Cleanup_Strategy : public ACE_Cleanup_Strategy class ACE_Handler_Cleanup_Strategy : public ACE_Cleanup_Strategy { // = TITLE // Defines a strategy to be followed for cleaning up - // entries which are svc_handlers from a container. + // entries which are svc_handlers from a container. // // = DESCRIPTION // The entry to be cleaned up is removed from the container. @@ -106,15 +78,13 @@ class ACE_Handler_Cleanup_Strategy : public ACE_Cleanup_Strategy class ACE_Null_Cleanup_Strategy : public ACE_Cleanup_Strategy { @@ -126,10 +96,9 @@ class ACE_Null_Cleanup_Strategy : public ACE_Cleanup_Strategy +template ACE_Hash_Cache_Map_Manager::ACE_Hash_Cache_Map_Manager (CACHING_STRATEGY &caching_s, size_t size, ACE_Allocator *alloc) diff --git a/ace/Hash_Cache_Map_Manager_T.h b/ace/Hash_Cache_Map_Manager_T.h index cae1929c0c9..27391876765 100644 --- a/ace/Hash_Cache_Map_Manager_T.h +++ b/ace/Hash_Cache_Map_Manager_T.h @@ -27,12 +27,26 @@ // Forward declaration. class ACE_Allocator; +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) +#define ACE_CACHE_MAP_MANAGER \ + ACE_Cache_Map_Manager, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + ACE_Hash_Map_Iterator_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + ACE_Hash_Map_Reverse_Iterator_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + CACHING_STRATEGY, \ + ATTRIBUTES> +#else +#define ACE_CACHE_MAP_MANAGER \ + ACE_Cache_Map_Manager, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + CACHING_STRATEGY, \ + ATTRIBUTES> +#endif (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + template -class ACE_Hash_Cache_Map_Manager : public ACE_Cache_Map_Manager< KEY, VALUE, - ACE_Hash_Map_Manager_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Iterator_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Reverse_Iterator_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - CACHING_STRATEGY, ATTRIBUTES> +class ACE_Hash_Cache_Map_Manager : public ACE_CACHE_MAP_MANAGER { // = TITLE // Defines a abstraction which will purge entries from a map. @@ -160,12 +174,7 @@ class ACE_Hash_Cache_Map_Manager : public ACE_Cache_Map_Manager< KEY, VALUE, protected: - typedef ACE_Cache_Map_Manager, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Iterator_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Reverse_Iterator_Ex, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - CACHING_STRATEGY, ATTRIBUTES> - ACE_HCMM_BASE; + typedef ACE_CACHE_MAP_MANAGER ACE_HCMM_BASE; // Base class. }; -- cgit v1.2.1