16 #ifndef HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMAP_H_
17 #define HAZELCAST_CLIENT_ADAPTOR_RAWPOINTERMAP_H_
19 #include "hazelcast/client/IMap.h"
20 #include "hazelcast/client/adaptor/MapEntryView.h"
21 #include "hazelcast/client/impl/DataArrayImpl.h"
22 #include "hazelcast/client/impl/EntryArrayImpl.h"
23 #include "hazelcast/client/impl/EntryArrayKeyAdaptor.h"
24 #include "hazelcast/client/impl/EntryArrayValueAdaptor.h"
26 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
28 #pragma warning(disable: 4251) //for dll export
49 template<
typename K,
typename V>
53 map.context->getSerializationService()) {
63 return map.containsKey(key);
73 return map.containsValue(value);
83 std::auto_ptr<V>
get(
const K &key) {
84 return serializationService.toObject<V>(map.getData(serializationService.toData<K>(&key)).get());
95 std::auto_ptr<V>
put(
const K &key,
const V &value) {
96 return serializationService.toObject<V>(
97 map.putData(serializationService.toData<K>(&key),
98 serializationService.toData<V>(&value)).get());
108 std::auto_ptr<V>
remove(
const K &key) {
109 return serializationService.toObject<V>(map.removeData(serializationService.toData<K>(&key)).get());
119 bool remove(
const K &key,
const V &value) {
120 return map.remove(key, value);
130 map.deleteEntry(key);
152 return map.tryRemove(key, timeoutInMillis);
167 bool tryPut(
const K &key,
const V &value,
long timeoutInMillis) {
168 return map.tryPut(key, value, timeoutInMillis);
182 std::auto_ptr<V>
put(
const K &key,
const V &value,
long ttlInMillis) {
183 return serializationService.toObject<V>(
184 map.putData(serializationService.toData<K>(&key), serializationService.toData<V>(&value),
198 map.putTransient(key, value, ttlInMillis);
210 return serializationService.toObject<V>(map.putIfAbsentData(serializationService.toData<K>(&key),
211 serializationService.toData<V>(&value),
226 std::auto_ptr<V>
putIfAbsent(
const K &key,
const V &value,
long ttlInMillis) {
227 return serializationService.toObject<V>(
228 map.putIfAbsentData(serializationService.toData<K>(&key),
229 serializationService.toData<V>(&value),
240 bool replace(
const K &key,
const V &oldValue,
const V &newValue) {
241 return map.replace(key, oldValue, newValue);
251 std::auto_ptr<V>
replace(
const K &key,
const V &value) {
252 return serializationService.toObject<V>(
253 map.replaceData(serializationService.toData<K>(&key), serializationService.toData<V>(&value)).get());
265 void set(
const K &key,
const V &value,
long ttl) {
266 map.set(key, value, ttl);
305 void lock(
const K &key,
long leaseTime) {
306 map.lock(key, leaseTime);
318 return map.isLocked(key);
331 return map.tryLock(key, 0);
350 bool tryLock(
const K &key,
long timeInMillis) {
351 return map.tryLock(key, timeInMillis);
380 map.forceUnlock(key);
394 template<
typename MapInterceptor>
396 return map.template addInterceptor<MapInterceptor>(interceptor);
406 map.removeInterceptor(
id);
424 return map.addEntryListener(listener, includeValue);
437 return map.removeEntryListener(registrationId);
455 return map.addEntryListener(listener, key, includeValue);
467 std::auto_ptr<map::DataEntryView> dataView = map.getEntryViewData(serializationService.toData<K>(&key));
468 return std::auto_ptr<MapEntryView<K, V> >(
new MapEntryView<K, V>(dataView, serializationService));
482 return map.evict(key);
506 std::auto_ptr<EntryArray<K, V> >
getAll(
const std::set<K> &keys) {
507 std::vector<serialization::pimpl::Data> allKeys(keys.size());
509 for (
typename std::set<K>::iterator it = keys.begin(); it != keys.end(); ++it) {
510 allKeys[i++] = serializationService.toData<K>(&(*it));
512 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> >
entrySet = map.getAllData(
515 return std::auto_ptr<EntryArray<K, V> >(
new client::impl::EntryArrayImpl<K, V>(
entrySet, serializationService));
526 std::vector<serialization::pimpl::Data> dataResult = map.keySetData();
527 return std::auto_ptr<DataArray<K> >(
new client::impl::DataArrayImpl<K>(dataResult, serializationService));
541 std::vector<serialization::pimpl::Data> dataResult = map.keySetData(predicate);
542 return std::auto_ptr<DataArray<K> >(
new client::impl::DataArrayImpl<K>(dataResult, serializationService));
557 predicate.setIterationType(query::KEY);
559 std::vector<serialization::pimpl::Data> dataResult = map.keySetForPagingPredicateData(predicate);
561 EntryVector entryResult;
562 for (std::vector<serialization::pimpl::Data>::iterator it = dataResult.begin();it != dataResult.end(); ++it) {
563 entryResult.push_back(std::pair<serialization::pimpl::Data, serialization::pimpl::Data>(*it, serialization::pimpl::Data()));
566 client::impl::EntryArrayImpl<K, V> entries(entryResult, serializationService);
568 entries.sort(query::KEY, predicate.getComparator());
570 std::pair<size_t, size_t> range = map.template updateAnchor<K, V>(entries, predicate, query::KEY);
572 std::auto_ptr<EntryArray<K, V> > subList(
new client::impl::EntryArrayImpl<K, V>(entries, range.first, range.second));
574 std::auto_ptr<DataArray<K> > result = std::auto_ptr<DataArray<K> >(
new impl::EntryArrayKeyAdaptor<K, V>(subList));
587 std::vector<serialization::pimpl::Data> dataResult = map.valuesData();
588 return std::auto_ptr<DataArray<V> >(
new client::impl::DataArrayImpl<V>(dataResult, serializationService));
600 std::vector<serialization::pimpl::Data> dataResult = map.valuesData(predicate);
601 return std::auto_ptr<DataArray<V> >(
new client::impl::DataArrayImpl<V>(dataResult, serializationService));
613 predicate.setIterationType(query::VALUE);
615 EntryVector entryResult = map.valuesForPagingPredicateData(predicate);
617 client::impl::EntryArrayImpl<K, V> entries(entryResult, serializationService);
619 entries.sort(query::VALUE, predicate.getComparator());
621 std::pair<size_t, size_t> range = map.template updateAnchor<K, V>(entries, predicate, query::VALUE);
623 std::auto_ptr<EntryArray<K, V> > subList(
new client::impl::EntryArrayImpl<K, V>(entries, range.first, range.second));
624 std::auto_ptr<DataArray<V> > result = std::auto_ptr<DataArray<V> >(
new impl::EntryArrayValueAdaptor<K, V>(subList));
637 EntryVector entries = map.entrySetData();
638 return std::auto_ptr<EntryArray<K, V> >(
new client::impl::EntryArrayImpl<K, V>(entries, serializationService));
652 EntryVector entries = map.entrySetData(predicate);
653 return std::auto_ptr<EntryArray<K, V> >(
new client::impl::EntryArrayImpl<K, V>(entries, serializationService));
667 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult =
668 map.entrySetForPagingPredicateData(predicate);
670 client::impl::EntryArrayImpl<K, V> entries(dataResult, map.context->getSerializationService());
672 entries.sort(query::ENTRY, predicate.getComparator());
674 std::pair<size_t, size_t> range = map.template updateAnchor<K, V>(entries, predicate, query::ENTRY);
676 return std::auto_ptr<EntryArray<K, V> >(
new client::impl::EntryArrayImpl<K, V>(entries, range.first, range.second));
711 void addIndex(
const std::string &attribute,
bool ordered) {
712 map.addIndex(attribute, ordered);
729 template<
typename ResultType,
typename EntryProcessor>
730 std::auto_ptr<ResultType>
executeOnKey(
const K &key, EntryProcessor &entryProcessor) {
731 std::auto_ptr<serialization::pimpl::Data> resultData =
732 map.template executeOnKeyData<K, EntryProcessor>(key, entryProcessor);
733 return serializationService.toObject<ResultType>(resultData.get());
750 template<
typename ResultType,
typename EntryProcessor>
751 std::auto_ptr<EntryArray<K, ResultType> >
executeOnEntries(EntryProcessor &entryProcessor) {
752 EntryVector results = map.template executeOnEntriesData<EntryProcessor>(entryProcessor);
754 return std::auto_ptr<EntryArray<K, ResultType> >(
new client::impl::EntryArrayImpl<K, ResultType>(results, serializationService));
771 template<
typename ResultType,
typename EntryProcessor>
773 EntryVector results = map.template executeOnEntriesData<EntryProcessor>(entryProcessor, predicate);
775 return std::auto_ptr<EntryArray<K, ResultType> >(
new client::impl::EntryArrayImpl<K, ResultType>(results, serializationService));
785 void set(
const K &key,
const V &value) {
806 return map.isEmpty();
820 void putAll(
const std::map<K, V> &entries) {
835 serialization::pimpl::SerializationService &serializationService;
841 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
void flush()
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore...
Definition: RawPointerMap.h:137
std::auto_ptr< EntryArray< K, V > > entrySet()
Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map.
Definition: RawPointerMap.h:636
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner.
Definition: RawPointerMap.h:379
void lock(const K &key, long leaseTime)
Acquires the lock for the specified key for the specified lease time.
Definition: RawPointerMap.h:305
Map Entry listener to get notified when a map entry is added, removed, updated or evicted...
Definition: EntryListener.h:45
void putAll(const std::map< K, V > &entries)
Copies all of the mappings from the specified map to this map (optional operation).
Definition: RawPointerMap.h:820
std::auto_ptr< ResultType > executeOnKey(const K &key, EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key.
Definition: RawPointerMap.h:730
std::auto_ptr< EntryArray< K, ResultType > > executeOnEntries(EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: RawPointerMap.h:751
bool removeEntryListener(const std::string ®istrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: RawPointerMap.h:436
bool containsKey(const K &key)
check if this map contains key.
Definition: RawPointerMap.h:62
std::auto_ptr< DataArray< V > > values(query::PagingPredicate< K, V > &predicate)
Returns a vector clone of the values contained in this map.
Definition: RawPointerMap.h:612
void addIndex(const std::string &attribute, bool ordered)
Adds an index to this map for the specified entries so that queries can run faster.
Definition: RawPointerMap.h:711
void lock(const K &key)
Acquires the lock for the specified key.
Definition: RawPointerMap.h:283
std::auto_ptr< V > replace(const K &key, const V &value)
Replaces the entry for a key only if currently mapped to some value.
Definition: RawPointerMap.h:251
bool containsValue(const V &value)
check if this map contains value.
Definition: RawPointerMap.h:72
std::auto_ptr< DataArray< V > > values()
Returns a vector clone of the values contained in this map.
Definition: RawPointerMap.h:586
bool evict(const K &key)
Evicts the specified key from this map.
Definition: RawPointerMap.h:481
void removeInterceptor(const std::string &id)
Removes the given interceptor for this map.
Definition: RawPointerMap.h:405
std::auto_ptr< EntryArray< K, V > > entrySet(const query::Predicate &predicate)
Queries the map based on the specified predicate and returns the matching entries.
Definition: RawPointerMap.h:651
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key.
Definition: RawPointerMap.h:454
void deleteEntry(const K &key)
removes entry from map.
Definition: RawPointerMap.h:129
bool tryRemove(const K &key, long timeoutInMillis)
Tries to remove the entry with the given key from this map within specified timeout value...
Definition: RawPointerMap.h:151
NOTE: PagingPredicate can only be used with values(), keySet() and entries() methods!!! ...
Definition: PagingPredicate.h:127
std::auto_ptr< V > 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: RawPointerMap.h:226
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: RawPointerMap.h:197
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map.
Definition: RawPointerMap.h:395
bool isEmpty()
Returns true if this map contains no key-value mappings.
Definition: RawPointerMap.h:805
bool tryLock(const K &key, long timeInMillis)
Tries to acquire the lock for the specified key.
Definition: RawPointerMap.h:350
std::auto_ptr< MapEntryView< K, V > > getEntryView(const K &key)
Returns the MapEntryView for the specified key.
Definition: RawPointerMap.h:466
bool isLocked(const K &key)
Checks the lock for the specified key.
Definition: RawPointerMap.h:317
int size()
Returns the number of key-value mappings in this map.
Definition: RawPointerMap.h:796
Adaptor class to IMap which provides releasable raw pointers for returned objects.
Definition: RawPointerMap.h:50
void clear()
Removes all of the mappings from this map (optional operation).
Definition: RawPointerMap.h:828
bool replace(const K &key, const V &oldValue, const V &newValue)
Replaces the entry for a key only if currently mapped to a given value.
Definition: RawPointerMap.h:240
std::auto_ptr< DataArray< K > > keySet()
Returns a snaphot of the deys data in the map.
Definition: RawPointerMap.h:525
std::auto_ptr< EntryArray< K, V > > entrySet(query::PagingPredicate< K, V > &predicate)
Queries the map based on the specified predicate and returns the matching entries.
Definition: RawPointerMap.h:666
std::auto_ptr< V > put(const K &key, const V &value)
put new entry into map.
Definition: RawPointerMap.h:95
std::auto_ptr< DataArray< K > > keySet(query::PagingPredicate< K, V > &predicate)
Queries the map based on the specified predicate and returns the keys of matching entries...
Definition: RawPointerMap.h:556
std::auto_ptr< EntryArray< K, ResultType > > executeOnEntries(EntryProcessor &entryProcessor, const query::Predicate &predicate)
Applies the user defined EntryProcessor to the all entries in the map.
Definition: RawPointerMap.h:772
This is a merker class for Predicate classes.
Definition: Predicate.h:36
Concurrent, distributed, observable and queryable map client.
Definition: IMap.h:58
std::auto_ptr< EntryArray< K, V > > getAll(const std::set< K > &keys)
Returns the entries for the given keys.
Definition: RawPointerMap.h:506
void set(const K &key, const V &value, long ttl)
Puts an entry into this map.
Definition: RawPointerMap.h:265
void set(const K &key, const V &value)
Puts an entry into this map.
Definition: RawPointerMap.h:785
std::auto_ptr< V > put(const K &key, const V &value, long ttlInMillis)
Puts an entry into this map with a given ttl (time to live) value.
Definition: RawPointerMap.h:182
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this map.
Definition: RawPointerMap.h:423
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: RawPointerMap.h:167
void evictAll()
Evicts all keys from this map except locked ones.
Definition: RawPointerMap.h:496
std::auto_ptr< DataArray< V > > values(const query::Predicate &predicate)
Returns a vector clone of the values contained in this map.
Definition: RawPointerMap.h:599
bool tryLock(const K &key)
Tries to acquire the lock for the specified key.
Definition: RawPointerMap.h:330
std::auto_ptr< V > 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: RawPointerMap.h:209
void unlock(const K &key)
Releases the lock for the specified key.
Definition: RawPointerMap.h:367
MapEntryView represents a readonly view of a map entry.
Definition: MapEntryView.h:38
std::auto_ptr< DataArray< K > > keySet(const query::Predicate &predicate)
Queries the map based on the specified predicate and returns the keys of matching entries...
Definition: RawPointerMap.h:540