#include <Caching_Utility_T.h>
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 Member Functions | |
| ACE_Refcounted_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > *cleanup_strategy=0, int delete_cleanup_strategy=0) | |
| Constructor.   | |
| ~ACE_Refcounted_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.   | |
| size_t | marked_as_closed_entries_ | 
Private Member Functions | |
| 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.
Definition at line 163 of file Caching_Utility_T.h.
      
  | 
  |||||
| 
 
 Definition at line 168 of file Caching_Utility_T.h.  | 
  
      
  | 
  |||||
| 
 
 Definition at line 169 of file Caching_Utility_T.h.  | 
  
      
  | 
  ||||||||||||||||
| 
 Constructor. 
 Definition at line 239 of file Caching_Utility_T.cpp. References ACE_NEW. 
 00241 : cleanup_strategy_ (cleanup_strategy), 00242 delete_cleanup_strategy_ (delete_cleanup_strategy), 00243 marked_as_closed_entries_ (0) 00244 { 00245 if (cleanup_strategy == 0) 00246 { 00247 ACE_NEW (this->cleanup_strategy_, 00248 CLEANUP_STRATEGY); 00249 this->delete_cleanup_strategy_ = 1; 00250 } 00251 }  | 
  
      
  | 
  ||||||||||
| 
 Destructor. 
 Definition at line 254 of file Caching_Utility_T.cpp. 
 00255 {
00256   if (this->delete_cleanup_strategy_)
00257     delete this->cleanup_strategy_;
00258 }
 | 
  
      
  | 
  ||||||||||
| 
 
  | 
  
      
  | 
  ||||||||||||||||
| 
 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 261 of file Caching_Utility_T.cpp. References ACE_MAX, ACE_Refcounted_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::marked_as_closed_entries_, and ACE_Refcounted_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::minimum(). 
 00263 {
00264   // Check that the purge_percent is non-zero.
00265   if (purge_percent == 0)
00266     return 0;
00267 
00268   // Get the number of entries in the container which can be considered for purging.
00269   size_t const available_entries =
00270     container.current_size () - this->marked_as_closed_entries_;
00271 
00272   // Also whether the number of entries in the cache zero.
00273   // Oops! then there is no way out but exiting.
00274   if (available_entries <= 0)
00275     return 0;
00276 
00277   // Calculate the no of entries to remove from the cache depending
00278   // upon the <purge_percent>.
00279   size_t entries_to_remove
00280     = ACE_MAX (static_cast<size_t> (1),
00281                static_cast<size_t> (static_cast<double> (purge_percent)
00282                                     / 100 * available_entries));
00283 
00284   if (entries_to_remove >= available_entries  || entries_to_remove == 0)
00285     entries_to_remove = available_entries - 1;
00286 
00287   KEY *key_to_remove = 0;
00288   VALUE *value_to_remove = 0;
00289 
00290   for (size_t i = 0; i < entries_to_remove ; ++i)
00291     {
00292       this->minimum (container,
00293                      key_to_remove,
00294                      value_to_remove);
00295 
00296       // Simply verifying that the key is non-zero.
00297       // This is important for strategies where the minimum
00298       // entry cant be found due to constraints on the type of entry
00299       // to remove.
00300       if (key_to_remove == 0)
00301         return 0;
00302 
00303       if (this->cleanup_strategy_->cleanup (container,
00304                                             key_to_remove,
00305                                             value_to_remove) == -1)
00306         return -1;
00307 
00308       ++this->marked_as_closed_entries_;
00309     }
00310 
00311   return 0;
00312 }
 | 
  
      
  | 
  ||||||||||||||||||||
| 
 Find the entry with minimum caching attributes. 
 Definition at line 315 of file Caching_Utility_T.cpp. References ACE_RECYCLABLE_IDLE_AND_PURGABLE, and ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE. Referenced by ACE_Refcounted_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache(). 
 00318 {
00319   // Starting values.
00320   ITERATOR end = container.end ();
00321   ITERATOR iter = container.begin ();
00322   ATTRIBUTES min = (*iter).int_id_.second ();
00323   key_to_remove = 0;
00324   value_to_remove = 0;
00325   // Found the minimum entry to be purged?
00326   int found = 0;
00327 
00328   // The iterator moves thru the container searching for the entry
00329   // with the lowest ATTRIBUTES.
00330   for (;
00331        iter != end;
00332        ++iter)
00333     {
00334       // If the <min> entry isnt IDLE_AND_PURGABLE continue until you reach
00335       // the first entry which can be purged. This is the minimum with
00336       // which you will compare the rest of the purgable entries.
00337       if ((*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE ||
00338           (*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE)
00339         {
00340           if (found == 0)
00341             {
00342               min = (*iter).int_id_.second ();
00343               key_to_remove = &(*iter).ext_id_;
00344               value_to_remove = &(*iter).int_id_;
00345               found = 1;
00346             }
00347           else
00348             {
00349               // Ah! an entry with lower ATTTRIBUTES...
00350               if (min > (*iter).int_id_.second ())
00351                 {
00352                   min = (*iter).int_id_.second ();
00353                   key_to_remove = &(*iter).ext_id_;
00354                   value_to_remove = &(*iter).int_id_;
00355                 }
00356             }
00357         }
00358     }
00359 }
 | 
  
      
  | 
  ||||||||||
| 
 
  | 
  
      
  | 
  |||||
| 
 This is the default Cleanup Strategy for this utility. 
 Definition at line 194 of file Caching_Utility_T.h.  | 
  
      
  | 
  |||||
| 
 Whether the cleanup_strategy should be destroyed or not. 
 Definition at line 197 of file Caching_Utility_T.h.  | 
  
      
  | 
  |||||
| 
 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 204 of file Caching_Utility_T.h. Referenced by ACE_Refcounted_Recyclable_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache().  | 
  
 
1.3.6