Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Caching_Strategies_T.h

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

Generated on Mon Jun 16 11:19:17 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002