#include <Caching_Utility_T.h>
Collaboration diagram for ACE_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >:

Public Types | |
| typedef ACE_Recyclable_Handler_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY |
| typedef ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY_BASE |
Public Member Functions | |
| 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) |
Protected Member Functions | |
| void | minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove) |
| Find the entry with minimum caching attributes. | |
Protected 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. | |
Private Member Functions | |
| void | operator= (const ARHUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &) |
| ARHUTIL (const ARHUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &) | |
This class defines the methods commonly used by the different caching strategies. For instance: method which decides and purges the entry from the container.
Definition at line 103 of file Caching_Utility_T.h.
|
|||||
|
Definition at line 108 of file Caching_Utility_T.h. |
|
|||||
|
Definition at line 109 of file Caching_Utility_T.h. |
|
||||||||||||||||
|
Constructor.
Definition at line 120 of file Caching_Utility_T.cpp. References ACE_NEW.
00122 : cleanup_strategy_ (cleanup_strategy), 00123 delete_cleanup_strategy_ (delete_cleanup_strategy) 00124 { 00125 if (cleanup_strategy == 0) 00126 { 00127 ACE_NEW (this->cleanup_strategy_, 00128 CLEANUP_STRATEGY); 00129 this->delete_cleanup_strategy_ = 1; 00130 } 00131 } |
|
||||||||||
|
Destructor.
Definition at line 134 of file Caching_Utility_T.cpp.
00135 {
00136 if (this->delete_cleanup_strategy_)
00137 delete this->cleanup_strategy_;
00138 }
|
|
||||||||||
|
|
|
||||||||||||||||
|
Purge entries from the . The Cleanup_Strategy will do the actual job of cleanup once the entries to be cleaned up are decided. Definition at line 141 of file Caching_Utility_T.cpp. References ACE_MAX, ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER >::cleanup(), and ACE_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::minimum().
00143 {
00144 // Check that the purge_percent is non-zero.
00145 if (purge_percent == 0)
00146 return 0;
00147
00148 // Get the number of entries in the container.
00149 size_t current_map_size = container.current_size ();
00150
00151 // Also whether the number of entries in the cache is just one!
00152 // Oops! then there is no way out but exiting. So return an error.
00153 // if (current_map_size <= 1)
00154 if (current_map_size == 0)
00155 return 0;
00156
00157 // Calculate the no of entries to remove from the cache depending
00158 // upon the <purge_percent>.
00159 size_t const entries_to_remove
00160 = ACE_MAX (static_cast<size_t> (1),
00161 static_cast<size_t> (static_cast<double> (purge_percent)
00162 / 100 * current_map_size));
00163
00164 KEY *key_to_remove = 0;
00165 VALUE *value_to_remove = 0;
00166
00167 for (size_t i = 0; i < entries_to_remove ; ++i)
00168 {
00169 this->minimum (container,
00170 key_to_remove,
00171 value_to_remove);
00172
00173 // Simply verifying that the key is non-zero.
00174 // This is important for strategies where the minimum
00175 // entry cant be found due to constraints on the type of entry
00176 // to remove.
00177 if (key_to_remove == 0)
00178 return 0;
00179
00180 if (this->cleanup_strategy_->cleanup (container,
00181 key_to_remove,
00182 value_to_remove) == -1)
00183 return -1;
00184 }
00185
00186 return 0;
00187 }
|
|
||||||||||||||||||||
|
Find the entry with minimum caching attributes.
Definition at line 190 of file Caching_Utility_T.cpp. References ACE_RECYCLABLE_IDLE_AND_PURGABLE, and ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE. Referenced by ACE_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache().
00193 {
00194 // Starting values.
00195 ITERATOR end = container.end ();
00196 ITERATOR iter = container.begin ();
00197 ATTRIBUTES min = (*iter).int_id_.second ();
00198 key_to_remove = 0;
00199 value_to_remove = 0;
00200 // Found the minimum entry to be purged?
00201 int found = 0;
00202
00203 // The iterator moves thru the container searching for the entry
00204 // with the lowest ATTRIBUTES.
00205 for (;
00206 iter != end;
00207 ++iter)
00208 {
00209 // If the <min> entry isnt IDLE_AND_PURGABLE continue until you reach
00210 // the first entry which can be purged. This is the minimum with
00211 // which you will compare the rest of the purgable entries.
00212 if ((*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE ||
00213 (*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE)
00214 {
00215 if (found == 0)
00216 {
00217 min = (*iter).int_id_.second ();
00218 key_to_remove = &(*iter).ext_id_;
00219 value_to_remove = &(*iter).int_id_;
00220 found = 1;
00221 }
00222 else
00223 {
00224 // Ah! an entry with lower ATTTRIBUTES...
00225 if (min > (*iter).int_id_.second ())
00226 {
00227 min = (*iter).int_id_.second ();
00228 key_to_remove = &(*iter).ext_id_;
00229 value_to_remove = &(*iter).int_id_;
00230 }
00231 }
00232 }
00233 }
00234 }
|
|
||||||||||
|
|
|
|||||
|
This is the default Cleanup Strategy for this utility.
Definition at line 134 of file Caching_Utility_T.h. |
|
|||||
|
Whether the cleanup_strategy should be destroyed or not.
Definition at line 137 of file Caching_Utility_T.h. |
1.3.6