Hazelcast C++ Client
Hazelcast C++ Client Library
hazelcast::client::imap Class Reference

Concurrent, distributed, observable and queryable map client. More...

#include <imap.h>

+ Inheritance diagram for hazelcast::client::imap:

Public Member Functions

 imap (const std::string &instance_name, spi::ClientContext *context)
 
template<typename K >
boost::future< bool > contains_key (const K &key)
 check if this map contains key. More...
 
template<typename V >
boost::future< bool > contains_value (const V &value)
 check if this map contains value. More...
 
template<typename K , typename V >
boost::future< boost::optional< V > > get (const K &key)
 get the value. More...
 
template<typename K , typename V , typename R = V>
boost::future< boost::optional< R > > put (const K &key, const V &value)
 put new entry into map. More...
 
template<typename K , typename V , typename R = V>
boost::future< boost::optional< R > > put (const K &key, const V &value, std::chrono::milliseconds ttl)
 Puts an entry into this map with a given ttl (time to live) value. More...
 
template<typename K , typename V >
boost::future< boost::optional< V > > remove (const K &key)
 remove entry form map More...
 
template<typename K , typename V >
boost::future< bool > remove (const K &key, const V &value)
 removes entry from map if there is an entry with same key and value. More...
 
template<typename P >
boost::future< void > remove_all (const P &predicate)
 Removes all entries which match with the supplied predicate. More...
 
template<typename K >
boost::future< void > delete_entry (const K &key)
 removes entry from map. More...
 
template<typename K >
boost::future< bool > try_remove (const K &key, std::chrono::milliseconds timeout)
 Tries to remove the entry with the given key from this map within specified timeout value. More...
 
template<typename K , typename V >
boost::future< bool > try_put (const K &key, const V &value, std::chrono::milliseconds timeout)
 Tries to put the given key, value into this map within specified timeout value. More...
 
template<typename K , typename V >
boost::future< void > put_transient (const K &key, const V &value, std::chrono::milliseconds ttl)
 Same as put(K, V, int64_t, TimeUnit) but MapStore, if defined, will not be called to store/persist the entry. More...
 
template<typename K , typename V , typename R = V>
boost::future< boost::optional< V > > put_if_absent (const K &key, const V &value)
 Puts an entry into this map, if the specified key is not already associated with a value. More...
 
template<typename K , typename V , typename R = V>
boost::future< boost::optional< V > > put_if_absent (const K &key, const V &value, std::chrono::milliseconds ttl)
 Puts an entry into this map with a given ttl (time to live) value if the specified key is not already associated with a value. More...
 
template<typename K , typename V , typename N = V>
boost::future< bool > replace (const K &key, const V &old_value, const N &new_value)
 Replaces the entry for a key only if currently mapped to a given value. More...
 
template<typename K , typename V , typename R = V>
boost::future< boost::optional< R > > replace (const K &key, const V &value)
 Replaces the entry for a key only if currently mapped to some value. More...
 
template<typename K , typename V , typename R = V>
boost::future< void > set (const K &key, const V &value)
 Puts an entry into this map. More...
 
template<typename K , typename V >
boost::future< void > set (const K &key, const V &value, std::chrono::milliseconds ttl)
 Puts an entry into this map. More...
 
template<typename K >
boost::future< void > lock (const K &key)
 Acquires the lock for the specified key. More...
 
template<typename K >
boost::future< void > lock (const K &key, std::chrono::milliseconds lease_time)
 Acquires the lock for the specified key for the specified lease time. More...
 
template<typename K >
boost::future< bool > is_locked (const K &key)
 Checks the lock for the specified key. More...
 
template<typename K >
boost::future< bool > try_lock (const K &key)
 Tries to acquire the lock for the specified key. More...
 
template<typename K >
boost::future< bool > try_lock (const K &key, std::chrono::milliseconds timeout)
 Tries to acquire the lock for the specified key. More...
 
template<typename K >
boost::future< bool > try_lock (const K &key, std::chrono::milliseconds timeout, std::chrono::milliseconds lease_time)
 Tries to acquire the lock for the specified key for the specified lease time. More...
 
template<typename K >
boost::future< void > unlock (const K &key)
 Releases the lock for the specified key. More...
 
template<typename K >
boost::future< void > force_unlock (const K &key)
 Releases the lock for the specified key regardless of the lock owner. More...
 
template<typename MapInterceptor >
boost::future< std::string > add_interceptor (const MapInterceptor &interceptor)
 Adds an interceptor for this map. More...
 
boost::future< boost::uuids::uuid > add_entry_listener (entry_listener &&listener, bool include_value)
 Adds an entry listener for this map. More...
 
template<typename P >
boost::future< boost::uuids::uuid > add_entry_listener (entry_listener &&listener, const P &predicate, bool include_value)
 Adds an entry listener for this map. More...
 
template<typename K >
boost::future< boost::uuids::uuid > add_entry_listener (entry_listener &&listener, bool include_value, const K &key)
 Adds the specified entry listener for the specified key. More...
 
template<typename K , typename V >
boost::future< boost::optional< entry_view< K, V > > > get_entry_view (const K &key)
 Returns the EntryView for the specified key. More...
 
template<typename K >
boost::future< bool > evict (const K &key)
 Evicts the specified key from this map. More...
 
template<typename K , typename V >
boost::future< std::unordered_map< K, V > > get_all (const std::unordered_set< K > &keys)
 Returns the entries for the given keys. More...
 
template<typename K >
boost::future< std::vector< K > > key_set ()
 Returns a vector clone of the keys contained in this map. More...
 
template<typename K , typename P , class = typename std::enable_if<!std::is_base_of<query::paging_predicate_marker, P>::value>::type>
boost::future< std::vector< K > > key_set (const P &predicate)
 Queries the map based on the specified predicate and returns the keys of matching entries. More...
 
template<typename K , typename V >
boost::future< std::vector< K > > key_set (query::paging_predicate< K, V > &predicate)
 Queries the map based on the specified predicate and returns the keys of matching entries. More...
 
