17 #include "hazelcast/client/internal/nearcache/impl/KeyStateMarkerImpl.h"
18 #include "hazelcast/client/internal/nearcache/NearCacheManager.h"
19 #include "hazelcast/util/HashUtil.h"
20 #include "hazelcast/client/internal/eviction/EvictionChecker.h"
27 NearCacheManager::NearCacheManager(
28 const std::shared_ptr<spi::impl::ClientExecutionServiceImpl>& es,
29 serialization::pimpl::SerializationService& ss,
31 : execution_service_(es)
32 , serialization_service_(ss)
37 NearCacheManager::clear_near_cache(
const std::string& name)
39 std::shared_ptr<BaseNearCache> nearCache = near_cache_map_.get(name);
40 if (nearCache.get() != NULL) {
43 return nearCache.get() != NULL;
47 NearCacheManager::clear_all_near_caches()
49 std::vector<std::shared_ptr<BaseNearCache>> caches =
50 near_cache_map_.values();
51 for (std::vector<std::shared_ptr<BaseNearCache>>::iterator it =
60 NearCacheManager::destroy_near_cache(
const std::string& name)
62 std::shared_ptr<BaseNearCache> nearCache = near_cache_map_.remove(name);
63 if (nearCache.get() != NULL) {
66 return nearCache.get() != NULL;
70 NearCacheManager::destroy_all_near_caches()
72 std::vector<std::shared_ptr<BaseNearCache>> caches =
73 near_cache_map_.values();
74 for (std::vector<std::shared_ptr<BaseNearCache>>::iterator it =
82 std::vector<std::shared_ptr<BaseNearCache>>
83 NearCacheManager::list_all_near_caches()
85 return near_cache_map_.values();
90 NearCacheDataRecord::NearCacheDataRecord(
91 const std::shared_ptr<serialization::pimpl::data>& data_value,
94 : AbstractNearCacheRecord<serialization::pimpl::data>(data_value,
100 KeyStateMarkerImpl::KeyStateMarkerImpl(
int count)
102 , marks_(new std::atomic<int32_t>[count])
104 for (
int i = 0; i < count; ++i) {
109 KeyStateMarkerImpl::~KeyStateMarkerImpl()
115 KeyStateMarkerImpl::try_mark(
const serialization::pimpl::data& key)
117 return cas_state(key, UNMARKED, MARKED);
121 KeyStateMarkerImpl::try_unmark(
const serialization::pimpl::data& key)
123 return cas_state(key, MARKED, UNMARKED);
127 KeyStateMarkerImpl::try_remove(
const serialization::pimpl::data& key)
129 return cas_state(key, MARKED, REMOVED);
133 KeyStateMarkerImpl::force_unmark(
const serialization::pimpl::data& key)
135 int slot = get_slot(key);
136 marks_[slot] = UNMARKED;
140 KeyStateMarkerImpl::init()
142 for (
int i = 0; i < mark_count_; ++i) {
143 marks_[i] = UNMARKED;
148 KeyStateMarkerImpl::cas_state(
const serialization::pimpl::data& key,
152 int slot = get_slot(key);
153 int expected = expect;
154 return marks_[slot].compare_exchange_strong(expected, update);
158 KeyStateMarkerImpl::get_slot(
const serialization::pimpl::data& key)
160 return util::HashUtil::hash_to_index(key.get_partition_hash(), mark_count_);
168 EvictAlways::is_eviction_required()
const
174 const std::unique_ptr<EvictionChecker> EvictionChecker::EVICT_ALWAYS =
175 std::unique_ptr<EvictionChecker>(
new EvictAlways());
181 namespace nearcache {
183 TrueMarkerImpl::try_mark(
const serialization::pimpl::data& key)
189 TrueMarkerImpl::try_unmark(
const serialization::pimpl::data& key)
195 TrueMarkerImpl::try_remove(
const serialization::pimpl::data& key)
201 TrueMarkerImpl::force_unmark(
const serialization::pimpl::data& key)
205 TrueMarkerImpl::init()
208 const std::unique_ptr<KeyStateMarker> KeyStateMarker::TRUE_MARKER =
209 std::unique_ptr<KeyStateMarker>(
new TrueMarkerImpl());