16 #ifndef HAZELCAST_IMAP 
   17 #define HAZELCAST_IMAP 
   19 #include "hazelcast/client/proxy/IMapImpl.h" 
   20 #include "hazelcast/client/impl/EntryEventHandler.h" 
   21 #include "hazelcast/client/EntryListener.h" 
   22 #include "hazelcast/client/EntryView.h" 
   30 #if  defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 
   32 #pragma warning(disable: 4251) //for dll export 
   51         template<
typename K, 
typename V>
 
   52         class IMap : 
public proxy::IMapImpl {
 
   64                 return proxy::IMapImpl::containsKey(toData(key));
 
   74                 return proxy::IMapImpl::containsValue(toData(value));
 
   84             boost::shared_ptr<V> 
get(
const K &key) {
 
   85                 return toObject<V>(proxy::IMapImpl::get(toData(key)));
 
   96             boost::shared_ptr<V> 
put(
const K &key, 
const V &value) {
 
   97                 return toObject<V>(proxy::IMapImpl::put(toData(key), toData(value)));
 
  107             boost::shared_ptr<V> 
remove(
const K &key) {
 
  108                 return toObject<V>(proxy::IMapImpl::remove(toData(key)));
 
  118             bool remove(
const K &key, 
const V &value) {
 
  119                 return proxy::IMapImpl::remove(toData(key), toData(value));
 
  129                 proxy::IMapImpl::deleteEntry(toData(key));
 
  137                 proxy::IMapImpl::flush();
 
  151                 return proxy::IMapImpl::tryRemove(toData(key), timeoutInMillis);
 
  166             bool tryPut(
const K &key, 
const V &value, 
long timeoutInMillis) {
 
  167                 return proxy::IMapImpl::tryPut(toData(key), toData(value), timeoutInMillis);
 
  181             boost::shared_ptr<V> 
put(
const K &key, 
const V &value, 
long ttlInMillis) {
 
  182                 return toObject<V>(proxy::IMapImpl::put(toData(key), toData(value), ttlInMillis));
 
  195                 proxy::IMapImpl::putTransient(toData(key), toData(value), ttlInMillis);
 
  221             boost::shared_ptr<V> 
putIfAbsent(
const K &key, 
const V &value, 
long ttlInMillis) {
 
  222                 return toObject<V>(proxy::IMapImpl::putIfAbsent(toData(key), toData(value), ttlInMillis));
 
  232             bool replace(
const K &key, 
const V &oldValue, 
const V &newValue) {
 
  233                 return proxy::IMapImpl::replace(toData(key), toData(oldValue), toData(newValue));
 
  243             boost::shared_ptr<V> 
replace(
const K &key, 
const V &value) {
 
  244                 return toObject<V>(proxy::IMapImpl::replace(toData(key), toData(value)));
 
  256             void set(
const K &key, 
const V &value, 
long ttl) {
 
  257                 proxy::IMapImpl::set(toData(key), toData(value), ttl);
 
  275                 proxy::IMapImpl::lock(toData(key));
 
  296             void lock(
const K &key, 
long leaseTime) {
 
  297                 proxy::IMapImpl::lock(toData(key), leaseTime);
 
  309                 return proxy::IMapImpl::isLocked(toData(key));
 
  341             bool tryLock(
const K &key, 
long timeInMillis) {
 
  342                 return proxy::IMapImpl::tryLock(toData(key), timeInMillis);
 
  359                 proxy::IMapImpl::unlock(toData(key));
 
  371                 proxy::IMapImpl::forceUnlock(toData(key));
 
  385             template<
typename MapInterceptor>
 
  387                 return proxy::IMapImpl::addInterceptor(interceptor);
 
  397                 proxy::IMapImpl::removeInterceptor(
id);
 
  415                 impl::EntryEventHandler<K, V, protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
 
  416                         new impl::EntryEventHandler<K, V, protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler>(
 
  417                                 getName(), context->getClusterService(), context->getSerializationService(), listener,
 
  419                 return proxy::IMapImpl::addEntryListener(entryEventHandler, includeValue);
 
  432                 return proxy::IMapImpl::removeEntryListener(registrationId);
 
  450                 serialization::pimpl::Data keyData = toData(key);
 
  451                 impl::EntryEventHandler<K, V, protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler> *entryEventHandler =
 
  452                         new impl::EntryEventHandler<K, V, protocol::codec::MapAddEntryListenerCodec::AbstractEventHandler>(
 
  453                                 getName(), context->getClusterService(), context->getSerializationService(), listener,
 
  455                 return proxy::IMapImpl::addEntryListener(entryEventHandler, keyData, includeValue);
 
  467                 serialization::pimpl::Data keyData = toData(key);
 
  468                 std::auto_ptr<map::DataEntryView> dataEntryView = proxy::IMapImpl::getEntryView(keyData);
 
  469                 boost::shared_ptr<V> v = toObject<V>(dataEntryView->getValue());
 
  485                 return proxy::IMapImpl::evict(toData(key));
 
  500                 proxy::IMapImpl::evictAll();
 
  509             std::map<K, V> 
getAll(
const std::set<K> &keys) {
 
  510                 std::vector<serialization::pimpl::Data> 
keySet(keys.size());
 
  512                 for (
typename std::set<K>::iterator it = keys.begin(); it != keys.end(); ++it) {
 
  513                     keySet[i++] = toData(*it);
 
  515                 std::map<K, V> result;
 
  516                 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > 
entrySet = proxy::IMapImpl::getAll(
 
  518                 for (std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> >::const_iterator it = entrySet.begin();
 
  519                      it != entrySet.end(); ++it) {
 
  520                     boost::shared_ptr<K> key = toObject<K>(it->first);
 
  521                     boost::shared_ptr<V> value = toObject<V>(it->second);
 
  522                     result[*key] = *value;
 
  535                 std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::keySet();
 
  536                 int size = dataResult.size();
 
  537                 std::vector<K> keys(size);
 
  538                 for (
int i = 0; i < 
size; ++i) {
 
  539                     boost::shared_ptr<K> key = toObject<K>(dataResult[i]);
 
  556                 std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::keySet(predicate);
 
  557                 int size = dataResult.size();
 
  558                 std::vector<K> keys(size);
 
  559                 for (
int i = 0; i < 
size; ++i) {
 
  560                     boost::shared_ptr<K> key = toObject<K>(dataResult[i]);
 
  574                 std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::values();
 
  575                 int size = dataResult.size();
 
  576                 std::vector<K> 
values(size);
 
  577                 for (
int i = 0; i < 
size; ++i) {
 
  578                     boost::shared_ptr<K> value = toObject<K>(dataResult[i]);
 
  593                 std::vector<serialization::pimpl::Data> dataResult = proxy::IMapImpl::values(predicate);
 
  594                 int size = dataResult.size();
 
  595                 std::vector<V> 
values(size);
 
  596                 for (
int i = 0; i < 
size; ++i) {
 
  597                     boost::shared_ptr<V> value = toObject<V>(dataResult[i]);
 
  611                 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult = proxy::IMapImpl::entrySet();
 
  612                 size_t size = dataResult.size();
 
  613                 std::vector<std::pair<K, V> > entries(size);
 
  614                 for (
size_t i = 0; i < 
size; ++i) {
 
  615                     boost::shared_ptr<K> key = toObject<K>(dataResult[i].first);
 
  616                     boost::shared_ptr<V> value = toObject<V>(dataResult[i].second);
 
  617                     entries[i] = std::make_pair(*key, *value);
 
  633                 std::vector<std::pair<serialization::pimpl::Data, serialization::pimpl::Data> > dataResult = proxy::IMapImpl::entrySet(
 
  635                 size_t size = dataResult.size();
 
  636                 std::vector<std::pair<K, V> > entries(size);
 
  637                 for (
size_t i = 0; i < 
size; ++i) {
 
  638                     boost::shared_ptr<K> key = toObject<K>(dataResult[i].first);
 
  639                     boost::shared_ptr<V> value = toObject<V>(dataResult[i].second);
 
  640                     entries[i] = std::make_pair(*key, *value);
 
  677             void addIndex(
const std::string &attribute, 
bool ordered) {
 
  678                 proxy::IMapImpl::addIndex(attribute, ordered);
 
  695             template<
typename ResultType, 
typename EntryProcessor>
 
  696             boost::shared_ptr<ResultType> 
executeOnKey(
const K &key, EntryProcessor &entryProcessor) {
 
  697                 return proxy::IMapImpl::executeOnKey<K, ResultType, EntryProcessor>(key, entryProcessor);
 
  713             template<
typename ResultType, 
typename EntryProcessor>
 
  714             std::map<K, boost::shared_ptr<ResultType> > 
executeOnEntries(EntryProcessor &entryProcessor) {
 
  715                 return proxy::IMapImpl::executeOnEntries<K, ResultType, EntryProcessor>(entryProcessor);
 
  725             void set(
const K &key, 
const V &value) {
 
  737                 return proxy::IMapImpl::size();
 
  746                 return proxy::IMapImpl::isEmpty();
 
  760             void putAll(
const std::map<K, V> &entries) {
 
  761                 return proxy::IMapImpl::putAll(toDataEntriesSet(entries));
 
  769                 proxy::IMapImpl::clear();
 
  773             IMap(
const std::string &instanceName, spi::ClientContext *context)
 
  774                     : proxy::IMapImpl(instanceName, context) {
 
  782 #if  defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 
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: IMap.h:194
std::vector< std::pair< K, V > > entrySet()
Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map. 
Definition: IMap.h:610
boost::shared_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: IMap.h:221
std::map< K, V > getAll(const std::set< K > &keys)
Returns the entries for the given keys. 
Definition: IMap.h:509
void putAll(const std::map< K, V > &entries)
Copies all of the mappings from the specified map to this map (optional operation). 
Definition: IMap.h:760
boost::shared_ptr< V > replace(const K &key, const V &value)
Replaces the entry for a key only if currently mapped to some value. 
Definition: IMap.h:243
bool tryLock(const K &key)
Tries to acquire the lock for the specified key. 
Definition: IMap.h:321
Map Entry listener to get notified when a map entry is added, removed, updated or evicted...
Definition: EntryListener.h:45
bool tryLock(const K &key, long timeInMillis)
Tries to acquire the lock for the specified key. 
Definition: IMap.h:341
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: IMap.h:166
void set(const K &key, const V &value)
Puts an entry into this map. 
Definition: IMap.h:725
std::vector< V > values()
Returns a vector clone of the values contained in this map. 
Definition: IMap.h:573
void deleteEntry(const K &key)
removes entry from map. 
Definition: IMap.h:128
void evictAll()
Evicts all keys from this map except locked ones. 
Definition: IMap.h:499
std::map< K, boost::shared_ptr< ResultType > > executeOnEntries(EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the all entries in the map. 
Definition: IMap.h:714
std::string addEntryListener(EntryListener< K, V > &listener, bool includeValue)
Adds an entry listener for this map. 
Definition: IMap.h:414
std::vector< K > keySet()
Returns a vector clone of the keys contained in this map. 
Definition: IMap.h:534
void set(const K &key, const V &value, long ttl)
Puts an entry into this map. 
Definition: IMap.h:256
std::string addEntryListener(EntryListener< K, V > &listener, const K &key, bool includeValue)
Adds the specified entry listener for the specified key. 
Definition: IMap.h:449
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: IMap.h:232
boost::shared_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: IMap.h:206
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:42
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: IMap.h:677
bool isLocked(const K &key)
Checks the lock for the specified key. 
Definition: IMap.h:308
boost::shared_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: IMap.h:181
void flush()
If this map has a MapStore this method flushes all the local dirty entries by calling MapStore...
Definition: IMap.h:136
std::string addInterceptor(MapInterceptor &interceptor)
Adds an interceptor for this map. 
Definition: IMap.h:386
void lock(const K &key)
Acquires the lock for the specified key. 
Definition: IMap.h:274
bool tryRemove(const K &key, long timeoutInMillis)
Tries to remove the entry with the given key from this map within specified timeout value...
Definition: IMap.h:150
void lock(const K &key, long leaseTime)
Acquires the lock for the specified key for the specified lease time. 
Definition: IMap.h:296
void removeInterceptor(const std::string &id)
Removes the given interceptor for this map. 
Definition: IMap.h:396
EntryView represents a readonly view of a map entry. 
Definition: EntryView.h:39
std::vector< K > keySet(const serialization::IdentifiedDataSerializable &predicate)
Queries the map based on the specified predicate and returns the keys of matching entries...
Definition: IMap.h:555
Concurrent, distributed, observable and queryable map client. 
Definition: IMap.h:52
bool isEmpty()
Returns true if this map contains no key-value mappings. 
Definition: IMap.h:745
void unlock(const K &key)
Releases the lock for the specified key. 
Definition: IMap.h:358
bool evict(const K &key)
Evicts the specified key from this map. 
Definition: IMap.h:484
void forceUnlock(const K &key)
Releases the lock for the specified key regardless of the lock owner. 
Definition: IMap.h:370
std::vector< V > values(const serialization::IdentifiedDataSerializable &predicate)
Returns a vector clone of the values contained in this map. 
Definition: IMap.h:592
void clear()
Removes all of the mappings from this map (optional operation). 
Definition: IMap.h:768
boost::shared_ptr< V > put(const K &key, const V &value)
put new entry into map. 
Definition: IMap.h:96
EntryView< K, V > getEntryView(const K &key)
Returns the EntryView for the specified key. 
Definition: IMap.h:466
bool containsValue(const V &value)
check if this map contains value. 
Definition: IMap.h:73
Hazelcast Client enables you to do all Hazelcast operations without being a member of the cluster...
Definition: HazelcastClient.h:410
bool containsKey(const K &key)
check if this map contains key. 
Definition: IMap.h:63
std::vector< std::pair< K, V > > entrySet(const serialization::IdentifiedDataSerializable &predicate)
Queries the map based on the specified predicate and returns the matching entries. 
Definition: IMap.h:632
bool removeEntryListener(const std::string ®istrationId)
Removes the specified entry listener Returns silently if there is no such listener added before...
Definition: IMap.h:431
int size()
Returns the number of key-value mappings in this map. 
Definition: IMap.h:736
boost::shared_ptr< ResultType > executeOnKey(const K &key, EntryProcessor &entryProcessor)
Applies the user defined EntryProcessor to the entry mapped by the key. 
Definition: IMap.h:696