template<typename V >
boost::future< std::vector< V > > values ()
 Returns a vector clone of the values contained in this map. More...
 
template<typename V , typename P , class = typename std::enable_if<!std::is_base_of<query::paging_predicate_marker, P>::value>::type>
boost::future< std::vector< V > > values (const P &predicate)
 Returns a vector clone of the values contained in this map. More...
 
template<typename K , typename V >
boost::future< std::vector< V > > values (query::paging_predicate< K, V > &predicate)
 Returns a vector clone of the values contained in this map. More...
 
template<typename K , typename V >
boost::future< std::vector< std::pair< K, V > > > entry_set ()
 Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map. More...
 
template<typename K , typename V , typename P , class = typename std::enable_if<!std::is_base_of<query::paging_predicate_marker, P>::value>::type>
boost::future< std::vector< std::pair< K, V > > > entry_set (const P &predicate)
 Queries the map based on the specified predicate and returns the matching entries. More...
 
template<typename K , typename V >
boost::future< std::vector< std::pair< K, V > > > entry_set (query::paging_predicate< K, V > &predicate)
 Queries the map based on the specified predicate and returns the matching entries. More...
 
boost::future< void > add_index (const config::index_config &config)
 Adds an index to this map for the specified entries so that queries can run faster. More...
 
template<typename ... T>
boost::future< void > add_index (config::index_config::index_type type, T... attributes)
 Convenient method to add an index to this map with the given type and attributes. More...
 
boost::future< void > clear ()
 
template<typename K , typename ResultType , typename EntryProcessor >
boost::future< boost::optional< ResultType > > execute_on_key (const K &key, const EntryProcessor &entry_processor)
 Applies the user defined EntryProcessor to the entry mapped by the key. More...
 
template<typename K , typename ResultType , typename EntryProcessor >
boost::future< boost::optional< ResultType > > submit_to_key (const K &key, const EntryProcessor &entry_processor)
 Applies the user defined EntryProcessor to the entry mapped by the key. More...
 
template<typename K , typename ResultType , typename EntryProcessor >
boost::future< std::unordered_map< K, boost::optional< ResultType > > > execute_on_keys (const std::unordered_set< K > &keys, const EntryProcessor &entry_processor)
 Applies the user defined EntryProcessor to the entries mapped by the collection of keys. More...
 
template<typename K , typename ResultType , typename EntryProcessor >
boost::future< std::unordered_map< K, boost::optional< ResultType > > > execute_on_entries (const EntryProcessor &entry_processor)
 Applies the user defined EntryProcessor to the all entries in the map. More...
 
template<typename K , typename ResultType , typename EntryProcessor , typename P >
boost::future< std::unordered_map< K, boost::optional< ResultType > > > execute_on_entries (const EntryProcessor &entry_processor, const P &predicate)
 Applies the user defined EntryProcessor to the all entries in the map. More...
 
template<typename K , typename V >
boost::future< void > put_all (const std::unordered_map< K, V > &entries)
 Copies all of the mappings from the specified map to this map (optional operation). More...
 
monitor::local_map_statsget_local_map_stats ()
 Returns LocalMapStats for this map. More...
 
template<typename K , typename V >
query::paging_predicate< K, V > new_paging_predicate (size_t predicate_page_size)
 
template<typename K , typename V , typename INNER_PREDICATE >
query::paging_predicate< K, V > new_paging_predicate (size_t predicate_page_size, const INNER_PREDICATE &predicate)
 
template<typename K , typename V , typename COMPARATOR >
query::paging_predicate< K, V > new_paging_predicate (COMPARATOR &&comparator, size_t predicate_page_size)
 
template<typename K , typename V , typename INNER_PREDICATE , typename COMPARATOR >
query::paging_predicate< K, V > new_paging_predicate (const INNER_PREDICATE &predicate, COMPARATOR &&comparator, size_t predicate_page_size)
 

Static Public Attributes

static constexpr const char * SERVICE_NAME = "hz:impl:mapService"
 

Protected Member Functions

virtual boost::future< boost::optional< serialization::pimpl::data > > get_internal (const serialization::pimpl::data &key_data)
 
virtual boost::future< bool > contains_key_internal (const serialization::pimpl::data &key_data)
 
virtual boost::future< boost::optional< serialization::pimpl::data > > remove_internal (const serialization::pimpl::data &key_data)
 
virtual boost::future< bool > remove_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data)
 
virtual boost::future< protocol::ClientMessage > remove_all_internal (const serialization::pimpl::data &predicate_data)
 
virtual boost::future< protocol::ClientMessage > delete_internal (const serialization::pimpl::data &key_data)
 
virtual boost::future< bool > try_remove_internal (const serialization::pimpl::data &key_data, std::chrono::milliseconds timeout)
 
virtual boost::future< bool > try_put_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data, std::chrono::milliseconds timeout)
 
virtual boost::future< boost::optional< serialization::pimpl::data > > put_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data, std::chrono::milliseconds ttl)
 
virtual boost::future< protocol::ClientMessage > try_put_transient_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data, std::chrono::milliseconds ttl)
 
virtual boost::future< boost::optional< serialization::pimpl::data > > put_if_absent_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data, std::chrono::milliseconds ttl)
 
virtual boost::future< bool > replace_if_same_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data, const serialization::pimpl::data &new_value_data)
 
virtual boost::future< boost::optional< serialization::pimpl::data > > replace_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data)
 
virtual boost::future< protocol::ClientMessage > set_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &value_data, std::chrono::milliseconds ttl)
 
virtual boost::future< bool > evict_internal (const serialization::pimpl::data &key_data)
 
virtual boost::future< EntryVector > get_all_internal (int partition_id, const std::vector< serialization::pimpl::data > &partition_keys)
 
virtual boost::future< boost::optional< serialization::pimpl::data > > execute_on_key_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &processor)
 
