Caching_Strategies_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Caching_Strategies_T.h
00006  *
00007  *  Caching_Strategies_T.h,v 4.21 2005/10/28 16:14:51 ossama Exp
00008  *
00009  *  @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_CACHING_STRATEGIES_H
00014 #define ACE_CACHING_STRATEGIES_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/config-all.h"
00019 #include "ace/Caching_Utility_T.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 #if defined(_MSC_VER)
00026 #pragma warning(disable:4503)
00027 #endif /* _MSC_VER */
00028 
00029 // For linkers that cant grok long names.
00030 #define ACE_Caching_Strategy ACS
00031 
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 /**
00035  * @class ACE_Caching_Strategy
00036  *
00037  * @brief This class is an abstract base class for a caching strategy.
00038  *
00039  * This class consists of all the interfaces a caching strategy should
00040  * have and is used in association with the
00041  * ACE_Caching_Strategy_Adaptor.
00042  */
00043 template <class ATTRIBUTES, class CACHING_UTILITY>
00044 class ACE_Caching_Strategy
00045 {
00046 public:
00047   /// Destructor.
00048   virtual ~ACE_Caching_Strategy (void);
00049 
00050   /// Accessor method for the timer attributes.
00051   virtual ATTRIBUTES attributes (void) = 0;
00052 
00053   /// Get the percentage of entries to purge.
00054   virtual double purge_percent (void) = 0;
00055 
00056   /// Set the percentage of entries to purge.
00057   virtual void purge_percent (double percentage) = 0;
00058 
00059   // = Strategy related Operations
00060 
00061   /// This method acts as a notification about the CONTAINERs bind
00062   /// method call.
00063   virtual int notify_bind (int result,
00064                            const ATTRIBUTES &attr) = 0;
00065 
00066   /// This method acts as a notification about the CONTAINERs find
00067   /// method call
00068   virtual int notify_find (int result,
00069                            ATTRIBUTES &attr) = 0;
00070 
00071   /// This method acts as a notification about the CONTAINERs unbind
00072   /// method call
00073   virtual int notify_unbind (int result,
00074                              const ATTRIBUTES &attr) = 0;
00075 
00076   /// This method acts as a notification about the CONTAINERs trybind
00077   /// method call
00078   virtual int notify_trybind (int result,
00079                               ATTRIBUTES &attr) = 0;
00080 
00081   /// This method acts as a notification about the CONTAINERs rebind
00082   /// method call
00083   virtual int notify_rebind (int result,
00084                              const ATTRIBUTES &attr) = 0;
00085 
00086   /// Purge the cache.
00087   virtual CACHING_UTILITY &caching_utility (void) = 0;
00088 
00089   /// Dumps the state of the object.
00090   virtual void dump (void) const = 0;
00091 };
00092 
00093 //////////////////////////////////////////////////////////////////////////
00094 
00095 #define ACE_Caching_Strategy_Adapter ACSA
00096 
00097 /**
00098  * @class ACE_Caching_Strategy_Adapter
00099  *
00100  * @brief This class follows the Adaptor pattern and is used to provide
00101  * External Polymorphism by deriving from ACE_Caching_Strategy.
00102  *
00103  * This class simply delegates all requests to the
00104  * IMPLEMNETATION object within. This class should be passed in
00105  * place of the the abstract base ACE_Caching_Strategy class as
00106  * part of the External Polymorphism pattern.
00107  */
00108 template <class ATTRIBUTES, class CACHING_UTILITY, class IMPLEMENTATION>
00109 class ACE_Caching_Strategy_Adapter
00110   : public ACE_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
00111 {
00112 
00113 public:
00114 
00115   /// Constructor.
00116   ACE_Caching_Strategy_Adapter (IMPLEMENTATION *implementation = 0,
00117                                 int delete_implementation = 0);
00118 
00119   /// Destructor.
00120   ~ACE_Caching_Strategy_Adapter (void);
00121 
00122   /// Accessor method for the timer attributes.
00123   ATTRIBUTES attributes (void);
00124 
00125   /// Get the percentage of entries to purge.
00126   double purge_percent (void);
00127 
00128   /// Set the percentage of entries to purge.
00129   void purge_percent (double percentage);
00130 
00131   // = Strategy related Operations
00132 
00133   /// This method acts as a notification about the CONTAINERs bind
00134   /// method call.
00135   int notify_bind (int result,
00136                    const ATTRIBUTES &attr);
00137 
00138   /// This method acts as a notification about the CONTAINERs find
00139   /// method call
00140   int notify_find (int result,
00141                    ATTRIBUTES &attr);
00142 
00143   /// This method acts as a notification about the CONTAINERs unbind
00144   /// method call
00145   int notify_unbind (int result,
00146                      const ATTRIBUTES &attr);
00147 
00148   /// This method acts as a notification about the CONTAINERs trybind
00149   /// method call
00150   int notify_trybind (int result,
00151                       ATTRIBUTES &attr);
00152 
00153   /// This method acts as a notification about the CONTAINERs rebind
00154   /// method call
00155   int notify_rebind (int result,
00156                      const ATTRIBUTES &attr);
00157 
00158   /// Accessor to the implementation.
00159   IMPLEMENTATION &implementation (void);
00160 
00161   /// Purge the cache.
00162   CACHING_UTILITY &caching_utility (void);
00163 
00164   /// Dumps the state of the object.
00165   void dump (void) const;
00166 
00167 private:
00168 
00169   /// Implementation class.
00170   IMPLEMENTATION *implementation_;
00171 
00172   /// Do we need to delete the implementation?
00173   int delete_implementation_;
00174 };
00175 
00176 //////////////////////////////////////////////////////////////////////////
00177 #define ACE_LRU_Caching_Strategy ALRU
00178 
00179 /**
00180  * @class ACE_LRU_Caching_Strategy
00181  *
00182  * @brief Defines a Least Recently Used strategy which will decide on
00183  * the item to be removed from the cache.
00184  *
00185  * This is a strategy which makes use of a virtual timer which
00186  * is updated whenever an item is inserted or looked up in the
00187  * container. When the need of purging entries arises, the items
00188  * with the lowest timer values are removed.
00189  * Explanation of the template parameter list:
00190  * CONTAINER is any map with entries of type <KEY, VALUE>.
00191  * The ATTRIBUTES are the deciding factor for purging of entries
00192  * and should logically be included with the VALUE. Some ways of
00193  * doing this are: As being a member of the VALUE or VALUE being
00194  * ACE_Pair<x, ATTRIBUTES>. The CACHING_UTILITY is the
00195  * class which can be plugged in and which decides the entries
00196  * to purge.
00197  */
00198 template <class ATTRIBUTES, class CACHING_UTILITY>
00199 class ACE_LRU_Caching_Strategy
00200 {
00201 public:
00202 
00203   // Traits.
00204   typedef ATTRIBUTES CACHING_ATTRIBUTES;
00205 
00206   // = Initialisation and termination.
00207 
00208   /**
00209    * The <container> is the map in which the entries reside.  The
00210    * timer attribute is initialed to zero in this constructor.  And
00211    * the <purge_percent> field denotes the percentage of the entries
00212    * in the cache which can be purged automagically and by default is
00213    * set to 10%.
00214    */
00215   ACE_LRU_Caching_Strategy (void);
00216 
00217   // = Operations of the strategy.
00218 
00219   /// Accessor method for the timer attributes.
00220   ATTRIBUTES attributes (void);
00221 
00222   /// Get the percentage of entries to purge.
00223   double purge_percent (void);
00224 
00225   /// Set the percentage of entries to purge.
00226   void purge_percent (double percentage);
00227 
00228   // =  Strategy related Operations
00229 
00230   /// This method acts as a notification about the CONTAINERs bind
00231   /// method call.
00232   int notify_bind (int result,
00233                    const ATTRIBUTES &attr);
00234 
00235   /// This method acts as a notification about the CONTAINERs find
00236   /// method call
00237   int notify_find (int result,
00238                    ATTRIBUTES &attr);
00239 
00240   /// This method acts as a notification about the CONTAINERs unbind
00241   /// method call
00242   int notify_unbind (int result,
00243                      const ATTRIBUTES &attr);
00244 
00245 
00246   /// This method acts as a notification about the CONTAINERs trybind
00247   /// method call
00248   int notify_trybind (int result,
00249                       ATTRIBUTES &attr);
00250 
00251   /// This method acts as a notification about the CONTAINERs rebind
00252   /// method call
00253   int notify_rebind (int result,
00254                      const ATTRIBUTES &attr);
00255 
00256   /// Purge the cache.
00257   CACHING_UTILITY &caching_utility (void);
00258 
00259   /// Dumps the state of the object.
00260   void dump (void) const;
00261 
00262 private:
00263 
00264   /// This element is the one which is the deciding factor for purging
00265   /// of an ITEM.
00266   ATTRIBUTES timer_;
00267 
00268   /// The level about which the purging will happen automagically.
00269   double purge_percent_;
00270 
00271   /// This is the helper class which will decide and expunge entries
00272   /// from the cache.
00273   CACHING_UTILITY caching_utility_;
00274 };
00275 
00276 //////////////////////////////////////////////////////////////////////////
00277 #define ACE_LFU_Caching_Strategy ALFU
00278 
00279 /**
00280  * @class ACE_LFU_Caching_Strategy
00281  *
00282  * @brief Defines a Least Frequently Used strategy for which will decide on
00283  * the item to be removed from the cache.
00284  *
00285  * A attribute is tagged to each item which increments whenever
00286  * the item is bound or looked up in the cache. Thus it denotes
00287  * the frequency of use. According to the value of the attribute
00288  * the item is removed from the CONTAINER i.e cache.
00289  * Explanation of the template parameter list:
00290  * CONTAINER is any map with entries of type <KEY, VALUE>.
00291  * The ATTRIBUTES are the deciding factor for purging of entries
00292  * and should logically be included with the VALUE. Some ways of
00293  * doing this are: As being a member of the VALUE or VALUE being
00294  * ACE_Pair<x, ATTRIBUTES>. The CACHING_UTILITY is the
00295  * class which can be plugged in and which decides the entries
00296  * to purge.
00297  */
00298 template <class ATTRIBUTES, class CACHING_UTILITY>
00299 class ACE_LFU_Caching_Strategy
00300 {
00301 
00302 public:
00303 
00304   // Traits.
00305   typedef ATTRIBUTES CACHING_ATTRIBUTES;
00306 
00307   // = Initialisation and termination methods.
00308 
00309   /**
00310    * The <container> is the map in which the entries reside.  The
00311    * timer attribute is initialed to zero in this constructor.  And
00312    * the <purge_percent> field denotes the percentage of the entries
00313    * in the cache which can be purged automagically and by default is
00314    * set to 10%.
00315    */
00316   ACE_LFU_Caching_Strategy (void);
00317 
00318   // = Strategy methods.
00319 
00320   /// Access the attributes.
00321   ATTRIBUTES attributes (void);
00322 
00323   /// Get the percentage of entries to purge.
00324   double purge_percent (void);
00325 
00326   /// Set the percentage of entries to purge.
00327   void purge_percent (double percentage);
00328 
00329   // =  Strategy related Operations
00330 
00331   /// This method acts as a notification about the CONTAINERs bind
00332   /// method call.
00333   int notify_bind (int result,
00334                    const ATTRIBUTES &attr);
00335 
00336   /// Lookup notification.
00337   int notify_find (int result,
00338                    ATTRIBUTES &attr);
00339 
00340   /// This method acts as a notification about the CONTAINERs unbind
00341   /// method call
00342   int notify_unbind (int result,
00343                      const ATTRIBUTES &attr);
00344 
00345   /// This method acts as a notification about the CONTAINERs trybind
00346   /// method call
00347   int notify_trybind (int result,
00348                       ATTRIBUTES &attr);
00349 
00350   /// This method acts as a notification about the CONTAINERs rebind
00351   /// method call
00352   int notify_rebind (int result,
00353                      const ATTRIBUTES &attr);
00354 
00355   /// Purge the cache.
00356   CACHING_UTILITY &caching_utility (void);
00357 
00358   /// Dumps the state of the object.
00359   void dump (void) const;
00360 
00361 private:
00362 
00363   /// The level about which the purging will happen automagically.
00364   double purge_percent_;
00365 
00366   /// This is the helper class which will decide and expunge entries
00367   /// from the cache.
00368   CACHING_UTILITY caching_utility_;
00369 };
00370 
00371 /////////////////////////////////////////////////////////////
00372 #define ACE_FIFO_Caching_Strategy AFIFO
00373 
00374 /**
00375  * @class ACE_FIFO_Caching_Strategy
00376  *
00377  * @brief The First In First Out strategy is implemented wherein each
00378  * item is ordered.
00379  *
00380  * The order tag of each item is used to decide the item to be
00381  * removed from the cache. The items with least order are removed.
00382  * Explanation of the template parameter list:
00383  * CONTAINER is any map with entries of type <KEY, VALUE>.
00384  * The ATTRIBUTES are the deciding factor for purging of entries
00385  * and should logically be included with the VALUE. Some ways of
00386  * doing this are: As being a member of the VALUE or VALUE being
00387  * ACE_Pair<x, ATTRIBUTES>. The CACHING_UTILITY is the
00388  * class which can be plugged in and which decides the entries
00389  * to purge.
00390  */
00391 template<class ATTRIBUTES, class CACHING_UTILITY>
00392 class ACE_FIFO_Caching_Strategy
00393 {
00394 
00395 public:
00396 
00397   typedef ATTRIBUTES CACHING_ATTRIBUTES;
00398 
00399   // = Initialisation and termination.
00400 
00401   /**
00402    * The <container> is the map in which the entries reside.  The
00403    * timer attribute is initialed to zero in this constructor.  And
00404    * the <purge_percent> field denotes the percentage of the entries
00405    * in the cache which can be purged automagically and by default is
00406    * set to 10%.
00407    */
00408   ACE_FIFO_Caching_Strategy (void);
00409 
00410   // = Strategy methods.
00411 
00412   /// Accessor method.
00413   ATTRIBUTES attributes (void);
00414 
00415   /// Get the percentage of entries to purge.
00416   double purge_percent (void);
00417 
00418   /// Set the percentage of entries to purge.
00419   void purge_percent (double percentage);
00420 
00421   // =  Strategy related Operations
00422 
00423   /// Notification for an item getting bound into the cache.
00424   int notify_bind (int result,
00425                    const ATTRIBUTES &attr);
00426 
00427   /// This method acts as a notification about the CONTAINERs find
00428   /// method call
00429   int notify_find (int result,
00430                    ATTRIBUTES &attr);
00431 
00432   /// This method acts as a notification about the CONTAINERs unbind
00433   /// method call
00434   int notify_unbind (int result,
00435                      const ATTRIBUTES &attr);
00436 
00437   /// This method acts as a notification about the CONTAINERs trybind
00438   /// method call
00439   int notify_trybind (int result,
00440                       ATTRIBUTES &attr);
00441 
00442   /// Notification for an item getting bound again into the cache.
00443   int notify_rebind (int result,
00444                      const ATTRIBUTES &attr);
00445 
00446   /// Purge the cache.
00447   CACHING_UTILITY &caching_utility (void);
00448 
00449   /// Dumps the state of the object.
00450   void dump (void) const;
00451 
00452 private:
00453 
00454   /// The order is the deciding factor for the item to be removed from
00455   /// the cache.
00456   ATTRIBUTES order_;
00457 
00458   /// The level about which the purging will happen automagically.
00459   double purge_percent_;
00460 
00461   /// This is the helper class which will decide and expunge entries
00462   /// from the cache.
00463   CACHING_UTILITY caching_utility_;
00464 };
00465 
00466 //////////////////////////////////////////////////////////////////////
00467 #define ACE_Null_Caching_Strategy ANULL
00468 
00469 /**
00470  * @class ACE_Null_Caching_Strategy
00471  *
00472  * @brief The is a special caching strategy which doesnt have the purging
00473  * feature.
00474  *
00475  * No purging provided. To be used when purging might be too expensive
00476  * an operation.
00477  */
00478 template<class ATTRIBUTES, class CACHING_UTILITY>
00479 class ACE_Null_Caching_Strategy
00480 {
00481 
00482 public:
00483 
00484   // = Traits.
00485   typedef ATTRIBUTES CACHING_ATTRIBUTES;
00486 
00487   // = Strategy methods. All are NO_OP methods!!!
00488 
00489   /// Accessor method.
00490   ATTRIBUTES attributes (void);
00491 
00492   /// Get the percentage of entries to purge.
00493   double purge_percent (void);
00494 
00495   /// Set the percentage of entries to purge.
00496   void purge_percent (double percentage);
00497 
00498   // =  Strategy related Operations
00499 
00500   /// Notification for an item getting bound into the cache.
00501   int notify_bind (int result,
00502                    const ATTRIBUTES &attr);
00503 
00504   /// This method acts as a notification about the CONTAINERs find
00505   /// method call
00506   int notify_find (int result,
00507                    ATTRIBUTES &attr);
00508 
00509   /// This method acts as a notification about the CONTAINERs unbind
00510   /// method call
00511   int notify_unbind (int result,
00512                      const ATTRIBUTES &attr);
00513 
00514   /// This method acts as a notification about the CONTAINERs trybind
00515   /// method call
00516   int notify_trybind (int result,
00517                       ATTRIBUTES &attr);
00518 
00519   /// Notification for an item getting bound again into the cache.
00520   int notify_rebind (int result,
00521                      const ATTRIBUTES &attr);
00522 
00523   /// Purge the cache.
00524   CACHING_UTILITY &caching_utility (void);
00525 
00526   /// Dumps the state of the object.
00527   void dump (void) const;
00528 
00529 private:
00530 
00531   /// This is the helper class which will decide and expunge entries
00532   /// from the cache.
00533   CACHING_UTILITY caching_utility_;
00534 };
00535 
00536 ACE_END_VERSIONED_NAMESPACE_DECL
00537 
00538 #if defined (__ACE_INLINE__)
00539 #include "ace/Caching_Strategies_T.inl"
00540 #endif /* __ACE_INLINE__ */
00541 
00542 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00543 #include "ace/Caching_Strategies_T.cpp"
00544 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00545 
00546 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00547 #pragma implementation ("Caching_Strategies_T.cpp")
00548 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00549 
00550 #include /**/ "ace/post.h"
00551 
00552 #endif /* ACE_CACHING_STRATEGIES_H */

Generated on Thu Nov 9 09:41:47 2006 for ACE by doxygen 1.3.6