Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast::cp::atomic_long Class Reference

Client-side Raft-based proxy implementation of atomic long. More...

#include <cp.h>

Inheritance diagram for hazelcast::cp::atomic_long:

Public Member Functions

 atomic_long (const std::string &name, client::spi::ClientContext &context, const raft_group_id &group_id, const std::string &object_name)
boost::future< int64_t > add_and_get (int64_t delta)
 Atomically adds the given value to the current value.
boost::future< bool > compare_and_set (int64_t expect, int64_t update)
 Atomically sets the value to the given updated value only if the current value.
boost::future< int64_t > get_and_decrement ()
 Atomically decrements the current value by one.
boost::future< int64_t > decrement_and_get ()
 Atomically decrements the current value by one.
boost::future< int64_t > get ()
 Gets the current value.
boost::future< int64_t > get_and_add (int64_t delta)
 Atomically adds the given value to the current value.
boost::future< int64_t > get_and_set (int64_t new_value)
 Atomically sets the given value and returns the old value.
boost::future< int64_t > increment_and_get ()
 Atomically increments the current value by one.
boost::future< int64_t > get_and_increment ()
 Atomically increments the current value by one.
boost::future< void > set (int64_t new_value)
 Atomically sets the given value.
template<typename F>
boost::future< void > alter (const F &function)
 Alters the currently stored value by applying a function on it.
template<typename F>
boost::future< int64_t > alter_and_get (const F &function)
 Alters the currently stored value by applying a function on it and gets the result.
template<typename F>
boost::future< int64_t > get_and_alter (const F &function)
 Alters the currently stored value by applying a function on it on and gets the old value.
template<typename F, typename R>
boost::future< boost::optional< R > > apply (const F &function)
 Applies a function on the value, the actual stored value will not change.
Public Member Functions inherited from hazelcast::cp::cp_proxy
 cp_proxy (const std::string &service_name, const std::string &proxy_name, client::spi::ClientContext *context, const raft_group_id &group_id, const std::string &object_name)
const raft_group_idget_group_id () const

Additional Inherited Members

Protected Member Functions inherited from hazelcast::cp::cp_proxy
void on_destroy ()
Protected Attributes inherited from hazelcast::cp::cp_proxy
raft_group_id group_id_
std::string object_name_

Detailed Description

Client-side Raft-based proxy implementation of atomic long.

Definition at line 99 of file cp.h.

Constructor & Destructor Documentation

◆ atomic_long()

hazelcast::cp::atomic_long::atomic_long ( const std::string & name,
client::spi::ClientContext & context,
const raft_group_id & group_id,
const std::string & object_name )

Definition at line 211 of file cp.cpp.

215 : cp_proxy(SERVICE_NAME, name, &context, group_id, object_name)
216{}

Member Function Documentation

◆ add_and_get()

boost::future< int64_t > hazelcast::cp::atomic_long::add_and_get ( int64_t delta)

Atomically adds the given value to the current value.

Parameters
deltathe value to add to the current value
Returns
the updated value, the given value added to the current value

Definition at line 219 of file cp.cpp.

220{
221 auto request = atomiclong_addandget_encode(group_id_, object_name_, delta);
222 return invoke_and_get_future<int64_t>(request);
223}

◆ alter()

template<typename F>
boost::future< void > hazelcast::cp::atomic_long::alter ( const F & function)
inline

Alters the currently stored value by applying a function on it.

Parameters
functionthe function applied to the currently stored value

Definition at line 190 of file cp.h.

191 {
192 return to_void_future(alter_and_get(function));
193 }
boost::future< int64_t > alter_and_get(const F &function)
Alters the currently stored value by applying a function on it and gets the result.
Definition cp.h:203

◆ alter_and_get()

template<typename F>
boost::future< int64_t > hazelcast::cp::atomic_long::alter_and_get ( const F & function)
inline

Alters the currently stored value by applying a function on it and gets the result.

Parameters
functionthe function applied to the currently stored value
Returns
the new value

Definition at line 203 of file cp.h.

204 {
205 auto f = to_data(function);
206 return alter_data(f, alter_result_type::NEW_VALUE);
207 }

◆ apply()

template<typename F, typename R>
boost::future< boost::optional< R > > hazelcast::cp::atomic_long::apply ( const F & function)
inline

Applies a function on the value, the actual stored value will not change.

Parameters
functionthe function applied to the value, the value is not changed
<R>the result type of the function
Returns
the result of the function application

Definition at line 233 of file cp.h.

234 {
235 auto f = to_data(function);
236 return to_object<R>(apply_data(f));
237 }

◆ compare_and_set()

boost::future< bool > hazelcast::cp::atomic_long::compare_and_set ( int64_t expect,
int64_t update )

Atomically sets the value to the given updated value only if the current value.

==

the expected value.

Parameters
expectthe expected value
updatethe new value
Returns
true
if successful; or
false
if the actual value was not equal to the expected value.

Definition at line 226 of file cp.cpp.

227{
228 auto request =
229 atomiclong_compareandset_encode(group_id_, object_name_, expect, update);
230 return invoke_and_get_future<bool>(request);
231}

◆ decrement_and_get()

boost::future< int64_t > hazelcast::cp::atomic_long::decrement_and_get ( )

Atomically decrements the current value by one.

Returns
the updated value, the current value decremented by one

Definition at line 240 of file cp.cpp.

241{
242 return add_and_get(-1);
243}
boost::future< int64_t > add_and_get(int64_t delta)
Atomically adds the given value to the current value.
Definition cp.cpp:219

◆ get()

boost::future< int64_t > hazelcast::cp::atomic_long::get ( )

Gets the current value.

Returns
the current value

Definition at line 246 of file cp.cpp.

247{
248 auto request = atomiclong_get_encode(group_id_, object_name_);
249 return invoke_and_get_future<int64_t>(request);
250}

◆ get_and_add()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_add ( int64_t delta)

Atomically adds the given value to the current value.

Parameters
deltathe value to add to the current value
Returns
the old value before the add

Definition at line 253 of file cp.cpp.

254{
255 auto request = atomiclong_getandadd_encode(group_id_, object_name_, delta);
256 return invoke_and_get_future<int64_t>(request);
257}

◆ get_and_alter()

template<typename F>
boost::future< int64_t > hazelcast::cp::atomic_long::get_and_alter ( const F & function)
inline

Alters the currently stored value by applying a function on it on and gets the old value.

Parameters
functionthe function applied to the currently stored value
Returns
the old value
Since
3.2

Definition at line 218 of file cp.h.

219 {
220 auto f = to_data(function);
221 return alter_data(f, alter_result_type::OLD_VALUE);
222 }

◆ get_and_decrement()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_decrement ( )

Atomically decrements the current value by one.

Returns
the old value.

Definition at line 234 of file cp.cpp.

235{
236 return get_and_add(-1);
237}
boost::future< int64_t > get_and_add(int64_t delta)
Atomically adds the given value to the current value.
Definition cp.cpp:253

◆ get_and_increment()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_increment ( )

Atomically increments the current value by one.

Returns
the old value

Definition at line 274 of file cp.cpp.

275{
276 return get_and_add(1);
277}

◆ get_and_set()

boost::future< int64_t > hazelcast::cp::atomic_long::get_and_set ( int64_t new_value)

Atomically sets the given value and returns the old value.

Parameters
newValuethe new value
Returns
the old value

Definition at line 260 of file cp.cpp.

261{
262 auto request =
263 atomiclong_getandset_encode(group_id_, object_name_, new_value);
264 return invoke_and_get_future<int64_t>(request);
265}

◆ increment_and_get()

boost::future< int64_t > hazelcast::cp::atomic_long::increment_and_get ( )

Atomically increments the current value by one.

Returns
the updated value, the current value incremented by one

Definition at line 268 of file cp.cpp.

269{
270 return add_and_get(1);
271}

◆ set()

boost::future< void > hazelcast::cp::atomic_long::set ( int64_t new_value)

Atomically sets the given value.

Parameters
newValuethe new value

Definition at line 280 of file cp.cpp.

281{
282 return to_void_future(get_and_set(new_value));
283}
boost::future< int64_t > get_and_set(int64_t new_value)
Atomically sets the given value and returns the old value.
Definition cp.cpp:260

The documentation for this class was generated from the following files:
  • hazelcast/include/hazelcast/cp/cp.h
  • hazelcast/src/hazelcast/cp/cp.cpp