boost::future< boost::optional< serialization::pimpl::data > > submit_to_key_internal (const serialization::pimpl::data &key_data, const serialization::pimpl::data &processor)
 
template<typename K , typename EntryProcessor >
boost::future< EntryVector > execute_on_keys_internal (const std::unordered_set< K > &keys, const EntryProcessor &entry_processor)
 
virtual boost::future< protocol::ClientMessage > put_all_internal (int partition_id, const EntryVector &entries)
 

Protected Attributes

monitor::impl::LocalMapStatsImpl local_map_stats_
 

Static Protected Attributes

static constexpr std::chrono::milliseconds UNSET {-1}
 Default TTL value of a record.
 

Friends

class spi::ProxyManager
 

Detailed Description

Concurrent, distributed, observable and queryable map client.

Notice that this class have a private constructor. You can access get an IMap in the following way

 auto client = new_client().get();
 auto imap = client.get_map("aMap").get();

Definition at line 63 of file imap.h.

Member Function Documentation

◆ add_entry_listener() [1/3]

boost::future<boost::uuids::uuid> hazelcast::client::imap::add_entry_listener ( entry_listener &&  listener,
bool  include_value 
)
inline

Adds an entry listener for this map.

Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.

Warning 2: Do not make a call to hazelcast. It can cause deadlock.

Parameters
listenerentry listener
includeValuetrue if EntryEvent should contain the value.
Returns
registrationId of added listener that can be used to remove the entry listener.

Definition at line 471 of file imap.h.

471  {
472  const auto listener_flags = listener.flags_;
473  return proxy::IMapImpl::add_entry_listener(
474  std::unique_ptr<impl::BaseEventHandler>(
475  new impl::EntryEventHandler<protocol::codec::map_addentrylistener_handler>(
476  get_name(), get_context().get_client_cluster_service(),
477  get_context().get_serialization_service(),
478  std::move(listener),
479  include_value, get_context().get_logger())), include_value, listener_flags);
480  }

◆ add_entry_listener() [2/3]

template<typename K >
boost::future<boost::uuids::uuid> hazelcast::client::imap::add_entry_listener ( entry_listener &&  listener,
bool  include_value,
const K &  key 
)
inline

Adds the specified entry listener for the specified key.

Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.

Warning 2: Do not make a call to hazelcast. It can cause deadlock.

Parameters
listenerentry listener
keykey to listen
includeValuetrue if EntryEvent should contain the value.

Definition at line 524 of file imap.h.

524  {
525  const auto listener_flags = listener.flags_;
526  return proxy::IMapImpl::add_entry_listener(
527  std::shared_ptr<impl::BaseEventHandler>(
528  new impl::EntryEventHandler<protocol::codec::map_addentrylistenertokey_handler>(
529  get_name(), get_context().get_client_cluster_service(),
530  get_context().get_serialization_service(),
531  std::move(listener),
532  include_value, get_context().get_logger())), include_value, to_data<K>(key), listener_flags);
533  }

◆ add_entry_listener() [3/3]

template<typename P >
boost::future<boost::uuids::uuid> hazelcast::client::imap::add_entry_listener ( entry_listener &&  listener,
const P &  predicate,
bool  include_value 
)
inline

Adds an entry listener for this map.

Warning 1: If listener should do a time consuming operation, off-load the operation to another thread. otherwise it will slow down the system.

Warning 2: Do not make a call to hazelcast. It can cause deadlock.

Parameters
listenerentry listener
predicateThe query filter to use when returning the events to the user.
includeValuetrue if EntryEvent should contain the value.
Returns
registrationId of added listener that can be used to remove the entry listener.

Definition at line 499 of file imap.h.

499  {
500  const auto listener_flags = listener.flags_;
501  return proxy::IMapImpl::add_entry_listener(
502  std::unique_ptr<impl::BaseEventHandler>(
503  new impl::EntryEventHandler<protocol::codec::map_addentrylistenerwithpredicate_handler>(
504  get_name(), get_context().get_client_cluster_service(),
505  get_context().get_serialization_service(),
506  std::move(listener),
507  include_value, get_context().get_logger())), to_data<P>(predicate), include_value, listener_flags);
508  }

◆ add_index() [1/2]

template<typename ... T>
boost::future<void> hazelcast::client::imap::add_index ( config::index_config::index_type  type,
T...  attributes 
)
inline

Convenient method to add an index to this map with the given type and attributes.

Attributes are indexed in ascending order.

Parameters
typeIndex type.
attributesAttributes to be indexed.

Definition at line 832 of file imap.h.

832  {
833  return add_index(config::index_config(type, std::forward<T>(attributes)...));
834  }
boost::future< void > add_index(const config::index_config &config)
Adds an index to this map for the specified entries so that queries can run faster.
Definition: imap.h:819

◆ add_index() [2/2]

boost::future<void> hazelcast::client::imap::add_index ( const config::index_config config)
inline

Adds an index to this map for the specified entries so that queries can run faster.

Let's say your map values are Employee objects.

  struct Employee {
    bool active;
    int32_t age;
    std::string name;
    // other fields

  }

If you are querying your values mostly based on age and active then you may consider indexing these fields.

  auto imap = client.getMap("employees");
  imap.addIndex(config::index_config(config::index_config::index_type::SORTED, "age"));  // Sorted index for range queries
  imap.addIndex(config::index_config(config::index_config::index_type::HASH, "active"));  // Sorted index for range queries

Index attribute should either have a getter method or be public. You should also make sure to add the indexes before adding entries to this map.

Time to Index

Indexing time is executed in parallel on each partition by operation threads. The Map is not blocked during this operation.

The time taken in proportional to the size of the Map and the number Members.

Searches while indexes are being built

Until the index finishes being created, any searches for the attribute will use a full Map scan, thus avoiding using a partially built index and returning incorrect results.

Parameters
configIndex configuration.

Definition at line 819 of file imap.h.

819  {
820  return to_void_future(proxy::IMapImpl::add_index_data(config));
821  }

◆ add_interceptor()

