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" 40 #include "hazelcast/client/spi/impl/ClientClusterServiceImpl.h" 42 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 44 #pragma warning(disable: 4251) //for dll export 64 typedef std::map<int, std::vector<boost::shared_ptr<serialization::pimpl::Data> > > PID_TO_KEY_MAP;
66 ClientMapProxy(
const std::string &instanceName, spi::ClientContext *context);
76 serialization::pimpl::Data keyData = toData(key);
77 return containsKeyInternal(keyData);
88 return proxy::IMapImpl::containsValue(toData(value));
100 serialization::pimpl::Data keyData = toData(key);
101 boost::shared_ptr<TypedData> value = getInternal(keyData);
114 template<
typename K,
typename V>
116 return put(key, value, -1);
130 template<
typename K,
typename V>
132 serialization::pimpl::Data keyData = toData(key);
133 serialization::pimpl::Data valueData = toData(value);
135 return TypedData(putInternal(keyData, valueData, ttlInMillis), context->getSerializationService());
147 serialization::pimpl::Data keyData = toData(key);
149 std::auto_ptr<serialization::pimpl::Data> response = removeInternal(keyData);
150 return TypedData(response, context->getSerializationService());
160 template<
typename K,
typename V>
161 bool remove(
const K &key,
const V &value) {
162 serialization::pimpl::Data keyData = toData(key);
163 serialization::pimpl::Data valueData = toData(value);
165 return removeInternal(keyData, valueData);
184 serialization::pimpl::Data keyData = toData(key);
186 deleteInternal(keyData);
207 serialization::pimpl::Data keyData = toData(key);
209 return tryRemoveInternal(keyData, timeoutInMillis);
224 template<
typename K,
typename V>
225 bool tryPut(
const K &key,
const V &value,
long timeoutInMillis) {
226 serialization::pimpl::Data keyData = toData(key);
227 serialization::pimpl::Data valueData = toData(value);
229 return tryPutInternal(keyData, valueData, timeoutInMillis);
241 template<
typename K,
typename V>
243 serialization::pimpl::Data keyData = toData(key);
244 serialization::pimpl::Data valueData = toData(value);
246 tryPutTransientInternal(keyData, valueData, ttlInMillis);
257 template<
typename K,
typename V>
259 return putIfAbsent(key, value, -1);
273 template<
typename K,
typename V>
275 serialization::pimpl::Data keyData = toData(key);
276 serialization::pimpl::Data valueData = toData(value);
278 std::auto_ptr<serialization::pimpl::Data> response = putIfAbsentInternal(keyData, valueData,
280 return TypedData(response, context->getSerializationService());
290 template<
typename K,
typename V,
typename NEWTYPE>
291 bool replace(
const K &key,
const V &oldValue,
const NEWTYPE &newValue) {
292 serialization::pimpl::Data keyData = toData(key);
293 serialization::pimpl::Data oldValueData = toData(oldValue);
294 serialization::pimpl::Data newValueData = toData(newValue);
296 return replaceIfSameInternal(keyData, oldValueData, newValueData);
306 template<
typename K,
typename V>
308 serialization::pimpl::Data keyData = toData(key);
309 serialization::pimpl::Data valueData = toData(value);
311 return TypedData(replaceInternal(keyData, valueData), context->getSerializationService());
321 template<
typename K,
typename V>
322 void set(
const K &key,
const V &value) {
335 template<
typename K,
typename V>
336 void set(
const K &key,
const V &value,
long ttl) {
337 serialization::pimpl::Data keyData = toData(key);
338 serialization::pimpl::Data valueData = toData(value);
340 setInternal(keyData, valueData, ttl);
381 void lock(
const K &key,
long leaseTime) {
382 serialization::pimpl::Data keyData = toData(key);
384 proxy::IMapImpl::lock(toData(key), leaseTime);
397 return proxy::IMapImpl::isLocked(toData(key));
411 return tryLock(key, 0);
431 bool tryLock(
const K &key,
long timeInMillis) {
432 return proxy::IMapImpl::tryLock(toData(key), timeInMillis);
450 proxy::IMapImpl::unlock(toData(key));
463 proxy::IMapImpl::forceUnlock(toData(key));
477 template<
typename MapInterceptor>
479 return proxy::IMapImpl::addInterceptor(interceptor);
488 void removeInterceptor(
const std::string &
id);
533 bool removeEntryListener(
const std::string ®istrationId);
550 serialization::pimpl::Data keyData = toData(key);
551 impl::MixedEntryEventHandler<protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
552 new impl::MixedEntryEventHandler<protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler>(
553 getName(), context->getClientClusterService(), context->getSerializationService(),
556 return proxy::IMapImpl::addEntryListener(entryEventHandler, keyData, includeValue);
568 std::auto_ptr<EntryView<TypedData, TypedData> >
getEntryView(
const K &key) {
569 std::auto_ptr<serialization::pimpl::Data> keyData(
new serialization::pimpl::Data(toData(key)));
570 std::auto_ptr<map::DataEntryView> dataEntryView = proxy::IMapImpl::getEntryViewData(*keyData);
571 if ((map::DataEntryView *) NULL == dataEntryView.get()) {
572 return std::auto_ptr<EntryView<TypedData, TypedData> >();
574 TypedData value(std::auto_ptr<serialization::pimpl::Data>(
575 new serialization::pimpl::Data(dataEntryView->getValue())),
576 context->getSerializationService());
577 const TypedData &keyTypedData =
TypedData(keyData, context->getSerializationService());
579 keyTypedData, value, *dataEntryView));
595 serialization::pimpl::Data keyData = toData(key);
597 return evictInternal(keyData);
620 std::vector<std::pair<TypedData, TypedData> >
getAll(
const std::set<K> &keys) {
622 return std::vector<std::pair<TypedData, TypedData> >();
625 PID_TO_KEY_MAP partitionToKeyData;
627 for (
typename std::set<K>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
629 serialization::pimpl::Data keyData = toData<K>(key);
631 int partitionId = getPartitionId(keyData);
633 partitionToKeyData[partitionId].push_back(toShared(keyData));
636 return toTypedDataEntrySet(getAllInternal(partitionToKeyData));
646 std::vector<TypedData> keySet();
686 template<
typename K,
typename V>
688 predicate.setIterationType(query::KEY);
690 std::vector<serialization::pimpl::Data> dataResult = keySetForPagingPredicateData(predicate);
692 EntryVector entryResult;
693 for (std::vector<serialization::pimpl::Data>::iterator it = dataResult.begin();
694 it != dataResult.end(); ++it) {
695 entryResult.push_back(std::pair<serialization::pimpl::Data, serialization::pimpl::Data>(*it,
696 serialization::pimpl::Data()));
699 client::impl::EntryArrayImpl<K, V> entries(entryResult, context->getSerializationService());
700 entries.sort(query::KEY, predicate.getComparator());
702 std::pair<size_t, size_t> range = updateAnchor<K, V>(entries, predicate, query::KEY);
704 std::vector<K> result;
705 for (
size_t i = range.first; i < range.second; ++i) {
706 result.push_back(*entries.getKey(i));
719 std::vector<TypedData> values();
752 template<
typename K,
typename V>
754 predicate.setIterationType(query::VALUE);
756 EntryVector dataResult = proxy::IMapImpl::valuesForPagingPredicateData(predicate);
758 client::impl::EntryArrayImpl<K, V> entries(dataResult, context->getSerializationService());
760 entries.sort(query::VALUE, predicate.getComparator());
762 std::pair<size_t, size_t> range = updateAnchor<K, V>(entries, predicate, query::VALUE);
764 std::vector<V> result;
765 for (
size_t i = range.first; i < range.second; ++i) {
766 result.push_back(*entries.getValue(i));
778 std::vector<std::pair<TypedData, TypedData> > entrySet();
792 std::vector<std::pair<TypedData, TypedData> >
805 std::vector<std::pair<TypedData, TypedData> > entrySet(
const query::Predicate &predicate);
817 template<
typename K,
typename V>
819 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult =
820 proxy::IMapImpl::entrySetForPagingPredicateData(predicate);
822 client::impl::EntryArrayImpl<K, V> entries(dataResult, context->getSerializationService());
823 entries.sort(query::ENTRY, predicate.getComparator());
825 std::pair<size_t, size_t> range = updateAnchor<K, V>(entries, predicate, query::ENTRY);
827 std::vector<std::pair<K, V> > result;
828 for (
size_t i = range.first; i < range.second; ++i) {
829 std::pair<const K *, const V *> entry = entries[i];
830 result.push_back(std::pair<K, V>(*entry.first, *entry.second));
867 void addIndex(
const std::string &attribute,
bool ordered);
883 template<
typename K,
typename EntryProcessor>
885 serialization::pimpl::Data keyData = toData(key);
886 serialization::pimpl::Data processorData = toData(entryProcessor);
888 std::auto_ptr<serialization::pimpl::Data> response = executeOnKeyInternal(keyData, processorData);
890 return TypedData(response, getSerializationService());
893 template<
typename K,
typename EntryProcessor>
894 Future<TypedData> submitToKey(
const K &key,
const EntryProcessor &entryProcessor) {
895 serialization::pimpl::Data keyData = toData(key);
896 serialization::pimpl::Data processorData = toData(entryProcessor);
898 return submitToKeyInternal<TypedData>(keyData, processorData);
901 template<
typename K,
typename EntryProcessor>
902 std::map<K, TypedData> executeOnKeys(
const std::set<K> &keys,
const EntryProcessor &entryProcessor) {
903 EntryVector entries = executeOnKeysInternal<K, EntryProcessor>(keys, entryProcessor);
905 std::map<K, TypedData> result;
906 serialization::pimpl::SerializationService &serializationService = getSerializationService();
907 for (
size_t i = 0; i < entries.size(); ++i) {
908 std::auto_ptr<K> keyObj = toObject<K>(entries[i].first);
909 result[*keyObj] =
TypedData(std::auto_ptr<serialization::pimpl::Data>(
910 new serialization::pimpl::Data(entries[i].second)), serializationService);
927 template<
typename EntryProcessor>
929 EntryVector entries = proxy::IMapImpl::executeOnEntriesData<EntryProcessor>(entryProcessor);
930 std::map<TypedData, TypedData> result;
931 for (
size_t i = 0; i < entries.size(); ++i) {
932 std::auto_ptr<serialization::pimpl::Data> keyData(
933 new serialization::pimpl::Data(entries[i].first));
934 std::auto_ptr<serialization::pimpl::Data> valueData(
935 new serialization::pimpl::Data(entries[i].second));
936 serialization::pimpl::SerializationService &serializationService = context->getSerializationService();
937 result[
TypedData(keyData, serializationService)] =
TypedData(valueData, serializationService);
956 template<
typename EntryProcessor>
957 std::map<TypedData, TypedData>
959 EntryVector entries = proxy::IMapImpl::executeOnEntriesData<EntryProcessor>(entryProcessor,
961 std::map<TypedData, TypedData> result;
962 for (
size_t i = 0; i < entries.size(); ++i) {
963 std::auto_ptr<serialization::pimpl::Data> keyData(
964 new serialization::pimpl::Data(entries[i].first));
965 std::auto_ptr<serialization::pimpl::Data> valueData(
966 new serialization::pimpl::Data(entries[i].second));
967 serialization::pimpl::SerializationService &serializationService = context->getSerializationService();
968 result[
TypedData(keyData, serializationService)] =
TypedData(valueData, serializationService);
1000 template<
typename K,
typename V>
1002 std::map<int, EntryVector> entryMap;
1004 for (
typename std::map<K, V>::const_iterator it = entries.begin(); it != entries.end(); ++it) {
1005 serialization::pimpl::Data keyData = toData(it->first);
1006 serialization::pimpl::Data valueData = toData(it->second);
1008 int partitionId = getPartitionId(keyData);
1010 entryMap[partitionId].push_back(std::make_pair(keyData, valueData));
1013 putAllInternal(entryMap);
1022 serialization::pimpl::SerializationService &getSerializationService()
const;
1027 virtual boost::shared_ptr<TypedData> getInternal(serialization::pimpl::Data &keyData);
1029 virtual bool containsKeyInternal(
const serialization::pimpl::Data &keyData);
1031 virtual std::auto_ptr<serialization::pimpl::Data> removeInternal(
1032 const serialization::pimpl::Data &keyData);
1034 virtual bool removeInternal(
1035 const serialization::pimpl::Data &keyData,
const serialization::pimpl::Data &valueData);
1037 virtual void removeAllInternal(
const serialization::pimpl::Data &predicateData);
1039 virtual void deleteInternal(
const serialization::pimpl::Data &keyData);
1041 virtual bool tryRemoveInternal(
const serialization::pimpl::Data &keyData,
long timeoutInMillis);
1043 virtual bool tryPutInternal(
const serialization::pimpl::Data &keyData,
1044 const serialization::pimpl::Data &valueData,
long timeoutInMillis);
1046 virtual std::auto_ptr<serialization::pimpl::Data> putInternal(
const serialization::pimpl::Data &keyData,
1047 const serialization::pimpl::Data &valueData,
1048 long timeoutInMillis);
1050 virtual void tryPutTransientInternal(
const serialization::pimpl::Data &keyData,
1051 const serialization::pimpl::Data &valueData,
int ttlInMillis);
1053 virtual std::auto_ptr<serialization::pimpl::Data>
1054 putIfAbsentInternal(
const serialization::pimpl::Data &keyData,
1055 const serialization::pimpl::Data &valueData,
1058 virtual bool replaceIfSameInternal(
const serialization::pimpl::Data &keyData,
1059 const serialization::pimpl::Data &valueData,
1060 const serialization::pimpl::Data &newValueData);
1062 virtual std::auto_ptr<serialization::pimpl::Data>
1063 replaceInternal(
const serialization::pimpl::Data &keyData,
1064 const serialization::pimpl::Data &valueData);
1067 setInternal(
const serialization::pimpl::Data &keyData,
const serialization::pimpl::Data &valueData,
1070 virtual bool evictInternal(
const serialization::pimpl::Data &keyData);
1072 virtual EntryVector getAllInternal(
const PID_TO_KEY_MAP &partitionToKeyData);
1074 virtual std::auto_ptr<serialization::pimpl::Data>
1075 executeOnKeyInternal(
const serialization::pimpl::Data &keyData,
1076 const serialization::pimpl::Data &processor);
1078 template<
typename ResultType>
1080 submitToKeyInternal(
const serialization::pimpl::Data &keyData,
1081 const serialization::pimpl::Data &processor) {
1082 int partitionId = getPartitionId(keyData);
1084 std::auto_ptr<protocol::ClientMessage> request =
1085 protocol::codec::MapSubmitToKeyCodec::encodeRequest(getName(),
1088 util::getCurrentThreadId());
1090 boost::shared_ptr<spi::impl::ClientInvocationFuture> clientInvocationFuture = invokeAndGetFuture(
1091 request, partitionId);
1094 submitToKeyDecoder);
1097 static std::auto_ptr<serialization::pimpl::Data> submitToKeyDecoder(protocol::ClientMessage &response);
1099 template<
typename K,
typename EntryProcessor>
1100 EntryVector executeOnKeysInternal(
const std::set<K> &keys,
const EntryProcessor &entryProcessor) {
1102 return EntryVector();
1105 std::vector<serialization::pimpl::Data> keysData;
1106 for (
typename std::set<K>::const_iterator it = keys.begin(); it != keys.end(); ++it) {
1107 keysData.push_back(toData<K>(*it));
1110 serialization::pimpl::Data entryProcessorData = toData<EntryProcessor>(entryProcessor);
1112 return proxy::IMapImpl::executeOnKeysData(keysData, entryProcessorData);
1116 putAllInternal(
const std::map<int, EntryVector> &entries);
1119 monitor::impl::LocalMapStatsImpl stats;
1125 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 1126 #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:753
bool containsValue(const V &value)
check if this map contains value.
Definition: ClientMapProxy.h:87
std::map< TypedData, TypedData > executeOnEntries(const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: ClientMapProxy.h:928
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:291
void lock(const K &key)
Acquires the lock for the specified key.
Definition: ClientMapProxy.h:358
bool evict(const K &key)
Evicts the specified key from this map.
Definition: ClientMapProxy.h:594
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:131
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:449
TypedData executeOnKey(const K &key, const EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: ClientMapProxy.h:884
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:115
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:818
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: ClientMapProxy.h:396
std::auto_ptr< EntryView< TypedData, TypedData > > getEntryView(const K &key)
Returns the EntryView for the specified key.
Definition: ClientMapProxy.h:568
std::string addEntryListener(const K &key, MixedEntryListener &listener, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: ClientMapProxy.h:549
bool containsKey(const K &key)
check if this map contains key.
Definition: ClientMapProxy.h:75
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:225
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:1001
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:687
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:242
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:258
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: ClientMapProxy.h:462
Concurrent, distributed, observable and queryable map client.
Definition: ClientMapProxy.h:62
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:274
Definition: MapEntryView.h:32
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: ClientMapProxy.h:410
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:206
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:381
bool tryLock(const K &key, long timeInMillis)
Tries to acquire the lock for the specified key.
Definition: ClientMapProxy.h:431
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: ClientMapProxy.h:478
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:620
TypedData replace(const K &key, const V &value)
Replaces the entry for a key only if currently mapped to some value.
Definition: ClientMapProxy.h:307
void deleteEntry(const K &key)
removes entry from map.
Definition: ClientMapProxy.h:183
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:958