ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > Class Template Reference

Defines a helper class for the Caching Strategies. More...

#include <Caching_Utility_T.h>

List of all members.

Public Types

typedef ACE_Handler_Cleanup_Strategy<
KEY, VALUE, CONTAINER > 
CLEANUP_STRATEGY
typedef ACE_Cleanup_Strategy<
KEY, VALUE, CONTAINER > 
CLEANUP_STRATEGY_BASE

Public Member Functions

 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, double purge_percent)

Protected Member Functions

void minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove)

Protected Attributes

CLEANUP_STRATEGY_BASEcleanup_strategy_
int delete_cleanup_strategy_
 Whether the cleanup_strategy should be destroyed or not.


Private Member Functions

void operator= (const ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &)
 ACE_Handler_Caching_Utility (const ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &)


Detailed Description

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
class ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >

Defines a helper class for the Caching Strategies.

This class defines the methods commonly used by the different caching strategies. For instance: 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.

Definition at line 228 of file Caching_Utility_T.h.


Member Typedef Documentation

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
typedef ACE_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER> ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::CLEANUP_STRATEGY
 

Definition at line 232 of file Caching_Utility_T.h.

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
typedef ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER> ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::CLEANUP_STRATEGY_BASE
 

Definition at line 233 of file Caching_Utility_T.h.


Constructor & Destructor Documentation

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 = 0,
int  delete_cleanup_strategy = 0
 

Constructor.

Definition at line 364 of file Caching_Utility_T.cpp.

References ACE_NEW.

00366   : cleanup_strategy_ (cleanup_strategy),
00367     delete_cleanup_strategy_ (delete_cleanup_strategy)
00368 {
00369   if (cleanup_strategy == 0)
00370     {
00371       ACE_NEW (this->cleanup_strategy_,
00372                CLEANUP_STRATEGY);
00373       this->delete_cleanup_strategy_ = 1;
00374     }
00375 }

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   ) 
 

Destructor.

Definition at line 378 of file Caching_Utility_T.cpp.

00379 {
00380   if (this->delete_cleanup_strategy_)
00381     delete this->cleanup_strategy_;
00382 }

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::ACE_Handler_Caching_Utility const ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &   )  [private]
 


Member Function Documentation

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,
double  purge_percent
 

Purge entries from the . The Cleanup_Strategy will do the actual job of cleanup once the entries to be cleaned up are decided.

Definition at line 385 of file Caching_Utility_T.cpp.

References ACE_MAX, and ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::minimum().

00387 {
00388   // Check that the purge_percent is non-zero.
00389   if (purge_percent == 0)
00390     return 0;
00391 
00392   // Get the number of entries in the container.
00393   size_t current_map_size = container.current_size ();
00394 
00395   // Also whether the number of entries in the cache is just one!
00396   // Oops! then there is no way out but exiting. So return an error.
00397   if (current_map_size == 0)
00398     return 0;
00399 
00400   // Calculate the no of entries to remove from the cache depending
00401   // upon the <purge_percent>.
00402   size_t entries_to_remove
00403     = ACE_MAX (static_cast<size_t> (1),
00404                static_cast<size_t> (static_cast<double> (purge_percent)
00405                                     / 100 * current_map_size));
00406 
00407   KEY *key_to_remove = 0;
00408   VALUE *value_to_remove = 0;
00409 
00410   for (size_t i = 0; i < entries_to_remove ; ++i)
00411     {
00412       this->minimum (container,
00413                      key_to_remove,
00414                      value_to_remove);
00415 
00416       if (this->cleanup_strategy_->cleanup (container,
00417                                             key_to_remove,
00418                                             value_to_remove) == -1)
00419         return -1;
00420     }
00421 
00422   return 0;
00423 }

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
void ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::minimum CONTAINER &  container,
KEY *&  key_to_remove,
VALUE *&  value_to_remove
[protected]
 

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.

Definition at line 426 of file Caching_Utility_T.cpp.

Referenced by ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::clear_cache().

00429 {
00430   // Starting values.
00431   ITERATOR iter = container.begin ();
00432   ITERATOR end = container.end ();
00433   ATTRIBUTES min = (*iter).int_id_->caching_attributes ();
00434   key_to_remove = &(*iter).ext_id_;
00435   value_to_remove = &(*iter).int_id_;
00436 
00437   // The iterator moves thru the container searching for the entry
00438   // with the lowest ATTRIBUTES.
00439   for (++iter;
00440        iter != end;
00441        ++iter)
00442     {
00443       if (min > (*iter).int_id_->caching_attributes () &&
00444           (*iter).int_id_->active () != 1)
00445         {
00446           // Ah! an item with lower ATTTRIBUTES...
00447           min = (*iter).int_id_->caching_attributes ();
00448           key_to_remove = &(*iter).ext_id_;
00449           value_to_remove = &(*iter).int_id_;
00450         }
00451     }
00452 }

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
void ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::operator= const ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES > &   )  [private]
 


Member Data Documentation

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
CLEANUP_STRATEGY_BASE* ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::cleanup_strategy_ [protected]
 

The cleanup strategy which can be used to destroy the entries of the container.

Definition at line 264 of file Caching_Utility_T.h.

template<class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES>
int ACE_Handler_Caching_Utility< KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES >::delete_cleanup_strategy_ [protected]
 

Whether the cleanup_strategy should be destroyed or not.

Definition at line 267 of file Caching_Utility_T.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:22:48 2006 for ACE by doxygen 1.3.6