template<typename MapInterceptor >
boost::future<std::string> hazelcast::client::imap::add_interceptor ( const MapInterceptor &  interceptor)
inline

Adds an interceptor for this map.

Added interceptor will intercept operations and execute user defined methods and will cancel operations if user defined method throw exception.

Interceptor should be serializable. Notice that map interceptor runs on the nodes. Because of that same class should be implemented in java side with same classId and factoryId.

Parameters
interceptormap interceptor
Returns
id of registered interceptor

Definition at line 453 of file imap.h.

453  {
454  return proxy::IMapImpl::add_interceptor(to_data(interceptor));
455  }

◆ contains_key()

template<typename K >
boost::future<bool> hazelcast::client::imap::contains_key ( const K &  key)
inline

check if this map contains key.

Parameters
key
Returns
true if contains, false otherwise

Definition at line 77 of file imap.h.

77  {
78  return contains_key_internal(to_data(key));
79  }

◆ contains_value()

template<typename V >
boost::future<bool> hazelcast::client::imap::contains_value ( const V &  value)
inline

check if this map contains value.

Parameters
value
Returns
true if contains, false otherwise

Definition at line 87 of file imap.h.

87  {
88  return proxy::IMapImpl::contains_value(to_data(value));
89  }

◆ delete_entry()

template<typename K >
boost::future<void> hazelcast::client::imap::delete_entry ( const K &  key)
inline

removes entry from map.

Does not return anything.

Parameters
keyThe key of the map entry to remove.

Definition at line 168 of file imap.h.

168  {
169  return to_void_future(delete_internal(to_data(key)));
170  }

◆ entry_set() [1/3]

template<typename K , typename V >
boost::future<std::vector<std::pair<K, V> > > hazelcast::client::imap::entry_set ( )
inline

Returns a std::vector< std::pair<K, V> > clone of the mappings contained in this map.

The vector is NOT backed by the map, so changes to the map are NOT reflected in the set, and vice-versa.

Returns
a vector clone of the keys mappings in this map

Definition at line 733 of file imap.h.

733  {
734  return to_entry_object_vector<K,V>(proxy::IMapImpl::entry_set_data());
735  }

◆ entry_set() [2/3]

template<typename K , typename V , typename P , class = typename std::enable_if<!std::is_base_of<query::paging_predicate_marker, P>::value>::type>
boost::future<std::vector<std::pair<K, V> > > hazelcast::client::imap::entry_set ( const P &  predicate)
inline

Queries the map based on the specified predicate and returns the matching entries.

Specified predicate runs on all members in parallel.

Parameters
predicatequery criteria
Returns
result entry vector of the query

Definition at line 748 of file imap.h.

748  {
749  return to_entry_object_vector<K,V>(proxy::IMapImpl::entry_set_data(to_data(predicate)));
750  }

◆ entry_set() [3/3]

template<typename K , typename V >
boost::future<std::vector<std::pair<K, V> > > hazelcast::client::imap::entry_set ( query::paging_predicate< K, V > &  predicate)
inline

Queries the map based on the specified predicate and returns the matching entries.

Specified predicate runs on all members in parallel.

Parameters
predicatequery criteria
Returns
result entry vector of the query

Definition at line 763 of file imap.h.

763  {
764  predicate.set_iteration_type(query::iteration_type::ENTRY);
765  return entry_set_for_paging_predicate_data(
766  protocol::codec::holder::paging_predicate_holder::of(predicate, serialization_service_)).then(
767  [=, &predicate](boost::future<std::pair<EntryVector, query::anchor_data_list>> f) {
768  auto result = f.get();
769  predicate.set_anchor_data_list(std::move(result.second));
770  const auto &entries_data = result.first;
771  std::vector<std::pair<K, V>> entries;
772  entries.reserve(entries_data.size());
773  for(const auto &e : entries_data) {
774  entries.emplace_back(*to_object<K>(e.first), *to_object<V>(e.second));
775  }
776  return entries;
777  });
778  }

◆ evict()

template<typename K >
boost::future<bool> hazelcast::client::imap::evict ( const K &  key)
inline

Evicts the specified key from this map.

If a MapStore defined for this map, then the entry is not deleted from the underlying MapStore, evict only removes the entry from the memory.

Parameters
keykey to evict
Returns
true if the key is evicted, false otherwise.

Definition at line 566 of file imap.h.

566  {
567  return evict_internal(to_data(key));
568  }

◆ execute_on_entries() [1/2]

template<typename K , typename ResultType , typename EntryProcessor >
boost::future<std::unordered_map<K, boost::optional<ResultType> > > hazelcast::client::imap::execute_on_entries ( const EntryProcessor &  entry_processor)
inline

Applies the user defined EntryProcessor to the all entries in the map.

Returns the results mapped by each key in the map.

EntryProcessor should be serializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.

Template Parameters
ResultTypethat entry processor will return
EntryProcessortype of entry processor class
Parameters
entryProcessorthat will be applied

Definition at line 907 of file imap.h.

907  {
908  return to_object_map<K, ResultType>(proxy::IMapImpl::execute_on_entries_data(to_data(entry_processor)));
909  }

◆ execute_on_entries() [2/2]

template<typename K , typename ResultType , typename EntryProcessor , typename P >
boost::future<std::unordered_map<K, boost::optional<ResultType> > > hazelcast::client::imap::execute_on_entries ( const EntryProcessor &  entry_processor,
const P &  predicate 
)
inline

Applies the user defined EntryProcessor to the all entries in the map.

Returns the results mapped by each key in the map.

EntryProcessor should be serializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.

Template Parameters
ResultTypethat entry processor will return
EntryProcessortype of entry processor class
predicateThe filter to apply for selecting the entries at the server side.
Parameters
entryProcessorthat will be applied

Definition at line 927 of file imap.h.

927  {
928  return to_object_map<K, ResultType>(proxy::IMapImpl::execute_on_entries_data(to_data(entry_processor),
929  to_data(predicate)));
930  }

