diff options
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Cache_Map_Manager_T.cpp | 99 | ||||
-rw-r--r-- | ace/Cache_Map_Manager_T.h | 43 | ||||
-rw-r--r-- | ace/Cache_Map_Manager_T.i | 216 | ||||
-rw-r--r-- | ace/Cached_Connect_Strategy_T.cpp | 52 | ||||
-rw-r--r-- | ace/Cached_Connect_Strategy_T.h | 18 | ||||
-rw-r--r-- | ace/Caching_Strategies_T.cpp | 350 | ||||
-rw-r--r-- | ace/Caching_Strategies_T.h | 240 | ||||
-rw-r--r-- | ace/Caching_Strategies_T.i | 317 | ||||
-rw-r--r-- | ace/Caching_Utility_T.cpp | 162 | ||||
-rw-r--r-- | ace/Caching_Utility_T.h | 159 | ||||
-rw-r--r-- | ace/Cleanup_Strategies_T.cpp | 37 | ||||
-rw-r--r-- | ace/Cleanup_Strategies_T.h | 49 | ||||
-rw-r--r-- | ace/Hash_Cache_Map_Manager_T.cpp | 2 | ||||
-rw-r--r-- | ace/Hash_Cache_Map_Manager_T.h | 31 |
14 files changed, 752 insertions, 1023 deletions
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 <T_1> -ACE_Cache_Map_Manager<T_2>::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s, - size_t size, - ACE_Allocator *alloc) +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +template <ACE_T1> +ACE_Cache_Map_Manager<ACE_T2>::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<T_2>::ACE_Cache_Map_Manager (CACHING_STRATEGY &caching_s, } -template <T_1> -ACE_Cache_Map_Manager<T_2>::~ACE_Cache_Map_Manager (void) +template <ACE_T1> +ACE_Cache_Map_Manager<ACE_T2>::~ACE_Cache_Map_Manager (void) { this->close (); } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::open (size_t length, - ACE_Allocator *alloc) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::open (size_t length, + ACE_Allocator *alloc) { return this->map_.open (length, alloc); } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::close (void) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::close (void) { return this->map_.close (); } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::bind (const KEY &key, - const VALUE &value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::bind (const KEY &key, + const VALUE &value) { // Insert an entry which has the <key> and the <cache_value> which // is the combination of the <value> and the attributes of the @@ -97,9 +106,9 @@ ACE_Cache_Map_Manager<T_2>::bind (const KEY &key, } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key, - const VALUE &value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::rebind (const KEY &key, + const VALUE &value) { CACHE_VALUE cache_value (value, this->caching_strategy_.attributes ()); @@ -134,10 +143,10 @@ ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key, } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key, - const VALUE &value, - VALUE &old_value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::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<T_2>::rebind (const KEY &key, return rebind_result; } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::rebind (const KEY &key, - const VALUE &value, - KEY &old_key, - VALUE &old_value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::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<T_2>::rebind (const KEY &key, return rebind_result; } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::trybind (const KEY &key, - VALUE &value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::trybind (const KEY &key, + VALUE &value) { CACHE_VALUE cache_value (value, this->caching_strategy_.attributes ()); @@ -272,9 +281,9 @@ ACE_Cache_Map_Manager<T_2>::trybind (const KEY &key, return trybind_result; } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::find (const KEY &key, - VALUE &value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::find (const KEY &key, + VALUE &value) { // Lookup the key and populate the <value>. CACHE_VALUE cache_value; @@ -311,8 +320,8 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key, return find_result; } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::find (const KEY &key) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::find (const KEY &key) { // Lookup the key and populate the <value>. CACHE_VALUE cache_value; @@ -349,8 +358,8 @@ ACE_Cache_Map_Manager<T_2>::find (const KEY &key) } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::unbind (const KEY &key) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::unbind (const KEY &key) { // Remove the entry from the cache. CACHE_VALUE cache_value; @@ -372,9 +381,9 @@ ACE_Cache_Map_Manager<T_2>::unbind (const KEY &key) return unbind_result; } -template <T_1> int -ACE_Cache_Map_Manager<T_2>::unbind (const KEY &key, - VALUE &value) +template <ACE_T1> int +ACE_Cache_Map_Manager<ACE_T2>::unbind (const KEY &key, + VALUE &value) { // Remove the entry from the cache. CACHE_VALUE cache_value; @@ -399,15 +408,15 @@ ACE_Cache_Map_Manager<T_2>::unbind (const KEY &key, } -template <T_1> void -ACE_Cache_Map_Manager<T_2>::dump (void) const +template <ACE_T1> void +ACE_Cache_Map_Manager<ACE_T2>::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 KEY, class VALUE, class IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES> class ACE_Cache_Map_Iterator; template <class KEY, class VALUE, class REVERSE_IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES> class ACE_Cache_Map_Reverse_Iterator; -template <class KEY, class VALUE, class MAP, class ITERATOR_IMPL, class REVERSE_ITERATOR_IMPL, class CACHING_STRATEGY, class 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 + +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + +template <ACE_T1> 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<VALUE, ATTRIBUTES> CACHE_VALUE; - // The actual value mapped to the key in the map. The <attributes> - // are used by the strategy and is transparent to the user of this - // class. friend class ACE_Cache_Map_Iterator<KEY, VALUE, ITERATOR_IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES>; friend class ACE_Cache_Map_Reverse_Iterator<KEY, VALUE, REVERSE_ITERATOR_IMPLEMENTATION, CACHING_STRATEGY, ATTRIBUTES>; @@ -80,6 +91,13 @@ public: typedef REVERSE_ITERATOR reverse_iterator; +#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */ + + typedef ACE_Pair<VALUE, ATTRIBUTES> CACHE_VALUE; + // The actual value mapped to the key in the map. The <attributes> + // 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<KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> &)) - ACE_UNIMPLEMENTED_FUNC (ACE_Cache_Map_Manager (const ACE_Cache_Map_Manager<KEY, VALUE, MAP, ITERATOR_IMPL, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> &)) + ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Cache_Map_Manager<ACE_T2> &)) + ACE_UNIMPLEMENTED_FUNC (ACE_Cache_Map_Manager (const ACE_Cache_Map_Manager<ACE_T2> &)) }; +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + template <class KEY, class VALUE, class IMPLEMENTATION, class CACHING_STRATEGY, class ATTRIBUTES> 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 <T_1> ACE_INLINE int -ACE_Cache_Map_Manager<T_2>::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_T1> ACE_INLINE int +ACE_Cache_Map_Manager<ACE_T2>::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 <T_1> ACE_INLINE size_t -ACE_Cache_Map_Manager<T_2>::current_size (void) const +template <ACE_T1> ACE_INLINE size_t +ACE_Cache_Map_Manager<ACE_T2>::current_size (void) const { return this->map_.current_size (); } -template <T_1> ACE_INLINE size_t -ACE_Cache_Map_Manager<T_2>::total_size (void) const +template <ACE_T1> ACE_INLINE size_t +ACE_Cache_Map_Manager<ACE_T2>::total_size (void) const { return this->map_.total_size (); } -template <T_1> ACE_INLINE MAP & -ACE_Cache_Map_Manager<T_2>::map (void) +template <ACE_T1> ACE_INLINE MAP & +ACE_Cache_Map_Manager<ACE_T2>::map (void) { return this->map_; } -template <T_1> ACE_INLINE CACHING_STRATEGY & -ACE_Cache_Map_Manager<T_2>::caching_strategy (void) +template <ACE_T1> ACE_INLINE CACHING_STRATEGY & +ACE_Cache_Map_Manager<ACE_T2>::caching_strategy (void) { return this->caching_strategy_; } -template <T_1> ACE_INLINE ACE_Cache_Map_Iterator<KEY, VALUE, ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> -ACE_Cache_Map_Manager<T_2>::begin (void) +#if !defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + +template <ACE_T1> ACE_INLINE ACE_Cache_Map_Iterator<KEY, VALUE, ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> +ACE_Cache_Map_Manager<ACE_T2>::begin (void) { return ITERATOR (this->map_.begin ()); } -template <T_1> ACE_INLINE ACE_Cache_Map_Iterator<KEY, VALUE, ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> -ACE_Cache_Map_Manager<T_2>::end (void) +template <ACE_T1> ACE_INLINE ACE_Cache_Map_Iterator<KEY, VALUE, ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> +ACE_Cache_Map_Manager<ACE_T2>::end (void) { return ITERATOR (this->map_.end ()); } -template <T_1> ACE_INLINE ACE_Cache_Map_Reverse_Iterator<KEY, VALUE, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> -ACE_Cache_Map_Manager<T_2>::rbegin (void) +template <ACE_T1> ACE_INLINE ACE_Cache_Map_Reverse_Iterator<KEY, VALUE, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> +ACE_Cache_Map_Manager<ACE_T2>::rbegin (void) { return REVERSE_ITERATOR (this->map_.rbegin ()); } -template <T_1> ACE_INLINE ACE_Cache_Map_Reverse_Iterator<KEY, VALUE, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> -ACE_Cache_Map_Manager<T_2>::rend (void) +template <ACE_T1> ACE_INLINE ACE_Cache_Map_Reverse_Iterator<KEY, VALUE, REVERSE_ITERATOR_IMPL, CACHING_STRATEGY, ATTRIBUTES> +ACE_Cache_Map_Manager<ACE_T2>::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 <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2>::ACE_Cache_Map_Iterator (const ACE_Cache_Map_Iterator <T_2> &rhs) - : iterator_implementation_ (rhs.iterator_implementation_) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2>::ACE_Cache_Map_Iterator (const ACE_Cache_Map_Iterator <ACE_T2> &rhs) + : iterator_implementation_ (rhs.iterator_implementation_) { } -template <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2>::~ACE_Cache_Map_Iterator (void) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2>::~ACE_Cache_Map_Iterator (void) { } -template <T_1> ACE_INLINE ACE_Cache_Map_Iterator<T_2> & -ACE_Cache_Map_Iterator<T_2>::operator= (const ACE_Cache_Map_Iterator<T_2> &rhs) +template <ACE_T1> ACE_INLINE ACE_Cache_Map_Iterator<ACE_T2> & +ACE_Cache_Map_Iterator<ACE_T2>::operator= (const ACE_Cache_Map_Iterator<ACE_T2> &rhs) { this->iterator_implementation_ = rhs.iterator_implementation_; return *this; } -template <T_1> ACE_INLINE int -ACE_Cache_Map_Iterator<T_2>::operator== (const ACE_Cache_Map_Iterator<T_2> &rhs) const +template <ACE_T1> ACE_INLINE int +ACE_Cache_Map_Iterator<ACE_T2>::operator== (const ACE_Cache_Map_Iterator<ACE_T2> &rhs) const { return this->iterator_implementation_ == rhs.iterator_implementation_; } -template <T_1> ACE_INLINE int -ACE_Cache_Map_Iterator<T_2>::operator!= (const ACE_Cache_Map_Iterator<T_2> &rhs) const +template <ACE_T1> ACE_INLINE int +ACE_Cache_Map_Iterator<ACE_T2>::operator!= (const ACE_Cache_Map_Iterator<ACE_T2> &rhs) const { return this->iterator_implementation_ != rhs.iterator_implementation_; } -template <T_1> ACE_INLINE ACE_Reference_Pair<KEY, VALUE> -ACE_Cache_Map_Iterator<T_2>::operator* (void) const +template <ACE_T1> ACE_INLINE ACE_Reference_Pair<KEY, VALUE> +ACE_Cache_Map_Iterator<ACE_T2>::operator* (void) const { value_type retn ((*this->iterator_implementation_).ext_id_, (*this->iterator_implementation_).int_id_.first ()); return retn; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2> & -ACE_Cache_Map_Iterator<T_2>::operator++ (void) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2> & +ACE_Cache_Map_Iterator<ACE_T2>::operator++ (void) { ++this->iterator_implementation_; return *this; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2> -ACE_Cache_Map_Iterator<T_2>::operator++ (int) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2> +ACE_Cache_Map_Iterator<ACE_T2>::operator++ (int) { - ACE_Cache_Map_Iterator<T_2> retn = *this; + ACE_Cache_Map_Iterator<ACE_T2> retn = *this; ++this->iterator_implementation_; return retn; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2> & -ACE_Cache_Map_Iterator<T_2>::operator-- (void) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2> & +ACE_Cache_Map_Iterator<ACE_T2>::operator-- (void) { --this->iterator_implementation_; return *this; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2> -ACE_Cache_Map_Iterator<T_2>::operator-- (int) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2> +ACE_Cache_Map_Iterator<ACE_T2>::operator-- (int) { - ACE_Cache_Map_Iterator<T_2> retn = *this; + ACE_Cache_Map_Iterator<ACE_T2> retn = *this; --this->iterator_implementation_; return retn; } -template <T_1> ACE_INLINE void -ACE_Cache_Map_Iterator<T_2>::dump (void) const +template <ACE_T1> ACE_INLINE void +ACE_Cache_Map_Iterator<ACE_T2>::dump (void) const { this->iterator_implementation_.dump (); } -template <T_1> ACE_INLINE -ACE_Cache_Map_Iterator<T_2>::ACE_Cache_Map_Iterator (const IMPLEMENTATION &iterator_impl) - : iterator_implementation_ (iterator_impl) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Iterator<ACE_T2>::ACE_Cache_Map_Iterator (const IMPLEMENTATION &iterator_impl) + : iterator_implementation_ (iterator_impl) { } -template <T_1> ACE_INLINE IMPLEMENTATION & -ACE_Cache_Map_Iterator<T_2>::iterator_implementation (void) +template <ACE_T1> ACE_INLINE IMPLEMENTATION & +ACE_Cache_Map_Iterator<ACE_T2>::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 <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2>::ACE_Cache_Map_Reverse_Iterator (const ACE_Cache_Map_Reverse_Iterator <T_2> &rhs) - : reverse_iterator_implementation_ (rhs.reverse_iterator_implementation_) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::ACE_Cache_Map_Reverse_Iterator (const ACE_Cache_Map_Reverse_Iterator <ACE_T2> &rhs) + : reverse_iterator_implementation_ (rhs.reverse_iterator_implementation_) { } -template <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2>::~ACE_Cache_Map_Reverse_Iterator (void) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::~ACE_Cache_Map_Reverse_Iterator (void) { } -template <T_1> ACE_INLINE ACE_Cache_Map_Reverse_Iterator<T_2> & -ACE_Cache_Map_Reverse_Iterator<T_2>::operator= (const ACE_Cache_Map_Reverse_Iterator<T_2> &rhs) +template <ACE_T1> ACE_INLINE ACE_Cache_Map_Reverse_Iterator<ACE_T2> & +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator= (const ACE_Cache_Map_Reverse_Iterator<ACE_T2> &rhs) { this->reverse_iterator_implementation_ = rhs.reverse_iterator_implementation_; return *this; } -template <T_1> ACE_INLINE int -ACE_Cache_Map_Reverse_Iterator<T_2>::operator== (const ACE_Cache_Map_Reverse_Iterator<T_2> &rhs) const +template <ACE_T1> ACE_INLINE int +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator== (const ACE_Cache_Map_Reverse_Iterator<ACE_T2> &rhs) const { return this->reverse_iterator_implementation_ == rhs.reverse_iterator_implementation_; } -template <T_1> ACE_INLINE int -ACE_Cache_Map_Reverse_Iterator<T_2>::operator!= (const ACE_Cache_Map_Reverse_Iterator<T_2> &rhs) const +template <ACE_T1> ACE_INLINE int +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator!= (const ACE_Cache_Map_Reverse_Iterator<ACE_T2> &rhs) const { return this->reverse_iterator_implementation_ != rhs.reverse_iterator_implementation_; } -template <T_1> ACE_INLINE ACE_Reference_Pair<KEY, VALUE> -ACE_Cache_Map_Reverse_Iterator<T_2>::operator* (void) const +template <ACE_T1> ACE_INLINE ACE_Reference_Pair<KEY, VALUE> +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator* (void) const { value_type retv ((*this->reverse_iterator_implementation_).ext_id_, (*this->reverse_iterator_implementation_).int_id_.first ()); return retv; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2> & -ACE_Cache_Map_Reverse_Iterator<T_2>::operator++ (void) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2> & +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator++ (void) { ++this->reverse_iterator_implementation_; return *this; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2> -ACE_Cache_Map_Reverse_Iterator<T_2>::operator++ (int) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2> +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator++ (int) { - ACE_Cache_Map_Reverse_Iterator<T_2> retn = *this; + ACE_Cache_Map_Reverse_Iterator<ACE_T2> retn = *this; ++this->reverse_iterator_implementation_; return retn; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2> & -ACE_Cache_Map_Reverse_Iterator<T_2>::operator-- (void) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2> & +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator-- (void) { --this->reverse_iterator_implementation_; return *this; } -template <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2> -ACE_Cache_Map_Reverse_Iterator<T_2>::operator-- (int) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2> +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::operator-- (int) { - ACE_Cache_Map_Reverse_Iterator<T_2> retn = *this; + ACE_Cache_Map_Reverse_Iterator<ACE_T2> retn = *this; --this->reverse_iterator_implementation_; return retn; } -template <T_1> ACE_INLINE void -ACE_Cache_Map_Reverse_Iterator<T_2>::dump (void) const +template <ACE_T1> ACE_INLINE void +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::dump (void) const { this->reverse_iterator_implementation_.dump (); } -template <T_1> ACE_INLINE -ACE_Cache_Map_Reverse_Iterator<T_2>::ACE_Cache_Map_Reverse_Iterator (const REVERSE_IMPLEMENTATION &iterator_impl) - : reverse_iterator_implementation_(iterator_impl) +template <ACE_T1> ACE_INLINE +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::ACE_Cache_Map_Reverse_Iterator (const REVERSE_IMPLEMENTATION &iterator_impl) + : reverse_iterator_implementation_(iterator_impl) { } -template <T_1> ACE_INLINE REVERSE_IMPLEMENTATION & -ACE_Cache_Map_Reverse_Iterator<T_2>::iterator_implementation (void) +template <ACE_T1> ACE_INLINE REVERSE_IMPLEMENTATION & +ACE_Cache_Map_Reverse_Iterator<ACE_T2>::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 <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> + template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::ACE_Cached_Connect_Strategy_Ex (CACHING_STRATEGY &caching_s, ACE_Creation_Strategy<SVC_HANDLER> *cre_s, @@ -45,8 +45,9 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::~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_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE (*iter).second ()->close (); } } -} - -template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::open -(ACE_Creation_Strategy<SVC_HANDLER> *cre_s, - ACE_Concurrency_Strategy<SVC_HANDLER> *con_s, - ACE_Recycling_Strategy<SVC_HANDLER> *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 <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int @@ -178,12 +160,12 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE // Connect using the svc_handler. if (this->cached_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<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::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<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE if (errno == EWOULDBLOCK) errno = ENOTSUP; - else if (errno == EMFILE) + else if (errno == EMFILE || errno == ENOBUFS || errno == ENOENT) { // If the connect failed due to the process running out of // file descriptors then, auto_purging of some connections diff --git a/ace/Cached_Connect_Strategy_T.h b/ace/Cached_Connect_Strategy_T.h index 59f070c9a46..23f49c63cab 100644 --- a/ace/Cached_Connect_Strategy_T.h +++ b/ace/Cached_Connect_Strategy_T.h @@ -57,12 +57,6 @@ public: virtual ~ACE_Cached_Connect_Strategy_Ex (void); // Destructor - virtual int open (ACE_Creation_Strategy<SVC_HANDLER> *cre_s, - ACE_Concurrency_Strategy<SVC_HANDLER> *con_s, - ACE_Recycling_Strategy<SVC_HANDLER> *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<ACE_PEER_CONNECTOR_ADDR> REFCOUNTED_HASH_RECYCLABLE_ADDRESS; - typedef ACE_Hash_Cache_Map_Manager<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Hash<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>,ACE_Equal_To<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, CACHING_STRATEGY, ATTRIBUTES> + typedef ACE_Hash_Cache_Map_Manager<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Hash<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, ACE_Equal_To<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, 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<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, ACE_Pair<SVC_HANDLER *, ATTRIBUTES>,ACE_Hash_Map_Manager_Ex<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, ACE_Pair<SVC_HANDLER *, ATTRIBUTES>, ACE_Hash<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, ACE_Equal_To<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, MUTEX> > - SVC_CLEANUP_STRATEGY; + typedef ACE_Recyclable_Handler_Cleanup_Strategy<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, ACE_Pair<SVC_HANDLER *, ATTRIBUTES>,ACE_Hash_Map_Manager_Ex<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, ACE_Pair<SVC_HANDLER *, ATTRIBUTES>, ACE_Hash<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, ACE_Equal_To<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, MUTEX> > + CLEANUP_STRATEGY; typedef ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX> CCSBASE; @@ -153,10 +145,6 @@ protected: CONNECTION_CACHE connection_cache_; // Table that maintains the cache of connected <SVC_HANDLER>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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::~ACE_Caching_Strategy (void) +template<class ATTRIBUTES, class CACHING_UTILITY> +ACE_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::~ACE_Caching_Strategy (void) { } ////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::ACE_LRU_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) +template<class ATTRIBUTES, class CACHING_UTILITY> +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::~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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::clear_cache (CONTAINER &container) -{ - return this->caching_strategy_utility_->clear_cache (container, - this->cleanup_strategy_, - this->purge_percent_); } //////////////////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::ACE_LFU_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::~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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::clear_cache (CONTAINER &container) +template<class ATTRIBUTES, class CACHING_UTILITY> +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::ACE_LFU_Caching_Strategy (void) + : purge_percent_ (10) { - return this->caching_strategy_utility_->clear_cache (container, - this->cleanup_strategy_, - this->purge_percent_); } - //////////////////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::ACE_FIFO_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, - int delete_cleanup_strategy, - CACHING_STRATEGY_UTILITY *utility_s, - int delete_caching_strategy_utility) +template<class ATTRIBUTES, class CACHING_UTILITY> +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::~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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::clear_cache (CONTAINER &container) -{ - return this->caching_strategy_utility_->clear_cache (container, - this->cleanup_strategy_, - this->purge_percent_); } //////////////////////////////////////////////////////////////////////////////////////////////// - -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::ACE_Null_Caching_Strategy (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::~ACE_Null_Caching_Strategy (void) -{ -} - -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::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 <class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template <class ATTRIBUTES, class CACHING_UTILITY> class ACE_Caching_Strategy { // = TITLE @@ -42,12 +44,6 @@ public: virtual ~ACE_Caching_Strategy (void); // Destructor. - virtual int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> -class ACE_Caching_Strategy_Adapter : public ACE_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY> +template <class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> +class ACE_Caching_Strategy_Adapter : public ACE_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY> { // = 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<KEY, VALUE, CONTAINER> *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 <class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template <class ATTRIBUTES, class CACHING_UTILITY> 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<x, ATTRIBUTES>. The CACHING_STRATEGY_UTILITY is the + // ACE_Pair<x, ATTRIBUTES>. 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<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // The <container> 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 <delete_cleanup_strategy> - // flag is needed to decide the ownership of the cleanup strategy. - // Also, the timer attribute is initialed to zero in this constructor. - // And the <purge_percent> field denotes the percentage of the entries + ACE_LRU_Caching_Strategy (void); + // The <container> is the map in which the entries reside. The + // timer attribute is initialed to zero in this constructor. And + // the <purge_percent> 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 - // <delete_caching_strategy_utility> 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<KEY, VALUE, CONTAINER> *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<KEY, VALUE, CONTAINER> 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<KEY, VALUE, CONTAINER> *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 <class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template <class ATTRIBUTES, class CACHING_UTILITY> 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<x, ATTRIBUTES>. The CACHING_STRATEGY_UTILITY is the + // ACE_Pair<x, ATTRIBUTES>. 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<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // The <container> 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 <delete_cleanup_strategy> - // flag is needed to decide the ownership of the cleanup strategy. - // Also, the timer attribute is initialed to zero in this constructor. - // And the <purge_percent> field denotes the percentage of the entries + ACE_LFU_Caching_Strategy (void); + // The <container> is the map in which the entries reside. The + // timer attribute is initialed to zero in this constructor. And + // the <purge_percent> 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 - // <delete_caching_strategy_utility> decides whether to destroy the - // utility or not. - - ~ACE_LFU_Caching_Strategy (void); - - int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<KEY, VALUE, CONTAINER> 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<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template<class ATTRIBUTES, class CACHING_UTILITY> 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<x, ATTRIBUTES>. The CACHING_STRATEGY_UTILITY is the + // ACE_Pair<x, ATTRIBUTES>. 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<KEY, VALUE, CONTAINER> *cleanup_s = 0, - int delete_cleanup_strategy = 1, - CACHING_STRATEGY_UTILITY *utility_s = 0, - int delete_caching_strategy_utility = 1); - // The <container> 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 <delete_cleanup_strategy> - // flag is needed to decide the ownership of the cleanup strategy. - // Also, the timer attribute is initialed to zero in this constructor. - // And the <purge_percent> field denotes the percentage of the entries + ACE_FIFO_Caching_Strategy (void); + // The <container> is the map in which the entries reside. The + // timer attribute is initialed to zero in this constructor. And + // the <purge_percent> 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 - // <delete_caching_strategy_utility> decides whether to destroy the - // utility or not. - - ~ACE_FIFO_Caching_Strategy (void); - - int open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<KEY, VALUE, CONTAINER> 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<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> +template<class ATTRIBUTES, class CACHING_UTILITY> 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<KEY, VALUE, CONTAINER> *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<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::ACE_Caching_Strategy_Adapter (IMPLEMENTATION *implementation, - int delete_implementation) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::ACE_Caching_Strategy_Adapter (IMPLEMENTATION *implementation, + int delete_implementation) : implementation_ (implementation), delete_implementation_ (delete_implementation) { @@ -17,100 +17,89 @@ ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY } } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::~ACE_Caching_Strategy_Adapter (void) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::~ACE_Caching_Strategy_Adapter (void) { if (this->delete_implementation_) - delete this->implementation_; - this->delete_implementation_ = 0; - this->implementation_ = 0; -} - -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::open (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE ATTRIBUTES -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::attributes (void) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE ATTRIBUTES +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::attributes (void) { return this->implementation_->attributes (); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE double -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::purge_percent (void) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE double +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::purge_percent (void) { return this->implementation_->purge_percent (); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE void -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::purge_percent (double percentage) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE void +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::purge_percent (double percentage) { this->implementation_->purge_percent (percentage); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::notify_bind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE int +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::notify_bind (int result, + const ATTRIBUTES &attr) { return this->implementation_->notify_bind (result, attr); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::notify_find (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE int +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::notify_find (int result, + ATTRIBUTES &attr) { return this->implementation_->notify_find (result, attr); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::notify_unbind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE int +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::notify_unbind (int result, + const ATTRIBUTES &attr) { return this->implementation_->notify_unbind (result, attr); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::notify_trybind (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE int +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::notify_trybind (int result, + ATTRIBUTES &attr) { return this->implementation_->notify_trybind (result, attr); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::notify_rebind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE int +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::notify_rebind (int result, + const ATTRIBUTES &attr) { return this->implementation_->notify_rebind (result, attr); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE int -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::clear_cache (CONTAINER &container) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE IMPLEMENTATION & +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::implementation (void) { - return this->implementation_->clear_cache (container); + return *this->implementation_; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE IMPLEMENTATION & -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::implementation (void) +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE CACHING_UTILITY & +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::caching_utility (void) { - return *this->implementation_; + return this->implementation_->caching_utility (); } - -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY, class IMPLEMENTATION> ACE_INLINE void -ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY, IMPLEMENTATION>::dump (void) const +template<class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION> ACE_INLINE void +ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, IMPLEMENTATION>::dump (void) const { ACE_TRACE ("ACE_Caching_Strategy_Adapter::dump"); @@ -120,42 +109,39 @@ ACE_Caching_Strategy_Adapter<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY ////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE ATTRIBUTES -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::attributes (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE ATTRIBUTES +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::attributes (void) { return this->timer_; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE double -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE double +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (void) { return this->purge_percent_; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (double percentage) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (double percentage) { this->purge_percent_ = percentage; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_bind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); if (result == 0) - { - ++this->timer_; - ++this->entries_; - } + ++this->timer_; return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_find (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_find (int result, + ATTRIBUTES &attr) { if (result == 0) { @@ -166,26 +152,26 @@ ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTI return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_unbind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_trybind (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_rebind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); @@ -195,8 +181,14 @@ ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTI return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::dump (void) const +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE CACHING_UTILITY & +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::caching_utility (void) +{ + return this->caching_utility_; +} + +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::dump (void) const { ACE_TRACE ("ACE_LRU_Caching_Strategy::dump"); @@ -207,39 +199,36 @@ ACE_LRU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTI ////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE ATTRIBUTES -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::attributes (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE ATTRIBUTES +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::attributes (void) { return 0; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE double -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE double +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (void) { return this->purge_percent_; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (double percentage) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (double percentage) { this->purge_percent_ = percentage; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_bind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); - if (result == 0) - ++this->entries_; - return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_find (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_find (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); @@ -249,37 +238,40 @@ ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTI return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_trybind (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_rebind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); - if (result == 0) - ++this->entries_; - return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_unbind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::dump (void) const +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE CACHING_UTILITY & +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::caching_utility (void) +{ + return this->caching_utility_; +} + +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::dump (void) const { ACE_TRACE ("ACE_LFU_Caching_Strategy::dump"); @@ -289,84 +281,83 @@ ACE_LFU_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTI ////////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE ATTRIBUTES -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::attributes (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE ATTRIBUTES +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::attributes (void) { return this->order_; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE double -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE double +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (void) { return this->purge_percent_; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (double percentage) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (double percentage) { this->purge_percent_ = percentage; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_bind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); if (result == 0) - { - ++this->order_; - ++this->entries_; - } + ++this->order_; return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_find (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_find (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_unbind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_trybind (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_rebind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); if (result == 0) - { - ++this->order_; - ++this->entries_; - } + ++this->order_; return result; } +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE CACHING_UTILITY & +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::caching_utility (void) +{ + return this->caching_utility_; +} -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::dump (void) const +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::dump (void) const { ACE_TRACE ("ACE_FIFO_Caching_Strategy::dump"); @@ -377,71 +368,77 @@ ACE_FIFO_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UT ////////////////////////////////////////////////////////////////////////////////// -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE ATTRIBUTES -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::attributes (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE ATTRIBUTES +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::attributes (void) { return 0; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE double -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (void) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE double +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (void) { return 0; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::purge_percent (double percentage) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::purge_percent (double percentage) { ACE_UNUSED_ARG (percentage); } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_bind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_bind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_find (int result, - ATTRIBUTES &attr) + +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_find (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_unbind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_unbind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_trybind (int result, - ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_trybind (int result, + ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE int -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::notify_rebind (int result, - const ATTRIBUTES &attr) +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE int +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::notify_rebind (int result, + const ATTRIBUTES &attr) { ACE_UNUSED_ARG (attr); return result; } +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE CACHING_UTILITY & +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::caching_utility (void) +{ + return this->caching_utility_; +} -template<class KEY, class VALUE, class CONTAINER, class ATTRIBUTES, class CACHING_STRATEGY_UTILITY> ACE_INLINE void -ACE_Null_Caching_Strategy<KEY, VALUE, CONTAINER, ATTRIBUTES, CACHING_STRATEGY_UTILITY>::dump (void) const +template<class ATTRIBUTES, class CACHING_UTILITY> ACE_INLINE void +ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>::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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::ACE_Pair_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::~ACE_Pair_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} + template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, double purge_percent) { // Check that the purge_percent is non-zero. @@ -57,9 +76,9 @@ ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::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<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::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<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimum ( } //////////////////////////////////////////////////////////////////////////////////////////////////////// +template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::ACE_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::~ACE_Recyclable_Handler_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} + +template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int +ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::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 <purge_percent>. + 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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> void ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimum (CONTAINER &container, @@ -119,32 +203,55 @@ ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUT { // If the <min> 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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::ACE_Handler_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::~ACE_Handler_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int ACE_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, double purge_percent) { // Check that the purge_percent is non-zero. @@ -172,9 +279,9 @@ ACE_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::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<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimu //////////////////////////////////////////////////////////////////////////////////////////////////////// +template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Null_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::ACE_Null_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +ACE_Null_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::~ACE_Null_Caching_Utility (void) +{ + if (this->delete_cleanup_strategy_) + delete this->cleanup_strategy_; +} + template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int ACE_Null_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 KEY, class VALUE, class CONTAINER> -class ACE_Cleanup_Strategy; +#include "ace/Cleanup_Strategies_T.h" template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> 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 <KEY, ACE_Pair<VALUE, - // attributes>> 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 <KEY, ACE_Pair<VALUE, attributes>> + // 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<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; + + ACE_Pair_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + + // Constructor. + + ~ACE_Pair_Caching_Utility (void); + // Destructor. + int clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, double purge_percent); + // Purge entries from the <container>. 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 KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> -class ACE_Recyclable_Handler_Caching_Utility : public ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES> +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<K // decides and purges the entry from the container. Note: This // class helps in the caching_strategies using a container // containing entries of <KEY, Svc_Handler> 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<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; + typedef ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY_BASE; + + ACE_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *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 <container>. 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 <KEY, HANDLER> 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 <KEY, HANDLER> 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<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; + typedef ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY_BASE; + + ACE_Handler_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + // Constructor. + + ~ACE_Handler_Caching_Utility (void); + // Destructor. + int clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, double purge_percent); // Purge entries from the <container>. 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 <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> +template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> 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<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY; + typedef ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> CLEANUP_STRATEGY_BASE; + + ACE_Null_Caching_Utility (ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_strategy = 0, + int delete_cleanup_strategy = 0); + // Constructor. + + ~ACE_Null_Caching_Utility (void); + // Destructor. + int clear_cache (CONTAINER &container, - ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> *cleanup_s, double purge_percent); // Purge entries from the <container>. 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 <class KEY, class VALUE, class CONTAINER> -ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER>::~ACE_Cleanup_Strategy (void) -{ -} - //////////////////////////////////////////////////////////////////////////// template <class KEY, class VALUE, class CONTAINER> int -ACE_Default_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container, - KEY *key, - VALUE *value) +ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container, + KEY *key, + VALUE *value) { ACE_UNUSED_ARG (value); @@ -37,24 +32,25 @@ ACE_Default_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &contain //////////////////////////////////////////////////////////////////////////// template <class KEY, class VALUE, class CONTAINER> int -ACE_Svc_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container, - KEY *key, +ACE_Recyclable_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER>::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 <class KEY, class VALUE, class CONTAINER> int -ACE_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container, - KEY *key, +ACE_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER>::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<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &contain } return 0; - } //////////////////////////////////////////////////////////////////////////// + template <class KEY, class VALUE, class CONTAINER> int -ACE_Null_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container, - KEY *key, +ACE_Null_Cleanup_Strategy<KEY, VALUE, CONTAINER>::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 @@ -27,51 +27,23 @@ template <class KEY, class VALUE, class CONTAINER> 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 <KEY, - // VALUE> entry. - -}; - -////////////////////////////////////////////////////////////////////////// - -template <class KEY, class VALUE, class CONTAINER> -class ACE_Default_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> -{ - // = 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 KEY, class VALUE, class CONTAINER> -class ACE_Svc_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> +class ACE_Recyclable_Handler_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> { // = TITLE // Defines a strategy to be followed for cleaning up @@ -84,19 +56,19 @@ class ACE_Svc_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAIN // the handler is recyclable. 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 KEY, class VALUE, class CONTAINER> class ACE_Handler_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> { // = 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<KEY, VALUE, CON // attributes. 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 KEY, class VALUE, class CONTAINER> class ACE_Null_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> { @@ -126,10 +96,9 @@ class ACE_Null_Cleanup_Strategy : public ACE_Cleanup_Strategy<KEY, VALUE, CONTAI // the effect of the Cleanup Strategy. public: - + virtual int cleanup (CONTAINER &container, KEY *key, VALUE *value); // The dummy cleanup method. - }; #if defined (__ACE_INLINE__) diff --git a/ace/Hash_Cache_Map_Manager_T.cpp b/ace/Hash_Cache_Map_Manager_T.cpp index 9abe0de904d..57dde184a04 100644 --- a/ace/Hash_Cache_Map_Manager_T.cpp +++ b/ace/Hash_Cache_Map_Manager_T.cpp @@ -22,7 +22,7 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Hash_Cache_Map_Manager) #define T_1 class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES #define T_2 KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY, ATTRIBUTES - template <T_1> +template <T_1> ACE_Hash_Cache_Map_Manager<T_2>::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<KEY, \ + VALUE, \ + ACE_Hash_Map_Manager_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + ACE_Hash_Map_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + ACE_Hash_Map_Reverse_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + CACHING_STRATEGY, \ + ATTRIBUTES> +#else +#define ACE_CACHE_MAP_MANAGER \ + ACE_Cache_Map_Manager<KEY, \ + VALUE, \ + ACE_Hash_Map_Manager_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, \ + CACHING_STRATEGY, \ + ATTRIBUTES> +#endif (ACE_HAS_BROKEN_EXTENDED_TEMPLATES) + template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY, class ATTRIBUTES> -class ACE_Hash_Cache_Map_Manager : public ACE_Cache_Map_Manager< KEY, VALUE, - ACE_Hash_Map_Manager_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Reverse_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, 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<KEY, VALUE, - ACE_Hash_Map_Manager_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - ACE_Hash_Map_Reverse_Iterator_Ex<KEY, ACE_Pair<VALUE, ATTRIBUTES>, HASH_KEY, COMPARE_KEYS, ACE_Null_Mutex>, - CACHING_STRATEGY, ATTRIBUTES> - ACE_HCMM_BASE; + typedef ACE_CACHE_MAP_MANAGER ACE_HCMM_BASE; // Base class. }; |