16 #ifndef HAZELCAST_CLIENT_INTERNAL_EVICTION_EVICTIONPOLICYEVALUATORPROVIDER_H_
17 #define HAZELCAST_CLIENT_INTERNAL_EVICTION_EVICTIONPOLICYEVALUATORPROVIDER_H_
20 #include <boost/shared_ptr.hpp>
22 #include "hazelcast/client/exception/IllegalArgumentException.h"
23 #include "hazelcast/client/internal/eviction/impl/comparator/LRUEvictionPolicyComparator.h"
24 #include "hazelcast/client/internal/eviction/impl/comparator/LFUEvictionPolicyComparator.h"
25 #include "hazelcast/client/internal/eviction/impl/comparator/RandomEvictionPolicyComparator.h"
26 #include "hazelcast/client/internal/eviction/EvictionConfiguration.h"
27 #include "hazelcast/client/internal/eviction/EvictionPolicyEvaluator.h"
28 #include "hazelcast/client/internal/eviction/impl/evaluator/DefaultEvictionPolicyEvaluator.h"
30 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
32 #pragma warning(disable: 4251) //for dll export
51 template<
typename MAPKEY,
typename MAPVALUE,
typename A,
typename E>
54 if (evictionConfig.get() == NULL) {
55 return std::auto_ptr<EvictionPolicyEvaluator<MAPKEY, MAPVALUE, A, E> >();
58 boost::shared_ptr<EvictionPolicyComparator<MAPKEY, MAPVALUE> > evictionPolicyComparator;
60 const boost::shared_ptr<EvictionPolicyComparator<MAPKEY, MAPVALUE> > &comparator = evictionConfig->getComparator();
61 if (comparator.get() != NULL) {
62 evictionPolicyComparator = comparator;
64 EvictionPolicyType evictionPolicyType = evictionConfig->getEvictionPolicyType();
65 evictionPolicyComparator = createEvictionPolicyComparator<MAPKEY, MAPVALUE>(evictionPolicyType);
68 return std::auto_ptr<EvictionPolicyEvaluator<MAPKEY, MAPVALUE, A, E> >(
69 new impl::evaluator::DefaultEvictionPolicyEvaluator<MAPKEY, MAPVALUE, A, E>(
70 evictionPolicyComparator));
74 template<
typename A,
typename E>
75 static boost::shared_ptr<EvictionPolicyComparator<A, E> > createEvictionPolicyComparator(
76 EvictionPolicyType evictionPolicyType) {
77 switch (evictionPolicyType) {
79 return boost::shared_ptr<EvictionPolicyComparator<A, E> >(
80 new impl::comparator::LRUEvictionPolicyComparator<A, E>());
82 return boost::shared_ptr<EvictionPolicyComparator<A, E> >(
83 new impl::comparator::LFUEvictionPolicyComparator<A, E>());
85 return boost::shared_ptr<EvictionPolicyComparator<A, E> >(
86 new impl::comparator::RandomEvictionPolicyComparator<A, E>());
88 return boost::shared_ptr<EvictionPolicyComparator<A, E> >();
90 std::ostringstream out;
91 out <<
"Unsupported eviction policy type: " << (int) evictionPolicyType;
92 throw exception::IllegalArgumentException(out.str());
97 EvictionPolicyEvaluatorProvider();
99 ~EvictionPolicyEvaluatorProvider();
107 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
Provider to get any kind (EvictionPolicyType) of EvictionPolicyEvaluator.
Definition: EvictionPolicyEvaluatorProvider.h:42
Definition: MapEntryView.h:32
static std::auto_ptr< EvictionPolicyEvaluator< MAPKEY, MAPVALUE, A, E > > getEvictionPolicyEvaluator(const boost::shared_ptr< EvictionConfiguration< MAPKEY, MAPVALUE > > &evictionConfig)
Gets the EvictionPolicyEvaluator implementation specified with.
Definition: EvictionPolicyEvaluatorProvider.h:52
Interface for configuration information about eviction.
Definition: EvictionConfiguration.h:38