◆ execute_on_key()

template<typename K , typename ResultType , typename EntryProcessor >
boost::future<boost::optional<ResultType> > hazelcast::client::imap::execute_on_key ( const K &  key,
const EntryProcessor &  entry_processor 
)
inline

Applies the user defined EntryProcessor to the entry mapped by the key.

Returns the the ResultType which is result of the process() method of EntryProcessor.

EntryProcessor should be serializable. Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side with same classId and factoryId.

Template Parameters
EntryProcessortype of entry processor class
ResultTypethat entry processor will return
Parameters
entryProcessorthat will be applied
keyof entry that entryProcessor will be applied on
Returns
result of entry process.

Definition at line 855 of file imap.h.

855  {
856  return to_object<ResultType>(execute_on_key_internal(to_data(key), to_data(entry_processor)));
857  }

◆ execute_on_keys()

template<typename K , typename ResultType , typename EntryProcessor >
boost::future<std::unordered_map<K, boost::optional<ResultType> > > hazelcast::client::imap::execute_on_keys ( const std::unordered_set< K > &  keys,
const EntryProcessor &  entry_processor 
)
inline

Applies the user defined EntryProcessor to the entries mapped by the collection of keys.

Returns the results mapped by each key in the map.

Notice that map EntryProcessor runs on the nodes. Because of that, same class should be implemented in java side

Template Parameters
ResultTypethat entry processor will return
EntryProcessortype of entry processor class
keysThe keys for which the entry processor will be applied.
Parameters
entryProcessorthat will be applied

Definition at line 889 of file imap.h.

889  {
890  return to_object_map<K, ResultType>(execute_on_keys_internal<K, EntryProcessor>(keys, entry_processor));
891  }

◆ force_unlock()

template<typename K >
boost::future<void> hazelcast::client::imap::force_unlock ( const K &  key)
inline

Releases the lock for the specified key regardless of the lock owner.

It always successfully unlocks the key, never blocks and returns immediately.

Parameters
keykey to lock.

Definition at line 437 of file imap.h.

437  {
438  return to_void_future(proxy::IMapImpl::force_unlock(to_data(key)));
439  }

◆ get()

template<typename K , typename V >
boost::future<boost::optional<V> > hazelcast::client::imap::get ( const K &  key)
inline

get the value.

Parameters
key
Returns
value value, if there is no mapping for key then returns boost::none.

Definition at line 97 of file imap.h.

97  {
98  return to_object<V>(get_internal(to_data(key)));
99  }

◆ get_all()

template<typename K , typename V >
boost::future<std::unordered_map<K, V> > hazelcast::client::imap::get_all ( const std::unordered_set< K > &  keys)
inline

Returns the entries for the given keys.

Parameters
keyskeys to get
Returns
map of entries

Definition at line 577 of file imap.h.

577  {
578  if (keys.empty()) {
579  return boost::make_ready_future(std::unordered_map<K, V>());
580  }
581 
582  std::unordered_map<int, std::vector<serialization::pimpl::data>> partition_to_key_data;
583  // group the request per server
584  for (auto &key : keys) {
585  auto key_data = to_data<K>(key);
586 
587  auto partitionId = get_partition_id(key_data);
588  partition_to_key_data[partitionId].push_back(std::move(key_data));
589  }
590 
591  std::vector<boost::future<EntryVector>> futures;
592  futures.reserve(partition_to_key_data.size());
593  for (auto &entry : partition_to_key_data) {
594  futures.push_back(get_all_internal(entry.first, entry.second));
595  }
596 
597  return boost::when_all(futures.begin(), futures.end()).then(boost::launch::sync,
598  [=](boost::future<boost::csbl::vector<boost::future<EntryVector>>> results_data) {
599  std::unordered_map<K, V> result;
600  for (auto &entryVectorFuture : results_data.get()) {
601  for (auto &entry : entryVectorFuture.get()) {
602  auto val = to_object<V>(
603  entry.second);
604  // it is guaranteed that all values are non-null
605  assert(val.has_value());
606  result[to_object<K>(
607  entry.first).value()] = std::move(
608  val.value());
609  }
610  }
611  return result;
612  });
613  }

◆ get_entry_view()

template<typename K , typename V >
boost::future<boost::optional<entry_view<K, V> > > hazelcast::client::imap::get_entry_view ( const K &  key)
inline

Returns the EntryView for the specified key.

Parameters
keykey of the entry
Returns
EntryView of the specified key
See also
EntryView

Definition at line 544 of file imap.h.

544  {
545  return proxy::IMapImpl::get_entry_view_data(to_data(key)).then([=] (boost::future<boost::optional<map::data_entry_view>> f) {
546  auto dataView = f.get();
547  if (!dataView) {
548  return boost::optional<entry_view<K, V>>();
549  }
550  auto v = to_object<V>(dataView->get_value());
551  return boost::make_optional(entry_view<K, V>(key, std::move(v).value(), *std::move(dataView)));
552  });
553  }

◆ get_local_map_stats()

monitor::local_map_stats& hazelcast::client::imap::get_local_map_stats ( )
inline

Returns LocalMapStats for this map.

LocalMapStats is the statistics for the local portion of this distributed map and contains information such as ownedEntryCount backupEntryCount, lastUpdateTime, lockedEntryCount.

Since this stats are only for the local portion of this map, if you need the cluster-wide MapStats then you need to get the LocalMapStats from all members of the cluster and combine them.

Returns
this map's local statistics.

Definition at line 976 of file imap.h.

976  {
977  return local_map_stats_;
978  }

◆ is_locked()

template<typename K >
boost::future<bool> hazelcast::client::imap::is_locked ( const K &  key)
inline

Checks the lock for the specified key.

If the lock is acquired then returns true, else false.

Parameters
keykey to lock to be checked.
Returns
true if lock is acquired, false otherwise.

Definition at line 347 of file imap.h.

347  {
348  return proxy::IMapImpl::is_locked(to_data(key));
349  }

