#include <Caching_Utility_T.h>
Collaboration diagram for ACE_Refcounted_Recyclable_Handler_Caching_Utility:

Public Types | |
| typedef ACE_Refcounted_Recyclable_Handler_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY |
| typedef ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY_BASE |
Public Methods | |
| ACE_Refcounted_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > *cleanup_strategy=0, int delete_cleanup_strategy=0) | |
| Constructor. More... | |
| ~ACE_Refcounted_Recyclable_Handler_Caching_Utility (void) | |
| Destructor. More... | |
| int | clear_cache (CONTAINER &container, double purge_percent) |
Protected Methods | |
| void | minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove) |
| Find the entry with minimum caching attributes. More... | |
Protected Attributes | |
| CLEANUP_STRATEGY_BASE * | cleanup_strategy_ |
| This is the default Cleanup Strategy for this utility. More... | |
| int | delete_cleanup_strategy_ |
| Whether the cleanup_strategy should be destroyed or not. More... | |
| size_t | marked_as_closed_entries_ |
Private Methods | |
| void | operator= (const ARRHUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &) |
| ARRHUTIL (const ARRHUTIL< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &) | |
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 <Refcounted_KEY, Recyclable_Connection_Handler> 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.
Definition at line 161 of file Caching_Utility_T.h.
|
|||||
|
Definition at line 166 of file Caching_Utility_T.h. |
|
|||||
|
Definition at line 167 of file Caching_Utility_T.h. |
|
||||||||||||||||
|
Constructor.
Definition at line 242 of file Caching_Utility_T.cpp. References ACE_NEW, and delete_cleanup_strategy_.
00244 : cleanup_strategy_ (cleanup_strategy), 00245 delete_cleanup_strategy_ (delete_cleanup_strategy), 00246 marked_as_closed_entries_ (0) 00247 { 00248 if (cleanup_strategy == 0) 00249 { 00250 ACE_NEW (this->cleanup_strategy_, 00251 CLEANUP_STRATEGY); 00252 this->delete_cleanup_strategy_ = 1; 00253 } 00254 } |
|
||||||||||
|
Destructor.
Definition at line 257 of file Caching_Utility_T.cpp. References cleanup_strategy_, and delete_cleanup_strategy_.
00258 {
00259 if (this->delete_cleanup_strategy_)
00260 delete this->cleanup_strategy_;
00261 }
|
|
||||||||||
|
|
|
||||||||||||||||
|
Purge entries from the <container>. The Cleanup_Strategy will do the actual job of cleanup once the entries to be cleaned up are decided. Definition at line 264 of file Caching_Utility_T.cpp. References ACE_MAX, ACE_Cleanup_Strategy::cleanup, cleanup_strategy_, marked_as_closed_entries_, and minimum.
00266 {
00267 // Check that the purge_percent is non-zero.
00268 if (purge_percent == 0)
00269 return 0;
00270
00271 // Get the number of entries in the container which can be considered for purging.
00272 size_t available_entries = container.current_size () - this->marked_as_closed_entries_;
00273
00274 // Also whether the number of entries in the cache zero.
00275 // Oops! then there is no way out but exiting.
00276 if (available_entries <= 0)
00277 return 0;
00278
00279 // Calculate the no of entries to remove from the cache depending
00280 // upon the <purge_percent>.
00281 size_t entries_to_remove
00282 = ACE_MAX (ACE_static_cast (size_t, 1),
00283 ACE_static_cast(size_t,
00284 ACE_static_cast(double, purge_percent)
00285 / 100 * available_entries));
00286
00287 if (entries_to_remove >= available_entries ||
00288 entries_to_remove == 0)
00289 entries_to_remove = available_entries - 1;
00290
00291 KEY *key_to_remove = 0;
00292 VALUE *value_to_remove = 0;
00293
00294 for (size_t i = 0; i < entries_to_remove ; ++i)
00295 {
00296 this->minimum (container,
00297 key_to_remove,
00298 value_to_remove);
00299
00300 // Simply verifying that the key is non-zero.
00301 // This is important for strategies where the minimum
00302 // entry cant be found due to constraints on the type of entry
00303 // to remove.
00304 if (key_to_remove == 0)
00305 return 0;
00306
00307 if (this->cleanup_strategy_->cleanup (container,
00308 key_to_remove,
00309 value_to_remove) == -1)
00310 return -1;
00311
00312 ++this->marked_as_closed_entries_;
00313 }
00314
00315 return 0;
00316 }
|
|
||||||||||||||||||||
|
Find the entry with minimum caching attributes.
Definition at line 319 of file Caching_Utility_T.cpp. References ACE_RECYCLABLE_IDLE_AND_PURGABLE, and ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE. Referenced by clear_cache.
00322 {
00323 // Starting values.
00324 ITERATOR end = container.end ();
00325 ITERATOR iter = container.begin ();
00326 ATTRIBUTES min = (*iter).int_id_.second ();
00327 key_to_remove = 0;
00328 value_to_remove = 0;
00329 // Found the minimum entry to be purged?
00330 int found = 0;
00331
00332 // The iterator moves thru the container searching for the entry
00333 // with the lowest ATTRIBUTES.
00334 for (;
00335 iter != end;
00336 ++iter)
00337 {
00338 // If the <min> entry isnt IDLE_AND_PURGABLE continue until you reach
00339 // the first entry which can be purged. This is the minimum with
00340 // which you will compare the rest of the purgable entries.
00341 if ((*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE ||
00342 (*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE)
00343 {
00344 if (found == 0)
00345 {
00346 min = (*iter).int_id_.second ();
00347 key_to_remove = &(*iter).ext_id_;
00348 value_to_remove = &(*iter).int_id_;
00349 found = 1;
00350 }
00351 else
00352 {
00353 // Ah! an entry with lower ATTTRIBUTES...
00354 if (min > (*iter).int_id_.second ())
00355 {
00356 min = (*iter).int_id_.second ();
00357 key_to_remove = &(*iter).ext_id_;
00358 value_to_remove = &(*iter).int_id_;
00359 }
00360 }
00361 }
00362 }
00363 }
|
|
||||||||||
|
|
|
|||||
|
This is the default Cleanup Strategy for this utility.
Definition at line 192 of file Caching_Utility_T.h. Referenced by clear_cache, and ~ACE_Refcounted_Recyclable_Handler_Caching_Utility. |
|
|||||
|
Whether the cleanup_strategy should be destroyed or not.
Definition at line 195 of file Caching_Utility_T.h. Referenced by ACE_Refcounted_Recyclable_Handler_Caching_Utility, and ~ACE_Refcounted_Recyclable_Handler_Caching_Utility. |
|
|||||
|
This figure denotes the number of entries are there in the container which have been marked as closed already but might not have been unbound from the container. Definition at line 202 of file Caching_Utility_T.h. Referenced by clear_cache. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002