Hazelcast C++ Client
EvictionStrategyProvider.h
1 /*
2  * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HAZELCAST_CLIENT_INTERNAL_EVICTION_EVICTIONSTRATEGYPROVIDER_H_
17 #define HAZELCAST_CLIENT_INTERNAL_EVICTION_EVICTIONSTRATEGYPROVIDER_H_
18 
19 #include <assert.h>
20 #include <map>
21 
22 #include "hazelcast/client/internal/eviction/EvictionStrategyType.h"
23 #include "hazelcast/client/internal/eviction/EvictionStrategy.h"
24 #include "hazelcast/client/internal/eviction/EvictionConfiguration.h"
25 #include "hazelcast/client/internal/eviction/impl/strategy/sampling/SamplingBasedEvictionStrategy.h"
26 
27 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
28 #pragma warning(push)
29 #pragma warning(disable: 4251) //for dll export
30 #endif
31 
32 namespace hazelcast {
33  namespace client {
34  namespace internal {
35  namespace eviction {
39  template<typename MAPKEY, typename MAPVALUE, typename A, typename E, typename S>
41  public:
48  static boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> > getEvictionStrategy(
49  const boost::shared_ptr<EvictionConfiguration<MAPKEY, MAPVALUE> > &evictionConfig) {
50  if (evictionConfig.get() == NULL) {
51  return boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> >();
52  }
53  EvictionStrategyType::Type evictionStrategyType = evictionConfig->getEvictionStrategyType();
54 
56 
57  // TODO "evictionStrategyFactory" can be handled here from a single point
58  // for user defined custom implementations.
59  // So "EvictionStrategy" implementation can be taken from user defined factory.
60  }
61 
67  static boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> > &getDefaultEvictionStrategy() {
69  }
70 
71  static std::map<EvictionStrategyType::Type, boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> > > init() {
72  std::map<EvictionStrategyType::Type, boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> > > map;
73  map[EvictionStrategyType::SAMPLING_BASED_EVICTION] = boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> >(new impl::strategy::sampling::SamplingBasedEvictionStrategy<MAPKEY, MAPVALUE, A, E, S>());
74  return map;
75  }
76 
77  private:
78  static std::map<EvictionStrategyType::Type, boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> > > EVICTION_STRATEGY_MAP;
79  };
80 
81  template<typename MAPKEY, typename MAPVALUE, typename A, typename E, typename S>
82  std::map<EvictionStrategyType::Type, boost::shared_ptr<EvictionStrategy<MAPKEY, MAPVALUE, A, E, S> > > EvictionStrategyProvider<MAPKEY, MAPVALUE, A, E, S>::EVICTION_STRATEGY_MAP = EvictionStrategyProvider<MAPKEY, MAPVALUE, A, E, S>::init();
83  }
84  }
85  }
86 };
87 
88 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
89 #pragma warning(pop)
90 #endif
91 
92 #endif /* HAZELCAST_CLIENT_INTERNAL_EVICTION_EVICTIONSTRATEGYPROVIDER_H_ */
Provider to get any kind (EvictionStrategyType) of EvictionStrategy.
Definition: EvictionStrategyProvider.h:40
static boost::shared_ptr< EvictionStrategy< MAPKEY, MAPVALUE, A, E, S > > getEvictionStrategy(const boost::shared_ptr< EvictionConfiguration< MAPKEY, MAPVALUE > > &evictionConfig)
Gets the EvictionStrategy implementation specified with evictionStrategyType.
Definition: EvictionStrategyProvider.h:48
Sampling based eviction strategy type.
Definition: EvictionStrategyType.h:39
Definition: MapEntryView.h:32
static const Type DEFAULT_EVICTION_STRATEGY
Default value of com.hazelcast.internal.eviction.EvictionStrategyType.
Definition: EvictionStrategyType.h:44
static boost::shared_ptr< EvictionStrategy< MAPKEY, MAPVALUE, A, E, S > > & getDefaultEvictionStrategy()
Gets the default EvictionStrategy implementation.
Definition: EvictionStrategyProvider.h:67
Interface for configuration information about eviction.
Definition: EvictionConfiguration.h:38