◆ key_set() [1/3]

template<typename K >
boost::future<std::vector<K> > hazelcast::client::imap::key_set ( )
inline

Returns a vector clone of the keys contained in this map.

The vector is NOT backed by the map, so changes to the map are NOT reflected in the vector, and vice-versa.

Returns
a vector clone of the keys contained in this map

Definition at line 623 of file imap.h.

623  {
624  return to_object_vector<K>(proxy::IMapImpl::key_set_data());
625  }

◆ key_set() [2/3]

template<typename K , typename P , class = typename std::enable_if<!std::is_base_of<query::paging_predicate_marker, P>::value>::type>
boost::future<std::vector<K> > hazelcast::client::imap::key_set ( const P &  predicate)
inline

Queries the map based on the specified predicate and returns the keys of matching entries.

Specified predicate runs on all members in parallel.

Parameters
predicatequery criteria
Returns
result key set of the query

Definition at line 639 of file imap.h.

639  {
640  return to_object_vector<K>(proxy::IMapImpl::key_set_data(to_data(predicate)));
641  }

◆ key_set() [3/3]

template<typename K , typename V >
boost::future<std::vector<K> > hazelcast::client::imap::key_set ( query::paging_predicate< K, V > &  predicate)
inline

Queries the map based on the specified predicate and returns the keys of matching entries.

Specified predicate runs on all members in parallel.

Parameters
predicatequery criteria
Returns
result key set of the query

Definition at line 655 of file imap.h.

655  {
656  predicate.set_iteration_type(query::iteration_type::KEY);
657  return key_set_for_paging_predicate_data(
658  protocol::codec::holder::paging_predicate_holder::of(predicate, serialization_service_)).then(
659  [=, &predicate](
660  boost::future<std::pair<std::vector<serialization::pimpl::data>, query::anchor_data_list>> f) {
661  auto result = f.get();
662  predicate.set_anchor_data_list(std::move(result.second));
663  const auto &entries = result.first;
664  std::vector<K> values;
665  values.reserve(entries.size());
666  for(const auto &e : entries) {
667  values.emplace_back(*to_object<K>(e));
668  }
669  return values;
670  });
671  }
boost::future< std::vector< V > > values()
Returns a vector clone of the values contained in this map.
Definition: imap.h:681

◆ lock() [1/2]

template<typename K >
boost::future<void> hazelcast::client::imap::lock ( const K &  key)
inline

Acquires the lock for the specified key.

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

Scope of the lock is this map only. Acquired lock is only for the key in this map.

Locks are re-entrant so if the key is locked N times then it should be unlocked N times before another thread can acquire it.

Parameters
keykey to lock.

Definition at line 311 of file imap.h.

311  {
312  return to_void_future(lock(key, UNSET));
313  }
boost::future< void > lock(const K &key)
Acquires the lock for the specified key.
Definition: imap.h:311
static constexpr std::chrono::milliseconds UNSET
Default TTL value of a record.
Definition: imap.h:1004

◆ lock() [2/2]

template<typename K >
boost::future<void> hazelcast::client::imap::lock ( const K &  key,
std::chrono::milliseconds  lease_time 
)
inline

Acquires the lock for the specified key for the specified lease time.

After lease time, lock will be released..

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

Scope of the lock is this map only. Acquired lock is only for the key in this map.

Locks are re-entrant so if the key is locked N times then it should be unlocked N times before another thread can acquire it.

Parameters
keykey to lock.
leaseTimetime to wait before releasing the lock.

Definition at line 334 of file imap.h.

334  {
335  return to_void_future(proxy::IMapImpl::lock(to_data(key), lease_time));
336  }

◆ put() [1/2]

template<typename K , typename V , typename R = V>
boost::future<boost::optional<R> > hazelcast::client::imap::put ( const K &  key,
const V &  value 
)
inline

put new entry into map.

Parameters
key
value
Returns
the previous value. if there is no mapping for key, then returns boost::none.

Definition at line 108 of file imap.h.

108  {
109  return put<K, V, R>(key, value, UNSET);
110  }

◆ put() [2/2]

template<typename K , typename V , typename R = V>
boost::future<boost::optional<R> > hazelcast::client::imap::put ( const K &  key,
const V &  value,
std::chrono::milliseconds  ttl 
)
inline

Puts an entry into this map with a given ttl (time to live) value.

Entry will expire and get evicted after the ttl. If ttl is 0, then the entry lives forever.

Parameters
keykey of the entry
valuevalue of the entry
ttlmaximum time for this entry to stay in the map. 0 means infinite.
Returns
the previous value. if there is no mapping for key, then returns boost::none.

Definition at line 123 of file imap.h.

123  {
124  return to_object<R>(put_internal(to_data(key), to_data(value), ttl));
125  }

◆ put_all()

template<typename K , typename V >
boost::future<void> hazelcast::client::imap::put_all ( const std::unordered_map< K, V > &  entries)
inline

Copies all of the mappings from the specified map to this map (optional operation).

The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress.

Parameters
entriesmappings to be stored in this map

Definition at line 943 of file imap.h.

943  {
944  std::unordered_map<int, EntryVector> entryMap;
945  for (auto &entry : entries) {
946  serialization::pimpl::data key_data = to_data(entry.first);
947  int partitionId = get_partition_id(key_data);
948  entryMap[partitionId].push_back(std::make_pair(key_data, to_data(entry.second)));
949  }
950 
951  std::vector<boost::future<protocol::ClientMessage>> resultFutures;
952  for (auto &&partitionEntry : entryMap) {
953  auto partitionId = partitionEntry.first;
954  resultFutures.push_back(put_all_internal(partitionId, std::move(partitionEntry.second)));
955  }
956  return boost::when_all(resultFutures.begin(), resultFutures.end()).then(boost::launch::sync,
957  [](boost::future<boost::csbl::vector<boost::future<protocol::ClientMessage>>> futures) {
958  for (auto &f : futures.get()) {
959  f.get();
960  }
961  });
962  }

