16 #ifndef HAZELCAST_CLIENT_MIXEDTYPE_MAP_H_ 17 #define HAZELCAST_CLIENT_MIXEDTYPE_MAP_H_ 27 #include "hazelcast/client/TypedData.h" 28 #include "hazelcast/client/monitor/LocalMapStats.h" 29 #include "hazelcast/client/monitor/impl/NearCacheStatsImpl.h" 30 #include "hazelcast/client/monitor/impl/LocalMapStatsImpl.h" 31 #include "hazelcast/client/protocol/codec/MapAddEntryListenerWithPredicateCodec.h" 32 #include "hazelcast/client/impl/EntryArrayImpl.h" 33 #include "hazelcast/client/proxy/IMapImpl.h" 34 #include "hazelcast/client/impl/EntryEventHandler.h" 35 #include "hazelcast/client/EntryListener.h" 36 #include "hazelcast/client/EntryView.h" 37 #include "hazelcast/client/serialization/pimpl/SerializationService.h" 38 #include "hazelcast/client/Future.h" 39 #include "hazelcast/client/protocol/codec/MapSubmitToKeyCodec.h" 41 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 43 #pragma warning(disable: 4251) //for dll export 63 typedef std::map<int, std::vector<boost::shared_ptr<serialization::pimpl::Data> > > PID_TO_KEY_MAP;
65 ClientMapProxy(
const std::string &instanceName, spi::ClientContext *context);
75 serialization::pimpl::Data keyData = toData<K>(key);
76 return containsKeyInternal(keyData);
87 return proxy::IMapImpl::containsValue(toData<V>(value));
99 serialization::pimpl::Data keyData = toData<K>(key);
100 boost::shared_ptr<TypedData> value = getInternal(keyData);
113 template<
typename K,
typename V>
115 return put(key, value, -1);
129 template<
typename K,
typename V>
131 serialization::pimpl::Data keyData = toData<K>(key);
132 serialization::pimpl::Data valueData = toData<V>(value);
134 return TypedData(putInternal(keyData, valueData, ttlInMillis), getContext().getSerializationService());
146 serialization::pimpl::Data keyData = toData<K>(key);
148 std::auto_ptr<serialization::pimpl::Data> response = removeInternal(keyData);
149 return TypedData(response, getContext().getSerializationService());
159 template<
typename K,
typename V>
160 bool remove(
const K &key,
const V &value) {
161 serialization::pimpl::Data keyData = toData<K>(key);
162 serialization::pimpl::Data valueData = toData<V>(value);
164 return removeInternal(keyData, valueData);
183 serialization::pimpl::Data keyData = toData<K>(key);
185 deleteInternal(keyData);
206 serialization::pimpl::Data keyData = toData<K>(key);
208 return tryRemoveInternal(keyData, timeoutInMillis);
223 template<
typename K,
typename V>
224 bool tryPut(
const K &key,
const V &value,
long timeoutInMillis) {
225 serialization::pimpl::Data keyData = toData<K>(key);
226 serialization::pimpl::Data valueData = toData<V>(value);
228 return tryPutInternal(keyData, valueData, timeoutInMillis);
240 template<
typename K,
typename V>
242 serialization::pimpl::Data keyData = toData<K>(key);
243 serialization::pimpl::Data valueData = toData<V>(value);
245 tryPutTransientInternal(keyData, valueData, ttlInMillis);
256 template<
typename K,
typename V>
258 return putIfAbsent(key, value, -1);
272 template<
typename K,
typename V>
274 serialization::pimpl::Data keyData = toData<K>(key);
275 serialization::pimpl::Data valueData = toData<V>(value);
277 std::auto_ptr<serialization::pimpl::Data> response = putIfAbsentInternal(keyData, valueData,
279 return TypedData(response, getContext().getSerializationService());
289 template<
typename K,
typename V,
typename NEWTYPE>
290 bool replace(
const K &key,
const V &oldValue,
const NEWTYPE &newValue) {
291 serialization::pimpl::Data keyData = toData<K>(key);
292 serialization::pimpl::Data oldValueData = toData<V>(oldValue);
293 serialization::pimpl::Data newValueData = toData<NEWTYPE>(newValue);
295 return replaceIfSameInternal(keyData, oldValueData, newValueData);
305 template<
typename K,
typename V>
307 serialization::pimpl::Data keyData = toData<K>(key);
308 serialization::pimpl::Data valueData = toData<V>(value);
310 return TypedData(replaceInternal(keyData, valueData), getContext().getSerializationService());
320 template<
typename K,
typename V>
321 void set(
const K &key,
const V &value) {
334 template<
typename K,
typename V>
335 void set(
const K &key,
const V &value,
long ttl) {
336 serialization::pimpl::Data keyData = toData<K>(key);
337 serialization::pimpl::Data valueData = toData<V>(value);
339 setInternal(keyData, valueData, ttl);
380 void lock(
const K &key,
long leaseTime) {
381 serialization::pimpl::Data keyData = toData<K>(key);
383 proxy::IMapImpl::lock(keyData, leaseTime);
396 return proxy::IMapImpl::isLocked(toData<K>(key));
410 return tryLock(key, 0);
430 bool tryLock(
const K &key,
long timeInMillis) {
431 return proxy::IMapImpl::tryLock(toData<K>(key), timeInMillis);
449 proxy::IMapImpl::unlock(toData<K>(key));
462 proxy::IMapImpl::forceUnlock(toData<K>(key));
476 template<
typename MapInterceptor>
478 return proxy::IMapImpl::addInterceptor(interceptor);
487 void removeInterceptor(
const std::string &
id);
532 bool removeEntryListener(
const std::string ®istrationId);
549 serialization::pimpl::Data keyData = toData<K>(key);
550 impl::MixedEntryEventHandler<protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
551 new impl::MixedEntryEventHandler<protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler>(
552 getName(), getContext().getClientClusterService(), getContext().getSerializationService(),
555 return proxy::IMapImpl::addEntryListener(entryEventHandler, keyData, includeValue);
567 std::auto_ptr<EntryView<TypedData, TypedData> >
getEntryView(
const K &key) {
568 std::auto_ptr<serialization::pimpl::Data> keyData(
new serialization::pimpl::Data(toData<K>(key)));
569 std::auto_ptr<map::DataEntryView> dataEntryView = proxy::IMapImpl::getEntryViewData(*keyData);
570 if ((map::DataEntryView *) NULL == dataEntryView.get()) {
571 return std::auto_ptr<EntryView<TypedData, TypedData> >();
573 TypedData value(std::auto_ptr<serialization::pimpl::Data>(
574 new serialization::pimpl::Data(dataEntryView->getValue())),
575 getContext().getSerializationService());
576 const TypedData &keyTypedData =
TypedData(keyData, getContext().getSerializationService());
578 keyTypedData, value, *dataEntryView));
594 serialization::pimpl::Data keyData = toData<K>(key);
596 return evictInternal(keyData);
619 std::vector<std::pair<TypedData, TypedData> >
getAll(
const std::set<K> &keys) {
621 return std::vector<std::pair<TypedData, TypedData> >();
624 PID_TO_KEY_MAP partitionToKeyData;
626 for (
typename std::set<K>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
628 serialization::pimpl::Data keyData = toData<K>(key);
630 int partitionId = getPartitionId(keyData);
632 partitionToKeyData[partitionId].push_back(toShared(keyData));
635 return toTypedDataEntrySet(getAllInternal(partitionToKeyData));
645 std::vector<TypedData> keySet();
685 template<
typename K,
typename V>
687 predicate.setIterationType(query::KEY);
689 std::vector<serialization::pimpl::Data> dataResult = keySetForPagingPredicateData(predicate);
691 EntryVector entryResult;
692 for (std::vector<serialization::pimpl::Data>::iterator it = dataResult.begin();
693 it != dataResult.end(); ++it) {
694 entryResult.push_back(std::pair<serialization::pimpl::Data, serialization::pimpl::Data>(*it,
695 serialization::pimpl::Data()));
698 client::impl::EntryArrayImpl<K, V> entries(entryResult, getContext().getSerializationService());
699 entries.sort(query::KEY, predicate.getComparator());
701 std::pair<size_t, size_t> range = updateAnchor<K, V>(entries, predicate, query::KEY);
703 std::vector<K> result;
704 for (
size_t i = range.first; i < range.second; ++i) {
705 result.push_back(*entries.getKey(i));
718 std::vector<TypedData> values();
751 template<
typename K,
typename V>
753 predicate.setIterationType(query::VALUE);
755 EntryVector dataResult = proxy::IMapImpl::valuesForPagingPredicateData(predicate);
757 client::impl::EntryArrayImpl<K, V> entries(dataResult, getContext().getSerializationService());
759 entries.sort(query::VALUE, predicate.getComparator());
761 std::pair<size_t, size_t> range = updateAnchor<K, V>(entries, predicate, query::VALUE);
763 std::vector<V> result;
764 for (
size_t i = range.first; i < range.second; ++i) {
765 result.push_back(*entries.getValue(i));
777 std::vector<std::pair<TypedData, TypedData> > entrySet();
791 std::vector<std::pair<TypedData, TypedData> >
804 std::vector<std::pair<TypedData, TypedData> > entrySet(
const query::Predicate &predicate);
816 template<
typename K,
typename V>
818 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult =
819 proxy::IMapImpl::entrySetForPagingPredicateData(predicate);
821 client::impl::EntryArrayImpl<K, V> entries(dataResult, getContext().getSerializationService());
822 entries.sort(query::ENTRY, predicate.getComparator());
824 std::pair<size_t, size_t> range = updateAnchor<K, V>(entries, predicate, query::ENTRY);
826 std::vector<std::pair<K, V> > result;
827 for (
size_t i = range.first; i < range.second; ++i) {
828 std::pair<const K *, const V *> entry = entries[i];
829 result.push_back(std::pair<K, V>(*entry.first, *entry.second));
866 void addIndex(
const std::string &attribute,
bool ordered);
882 template<
typename K,
typename EntryProcessor>
884 serialization::pimpl::Data keyData = toData<K>(key);
885 serialization::pimpl::Data processorData = toData<EntryProcessor>(entryProcessor);
887 std::auto_ptr<serialization::pimpl::Data> response = executeOnKeyInternal(keyData, processorData);
889 return TypedData(response, getSerializationService());
892 template<
typename K,
typename EntryProcessor>
893 Future<TypedData> submitToKey(
const K &key,
const EntryProcessor &entryProcessor) {
894 serialization::pimpl::Data keyData = toData<K>(key);
895 serialization::pimpl::Data processorData = toData<EntryProcessor>(entryProcessor);
897 return submitToKeyInternal<TypedData>(keyData, processorData);
900 template<
typename K,
typename EntryProcessor>
901 std::map<K, TypedData> executeOnKeys(
const std::set<K> &keys,
const EntryProcessor &entryProcessor) {
902 EntryVector entries = executeOnKeysInternal<K, EntryProcessor>(keys, entryProcessor);
904 std::map<K, TypedData> result;
905 serialization::pimpl::SerializationService &serializationService = getSerializationService();
906 for (
size_t i = 0; i < entries.size(); ++i) {
907 std::auto_ptr<K> keyObj = toObject<K>(entries[i].first);
908 result[*keyObj] =
TypedData(std::auto_ptr<serialization::pimpl::Data>(
909 new serialization::pimpl::Data(entries[i].second)), serializationService);
926 template<
typename EntryProcessor>
928 EntryVector entries = proxy::IMapImpl::executeOnEntriesData<EntryProcessor>(entryProcessor);
929 std::map<TypedData, TypedData> result;
930 for (
size_t i = 0; i < entries.size(); ++i) {
931 std::auto_ptr<serialization::pimpl::Data> keyData(
932 new serialization::pimpl::Data(entries[i].first));
933 std::auto_ptr<serialization::pimpl::Data> valueData(
934 new serialization::pimpl::Data(entries[i].second));
935 serialization::pimpl::SerializationService &serializationService = getContext().getSerializationService();
936 result[
TypedData(keyData, serializationService)] =
TypedData(valueData, serializationService);
955 template<
typename EntryProcessor>
956 std::map<TypedData, TypedData>
958 EntryVector entries = proxy::IMapImpl::executeOnEntriesData<EntryProcessor>(entryProcessor,
960 std::map<TypedData, TypedData> result;
961 for (
size_t i = 0; i < entries.size(); ++i) {
962 std::auto_ptr<serialization::pimpl::Data> keyData(
963 new serialization::pimpl::Data(entries[i].first));
964 std::auto_ptr<serialization::pimpl::Data> valueData(
965 new serialization::pimpl::Data(entries[i].second));
966 serialization::pimpl::SerializationService &serializationService = getContext().getSerializationService();
967 result[
TypedData(keyData, serializationService)] =
TypedData(valueData, serializationService);
999 template<
typename K,
typename V>
1001 std::map<int, EntryVector> entryMap;
1003 for (
typename std::map<K, V>::const_iterator it = entries.begin(); it != entries.end(); ++it) {
1004 serialization::pimpl::Data keyData = toData<K>(it->first);
1005 serialization::pimpl::Data valueData = toData<V>(it->second);
1007 int partitionId = getPartitionId(keyData);
1009 entryMap[partitionId].push_back(std::make_pair(keyData, valueData));
1012 putAllInternal(entryMap);
1021 serialization::pimpl::SerializationService &getSerializationService();
1026 virtual boost::shared_ptr<TypedData> getInternal(serialization::pimpl::Data &keyData);
1028 virtual bool containsKeyInternal(
const serialization::pimpl::Data &keyData);
1030 virtual std::auto_ptr<serialization::pimpl::Data> removeInternal(
1031 const serialization::pimpl::Data &keyData);
1033 virtual bool removeInternal(
1034 const serialization::pimpl::Data &keyData,
const serialization::pimpl::Data &valueData);
1036 virtual void removeAllInternal(
const serialization::pimpl::Data &predicateData);
1038 virtual void deleteInternal(
const serialization::pimpl::Data &keyData);
1040 virtual bool tryRemoveInternal(
const serialization::pimpl::Data &keyData,
long timeoutInMillis);
1042 virtual bool tryPutInternal(
const serialization::pimpl::Data &keyData,
1043 const serialization::pimpl::Data &valueData,
long timeoutInMillis);
1045 virtual std::auto_ptr<serialization::pimpl::Data> putInternal(
const serialization::pimpl::Data &keyData,
1046 const serialization::pimpl::Data &valueData,
1047 long timeoutInMillis);
1049 virtual void tryPutTransientInternal(
const serialization::pimpl::Data &keyData,
1050 const serialization::pimpl::Data &valueData,
int ttlInMillis);
1052 virtual std::auto_ptr<serialization::pimpl::Data>
1053 putIfAbsentInternal(
const serialization::pimpl::Data &keyData,
1054 const serialization::pimpl::Data &valueData,
1057 virtual bool replaceIfSameInternal(
const serialization::pimpl::Data &keyData,
1058 const serialization::pimpl::Data &valueData,
1059 const serialization::pimpl::Data &newValueData);
1061 virtual std::auto_ptr<serialization::pimpl::Data>
1062 replaceInternal(
const serialization::pimpl::Data &keyData,
1063 const serialization::pimpl::Data &valueData);
1066 setInternal(
const serialization::pimpl::Data &keyData,
const serialization::pimpl::Data &valueData,
1069 virtual bool evictInternal(
const serialization::pimpl::Data &keyData);
1071 virtual EntryVector getAllInternal(
const PID_TO_KEY_MAP &partitionToKeyData);
1073 virtual std::auto_ptr<serialization::pimpl::Data>
1074 executeOnKeyInternal(
const serialization::pimpl::Data &keyData,
1075 const serialization::pimpl::Data &processor);
1077 template<
typename ResultType>
1079 submitToKeyInternal(
const serialization::pimpl::Data &keyData,
1080 const serialization::pimpl::Data &processor) {
1081 int partitionId = getPartitionId(keyData);
1083 std::auto_ptr<protocol::ClientMessage> request =
1084 protocol::codec::MapSubmitToKeyCodec::encodeRequest(getName(),
1087 util::getCurrentThreadId());
1089 boost::shared_ptr<spi::impl::ClientInvocationFuture> clientInvocationFuture = invokeAndGetFuture(
1090 request, partitionId);
1093 submitToKeyDecoder);
1096 static std::auto_ptr<serialization::pimpl::Data> submitToKeyDecoder(protocol::ClientMessage &response);
1098 template<
typename K,
typename EntryProcessor>
1099 EntryVector executeOnKeysInternal(
const std::set<K> &keys,
const EntryProcessor &entryProcessor) {
1101 return EntryVector();
1104 std::vector<serialization::pimpl::Data> keysData;
1105 for (
typename std::set<K>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
1106 keysData.push_back(toData<K>(*it));
1109 serialization::pimpl::Data entryProcessorData = toData<EntryProcessor>(entryProcessor);
1111 return proxy::IMapImpl::executeOnKeysData(keysData, entryProcessorData);
1115 putAllInternal(
const std::map<int, EntryVector> &entries);
1118 monitor::impl::LocalMapStatsImpl stats;
1124 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 1125 #pragma warning(pop) std::vector< V > values(query::PagingPredicate< K, V > &predicate)
Returns a vector clone of the values contained in this map.
Definition: ClientMapProxy.h:752
bool containsValue(const V &value)
check if this map contains value.
Definition: ClientMapProxy.h:86
std::map< TypedData, TypedData > executeOnEntries(const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: ClientMapProxy.h:927
bool replace(const K &key, const V &oldValue, const NEWTYPE &newValue)
Replaces the entry for a key only if currently mapped to a given value.
Definition: ClientMapProxy.h:290
void lock(const K &key)
Acquires the lock for the specified key.
Definition: ClientMapProxy.h:357
bool evict(const K &key)
Evicts the specified key from this map.
Definition: ClientMapProxy.h:593
Definition: LocalMapStats.h:31
TypedData put(const K &key, const V &value, long ttlInMillis)
Puts an entry into this map with a given ttl (time to live) value.
Definition: ClientMapProxy.h:130
Definition: EntryListener.h:108
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:47
void unlock(const K &key)
Releases the lock for the specified key.
Definition: ClientMapProxy.h:448
TypedData executeOnKey(const K &key, const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: ClientMapProxy.h:883
NOTE: PagingPredicate can only be used with values(), keySet() and entries() methods!!! ...
Definition: PagingPredicate.h:127
TypedData put(const K &key, const V &value)
put new entry into map.
Definition: ClientMapProxy.h:114
std::vector< std::pair< K, V > > entrySet(query::PagingPredicate< K, V > &predicate)
Queries the map based on the specified predicate and returns the matching entries.
Definition: ClientMapProxy.h:817
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: ClientMapProxy.h:395
std::auto_ptr< EntryView< TypedData, TypedData > > getEntryView(const K &key)
Returns the EntryView for the specified key.
Definition: ClientMapProxy.h:567
std::string addEntryListener(const K &key, MixedEntryListener &listener, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: ClientMapProxy.h:548
bool containsKey(const K &key)
check if this map contains key.
Definition: ClientMapProxy.h:74
bool tryPut(const K &key, const V &value, long timeoutInMillis)
Tries to put the given key, value into this map within specified timeout value.
Definition: ClientMapProxy.h:224
void putAll(const std::map< K, V > &entries)
Copies all of the mappings from the specified map to this map (optional operation).
Definition: ClientMapProxy.h:1000
std::vector< K > keySet(query::PagingPredicate< K, V > &predicate)
Queries the map based on the specified predicate and returns the keys of matching entries...
Definition: ClientMapProxy.h:686
This is a unique Future.
Definition: Future.h:105
void putTransient(const K &key, const V &value, long ttlInMillis)
Same as put(K, V, long, TimeUnit) but MapStore, if defined, will not be called to store/persist the e...
Definition: ClientMapProxy.h:241
This is a marker class for Predicate classes.
Definition: Predicate.h:36
EntryView represents a readonly view of a map entry.
Definition: EntryView.h:41
TypedData putIfAbsent(const K &key, const V &value)
Puts an entry into this map, if the specified key is not already associated with a value...
Definition: ClientMapProxy.h:257
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: ClientMapProxy.h:461
Concurrent, distributed, observable and queryable map client.
Definition: ClientMapProxy.h:61
TypedData putIfAbsent(const K &key, const V &value, long ttlInMillis)
Puts an entry into this map with a given ttl (time to live) value if the specified key is not already...
Definition: ClientMapProxy.h:273
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: ClientMapProxy.h:409
bool tryRemove(const K &key, long timeoutInMillis)
Tries to remove the entry with the given key from this map within specified timeout value...
Definition: ClientMapProxy.h:205
This specialization overwrites the get method to return TypedData.
Definition: Future.h:230
void lock(const K &key, long leaseTime)
Acquires the lock for the specified key for the specified lease time.
Definition: ClientMapProxy.h:380
bool tryLock(const K &key, long timeInMillis)
Tries to acquire the lock for the specified key.
Definition: ClientMapProxy.h:430
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: ClientMapProxy.h:477
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40
std::vector< std::pair< TypedData, TypedData > > getAll(const std::set< K > &keys)
Returns the entries for the given keys.
Definition: ClientMapProxy.h:619
TypedData replace(const K &key, const V &value)
Replaces the entry for a key only if currently mapped to some value.
Definition: ClientMapProxy.h:306
void deleteEntry(const K &key)
removes entry from map.
Definition: ClientMapProxy.h:182
std::map< TypedData, TypedData > executeOnEntries(const EntryProcessor &entryProcessor, const query::Predicate &predicate)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: ClientMapProxy.h:957