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

Public Types | |
| typedef ACE_Recyclable_Handler_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY |
| typedef ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > | CLEANUP_STRATEGY_BASE |
Public Methods | |
| ACE_Recyclable_Handler_Caching_Utility (ACE_Cleanup_Strategy< KEY, VALUE, CONTAINER > *cleanup_strategy=0, int delete_cleanup_strategy=0) | |
| Constructor. More... | |
| ~ACE_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... | |
Private Methods | |
| 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: <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, Svc_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 101 of file Caching_Utility_T.h.
|
|||||
|
Definition at line 106 of file Caching_Utility_T.h. |
|
|||||
|
Definition at line 107 of file Caching_Utility_T.h. |
|
||||||||||||||||
|
Constructor.
Definition at line 122 of file Caching_Utility_T.cpp. References ACE_NEW, and delete_cleanup_strategy_.
00124 : cleanup_strategy_ (cleanup_strategy), 00125 delete_cleanup_strategy_ (delete_cleanup_strategy) 00126 { 00127 if (cleanup_strategy == 0) 00128 { 00129 ACE_NEW (this->cleanup_strategy_, 00130 CLEANUP_STRATEGY); 00131 this->delete_cleanup_strategy_ = 1; 00132 } 00133 } |
|
||||||||||
|
Destructor.
Definition at line 136 of file Caching_Utility_T.cpp. References cleanup_strategy_, and delete_cleanup_strategy_.
00137 {
00138 if (this->delete_cleanup_strategy_)
00139 delete this->cleanup_strategy_;
00140 }
|
|
||||||||||
|
|
|
||||||||||||||||
|
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 143 of file Caching_Utility_T.cpp. References ACE_MAX, ACE_Cleanup_Strategy::cleanup, cleanup_strategy_, and minimum.
00145 {
00146 // Check that the purge_percent is non-zero.
00147 if (purge_percent == 0)
00148 return 0;
00149
00150 // Get the number of entries in the container.
00151 size_t current_map_size = container.current_size ();
00152
00153 // Also whether the number of entries in the cache is just one!
00154 // Oops! then there is no way out but exiting. So return an error.
00155 // if (current_map_size <= 1)
00156 if (current_map_size == 0)
00157 return 0;
00158
00159 // Calculate the no of entries to remove from the cache depending
00160 // upon the <purge_percent>.
00161 size_t entries_to_remove
00162 = ACE_MAX (ACE_static_cast (size_t, 1),
00163 ACE_static_cast(size_t,
00164 ACE_static_cast(double, purge_percent)
00165 / 100 * current_map_size));
00166
00167 KEY *key_to_remove = 0;
00168 VALUE *value_to_remove = 0;
00169
00170 for (size_t i = 0; i < entries_to_remove ; ++i)
00171 {
00172 this->minimum (container,
00173 key_to_remove,
00174 value_to_remove);
00175
00176 // Simply verifying that the key is non-zero.
00177 // This is important for strategies where the minimum
00178 // entry cant be found due to constraints on the type of entry
00179 // to remove.
00180 if (key_to_remove == 0)
00181 return 0;
00182
00183 if (this->cleanup_strategy_->cleanup (container,
00184 key_to_remove,
00185 value_to_remove) == -1)
00186 return -1;
00187 }
00188
00189 return 0;
00190 }
|
|
||||||||||||||||||||
|
Find the entry with minimum caching attributes.
Definition at line 193 of file Caching_Utility_T.cpp. References ACE_RECYCLABLE_IDLE_AND_PURGABLE, and ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE. Referenced by clear_cache.
00196 {
00197 // Starting values.
00198 ITERATOR end = container.end ();
00199 ITERATOR iter = container.begin ();
00200 ATTRIBUTES min = (*iter).int_id_.second ();
00201 key_to_remove = 0;
00202 value_to_remove = 0;
00203 // Found the minimum entry to be purged?
00204 int found = 0;
00205
00206 // The iterator moves thru the container searching for the entry
00207 // with the lowest ATTRIBUTES.
00208 for (;
00209 iter != end;
00210 ++iter)
00211 {
00212 // If the <min> entry isnt IDLE_AND_PURGABLE continue until you reach
00213 // the first entry which can be purged. This is the minimum with
00214 // which you will compare the rest of the purgable entries.
00215 if ((*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE ||
00216 (*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE)
00217 {
00218 if (found == 0)
00219 {
00220 min = (*iter).int_id_.second ();
00221 key_to_remove = &(*iter).ext_id_;
00222 value_to_remove = &(*iter).int_id_;
00223 found = 1;
00224 }
00225 else
00226 {
00227 // Ah! an entry with lower ATTTRIBUTES...
00228 if (min > (*iter).int_id_.second ())
00229 {
00230 min = (*iter).int_id_.second ();
00231 key_to_remove = &(*iter).ext_id_;
00232 value_to_remove = &(*iter).int_id_;
00233 }
00234 }
00235 }
00236 }
00237 }
|
|
||||||||||
|
|
|
|||||
|
This is the default Cleanup Strategy for this utility.
Definition at line 132 of file Caching_Utility_T.h. Referenced by clear_cache, and ~ACE_Recyclable_Handler_Caching_Utility. |
|
|||||
|
Whether the cleanup_strategy should be destroyed or not.
Definition at line 135 of file Caching_Utility_T.h. Referenced by ACE_Recyclable_Handler_Caching_Utility, and ~ACE_Recyclable_Handler_Caching_Utility. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002