◆ put_if_absent() [1/2]

template<typename K , typename V , typename R = V>
boost::future<boost::optional<V> > hazelcast::client::imap::put_if_absent ( const K &  key,
const V &  value 
)
inline

Puts an entry into this map, if the specified key is not already associated with a value.

Parameters
keykey with which the specified value is to be associated
value
Returns
the previous value, if there is no mapping for key then returns boost::none.

Definition at line 226 of file imap.h.

226  {
227  return put_if_absent(key, value, UNSET);
228  }
boost::future< boost::optional< V > > put_if_absent(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:226

◆ put_if_absent() [2/2]

template<typename K , typename V , typename R = V>
boost::future<boost::optional<V> > hazelcast::client::imap::put_if_absent ( const K &  key,
const V &  value,
std::chrono::milliseconds  ttl 
)
inline

Puts an entry into this map with a given ttl (time to live) value if the specified key is not already associated with a value.

Entry will expire and get evicted after the ttl.

Parameters
keykey of the entry
valuevalue of the entry
ttlmaximum time for this entry to stay in the map
Returns
the previous value of the entry, if there is no mapping for key then returns boost::none.

Definition at line 242 of file imap.h.

242  {
243  return to_object<R>(put_if_absent_internal(to_data(key), to_data(value), ttl));
244  }

◆ put_transient()

template<typename K , typename V >
boost::future<void> hazelcast::client::imap::put_transient ( const K &  key,
const V &  value,
std::chrono::milliseconds  ttl 
)
inline

Same as put(K, V, int64_t, TimeUnit) but MapStore, if defined, will not be called to store/persist the entry.

If ttl is 0, then the entry lives forever.

Parameters
keykey of the entry
valuevalue of the entry
ttlmaximum time for this entry to stay in the map in milliseconds, 0 means infinite.

Definition at line 213 of file imap.h.

213  {
214  return to_void_future(try_put_transient_internal(to_data(key), to_data(value), ttl));
215  }

◆ remove() [1/2]

template<typename K , typename V >
boost::future<boost::optional<V> > hazelcast::client::imap::remove ( const K &  key)
inline

remove entry form map

Parameters
key
Returns
the previous value. if there is no mapping for key then returns boost::none.

Definition at line 133 of file imap.h.

133  {
134  return to_object<V>(remove_internal(to_data(key)));
135  }

◆ remove() [2/2]

template<typename K , typename V >
boost::future<bool> hazelcast::client::imap::remove ( const K &  key,
const V &  value 
)
inline

removes entry from map if there is an entry with same key and value.

Parameters
keykey of the entry to be removed
valuevalue of the entry to be removed
Returns
true if the entry with key and value exists and removed, false otherwise

Definition at line 144 of file imap.h.

144  {
145  return remove_internal(to_data(key), to_data(value));
146  }

◆ remove_all()

template<typename P >
boost::future<void> hazelcast::client::imap::remove_all ( const P &  predicate)
inline

Removes all entries which match with the supplied predicate.

If this map has index, matching entries will be found via index search, otherwise they will be found by full-scan.

Note that calling this method also removes all entries from callers Near Cache.

Parameters
predicatematching entries with this predicate will be removed from this map

Definition at line 158 of file imap.h.

158  {
159  return to_void_future(remove_all_internal(to_data<P>(predicate)));
160  }

◆ replace() [1/2]

template<typename K , typename V , typename N = V>
boost::future<bool> hazelcast::client::imap::replace ( const K &  key,
const V &  old_value,
const N &  new_value 
)
inline

Replaces the entry for a key only if currently mapped to a given value.

Parameters
keykey with which the specified value is associated
oldValuevalue expected to be associated with the specified key
newValue
Returns
true if the value was replaced

Definition at line 254 of file imap.h.

254  {
255  return replace_if_same_internal(to_data(key), to_data(old_value), to_data(new_value));
256  }

◆ replace() [2/2]

template<typename K , typename V , typename R = V>
boost::future<boost::optional<R> > hazelcast::client::imap::replace ( const K &  key,
const V &  value 
)
inline

Replaces the entry for a key only if currently mapped to some value.

Parameters
keykey with which the specified value is associated
value
Returns
the previous value of the entry, if there is no mapping for key then returns boost::none.

Definition at line 266 of file imap.h.

266  {
267  return to_object<R>(replace_internal(to_data(key), to_data(value)));
268  }

◆ set() [1/2]

template<typename K , typename V , typename R = V>
boost::future<void> hazelcast::client::imap::set ( const K &  key,
const V &  value 
)
inline

Puts an entry into this map.

Similar to put operation except that set doesn't return the old value which is more efficient.

Parameters
key
value

Definition at line 278 of file imap.h.

278  {
279  return to_void_future(set(key, value, UNSET));
280  }
boost::future< void > set(const K &key, const V &value)
Puts an entry into this map.
Definition: imap.h:278

◆ set() [2/2]

template<typename K , typename V >
boost::future<void> hazelcast::client::imap::set ( const K &  key,
const V &  value,
std::chrono::milliseconds  ttl 
)
inline

Puts an entry into this map.

Similar to put operation except that set doesn't return the old value which is more efficient.

Parameters
keykey with which the specified value is associated
value
ttlmaximum time in milliseconds for this entry to stay in the map 0 means infinite.

Definition at line 292 of file imap.h.

292  {
293  return to_void_future(set_internal(to_data(key), to_data(value), ttl));
294  }

◆ submit_to_key()

template<typename K , typename ResultType , typename EntryProcessor >
boost::future<boost::optional<ResultType> > hazelcast::client::imap::submit_to_key ( const K &  key,
const EntryProcessor &  entry_processor 
)
inline

Applies the user defined EntryProcessor to the entry mapped by the key.

Returns immediately with a Future representing that task.

Parameters
keykey to be processed
entryProcessorprocessor to process the key
Returns
Future from which the result of the operation can be retrieved.

Definition at line 871 of file imap.h.

871  {
872  return to_object<ResultType>(submit_to_key_internal(to_data(key), to_data(entry_processor)));
873  }

◆ try_lock() [1/3]

template<typename K >
boost::future<bool> hazelcast::client::imap::try_lock ( const K &  key)
inline

Tries to acquire the lock for the specified key.

If the lock is not available then the current thread doesn't wait and returns false immediately.

Parameters
keykey to lock.
Returns
true if lock is acquired, false otherwise.

Definition at line 361 of file imap.h.

361  {
362  return try_lock(key, std::chrono::milliseconds(0));
363  }
boost::future< bool > try_lock(const K &key)
Tries to acquire the lock for the specified key.
Definition: imap.h:361

◆ try_lock() [2/3]

template<typename K >
boost::future<bool> hazelcast::client::imap::try_lock ( const K &  key,
std::chrono::milliseconds  timeout 
)
inline

Tries to acquire the lock for the specified key.

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

  • The lock is acquired by the current thread; or
  • The specified waiting time elapses
Parameters
keykey to lock in this map
timeoutmaximum time in milliseconds to wait for the lock
Returns
true if the lock was acquired and false if the waiting time elapsed before the lock was acquired.

Definition at line 382 of file imap.h.

382  {
383  return proxy::IMapImpl::try_lock(to_data(key), timeout);
384  }

◆ try_lock() [3/3]

template<typename K >
boost::future<bool> hazelcast::client::imap::try_lock ( const K &  key,
std::chrono::milliseconds  timeout,
std::chrono::milliseconds  lease_time 
)
inline

Tries to acquire the lock for the specified key for the specified lease time.

After lease time, the lock will be released.

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

  • The lock is acquired by the current thread; or
  • The specified waiting time elapses
Parameters
keykey to lock in this map
timeoutmaximum time to wait for the lock
leaseTimetime to wait before releasing the lock.
Returns
true if the lock was acquired and false if the waiting time elapsed before the lock was acquired.

Definition at line 406 of file imap.h.

406  {
407  return proxy::IMapImpl::try_lock(to_data(key), timeout, lease_time);
408  }

◆ try_put()

template<typename K , typename V >
boost::future<bool> hazelcast::client::imap::try_put ( const K &  key,
const V &  value,
std::chrono::milliseconds  timeout 
)
inline

Tries to put the given key, value into this map within specified timeout value.

If this method returns false, it means that the caller thread couldn't acquire the lock for the key within timeout duration, thus put operation is not successful.

Parameters
keykey of the entry
valuevalue of the entry
timeoutmaximum time to wait
Returns
true if the put is successful, false otherwise.

Definition at line 199 of file imap.h.

199  {
200  return try_put_internal(to_data(key), to_data(value), timeout);
201  }

◆ try_remove()

template<typename K >
boost::future<bool> hazelcast::client::imap::try_remove ( const K &  key,
std::chrono::milliseconds  timeout 
)
inline

Tries to remove the entry with the given key from this map within specified timeout value.

If the key is already locked by another thread and/or member, then this operation will wait timeout amount for acquiring the lock.

Parameters
keykey of the entry
timeoutmaximum time to wait for acquiring the lock for the key

Definition at line 182 of file imap.h.

182  {
183  return try_remove_internal(to_data(key), timeout);
184  }

◆ unlock()

template<typename K >
boost::future<void> hazelcast::client::imap::unlock ( const K &  key)
inline

Releases the lock for the specified key.

It never blocks and returns immediately.

If the current thread is the holder of this lock then the hold count is decremented. If the hold count is now zero then the lock is released. If the current thread is not the holder of this lock then illegal_monitor_state is thrown.

Parameters
keykey to lock.
Exceptions
illegal_monitor_stateif the current thread does not hold this lock MTODO

Definition at line 424 of file imap.h.

424  {
425  return to_void_future(proxy::IMapImpl::unlock(to_data(key)));
426  }

◆ values() [1/3]

template<typename V >
boost::future<std::vector<V> > hazelcast::client::imap::values ( )
inline

Returns a vector clone of the values contained in this map.

The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.

Returns
a vector clone of the values contained in this map

Definition at line 681 of file imap.h.

681  {
682  return to_object_vector<V>(proxy::IMapImpl::values_data());
683  }

◆ values() [2/3]

template<typename V , typename P , class = typename std::enable_if<!std::is_base_of<query::paging_predicate_marker, P>::value>::type>
boost::future<std::vector<V> > hazelcast::client::imap::values ( const P &  predicate)
inline

Returns a vector clone of the values contained in this map.

The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.

Parameters
predicatethe criteria for values to match
Returns
a vector clone of the values contained in this map

Definition at line 694 of file imap.h.

694  {
695  return to_object_vector<V>(proxy::IMapImpl::values_data(to_data(predicate)));
696  }

◆ values() [3/3]

template<typename K , typename V >
boost::future<std::vector<V> > hazelcast::client::imap::values ( query::paging_predicate< K, V > &  predicate)
inline

Returns a vector clone of the values contained in this map.

The vector is NOT backed by the map, so changes to the map are NOT reflected in the collection, and vice-versa.

Parameters
predicatethe criteria for values to match
Returns
a vector clone of the values contained in this map

Definition at line 708 of file imap.h.

708  {
709  predicate.set_iteration_type(query::iteration_type::VALUE);
710  return values_for_paging_predicate_data(
711  protocol::codec::holder::paging_predicate_holder::of(predicate, serialization_service_)).then(
712  [=, &predicate](boost::future<std::pair<std::vector<serialization::pimpl::data>, query::anchor_data_list>> f) {
713  auto result = f.get();
714  predicate.set_anchor_data_list(std::move(result.second));
715  const auto &entries = result.first;
716  std::vector<V> values;
717  values.reserve(entries.size());
718  for(const auto &e : entries) {
719  values.emplace_back(*to_object<V>(e));
720  }
721  return values;
722  });
723  }

The documentation for this class was generated from the following files: