Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast::client::iexecutor_service Class Reference

Distributed implementation of java.util.concurrent.ExecutorService. More...

#include <iexecutor_service.h>

Inheritance diagram for hazelcast::client::iexecutor_service:

Classes

class  executor_promise

Public Member Functions

template<typename HazelcastSerializable>
void execute (const HazelcastSerializable &command)
 Executes the given command at some time in the future.
template<typename HazelcastSerializable>
void execute (const HazelcastSerializable &command, const member_selector &member_selector)
 Executes a task on a randomly selected member.
template<typename HazelcastSerializable, typename K>
void execute_on_key_owner (const HazelcastSerializable &command, const K &key)
 Executes a task on the owner of the specified key.
template<typename HazelcastSerializable>
void execute_on_member (const HazelcastSerializable &command, const member &member)
 Executes a task on the specified member.
template<typename HazelcastSerializable>
void execute_on_members (const HazelcastSerializable &command, const std::vector< member > &members)
 Executes a task on each of the specified members.
template<typename HazelcastSerializable>
void execute_on_members (const HazelcastSerializable &command, const member_selector &member_selector)
 Executes a task on each of the selected members.
template<typename HazelcastSerializable>
void execute_on_all_members (const HazelcastSerializable &command)
 Executes a task on all of the known cluster members.
template<typename HazelcastSerializable, typename T, typename K>
executor_promise< T > submit_to_key_owner (const HazelcastSerializable &task, const K &key)
 Submits a task to the owner of the specified key and returns a executor_promise representing that task.
template<typename HazelcastSerializable, typename T>
executor_promise< T > submit_to_member (const HazelcastSerializable &task, const member &member)
 Submits a task to the specified member and returns a executor_promise representing that task.
template<typename HazelcastSerializable, typename T>
std::unordered_map< member, executor_promise< T > > submit_to_members (const HazelcastSerializable &task, const std::vector< member > &members)
 Submits a task to given members and returns map of Member-executor_promise pairs representing pending completion of the task on each member.
template<typename HazelcastSerializable, typename T>
std::unordered_map< member, executor_promise< T > > submit_to_members (const HazelcastSerializable &task, const member_selector &member_selector)
 Submits a task to selected members and returns a map of Member-executor_promise pairs representing pending completion of the task on each member.
template<typename HazelcastSerializable, typename T>
std::unordered_map< member, executor_promise< T > > submit_to_all_members (const HazelcastSerializable &task)
 Submits task to all cluster members and returns a map of Member-executor_promise pairs representing pending completion of the task on each member.
template<typename HazelcastSerializable, typename T>
executor_promise< T > submit (const HazelcastSerializable &task)
 Submits a task for execution and returns a executor_promise representing that task.
template<typename HazelcastSerializable, typename T>
executor_promise< T > submit (const HazelcastSerializable &task, const member_selector &member_selector)
 Submits a task to a randomly selected member and returns a executor_promise representing that task.
void shutdown ()
 Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
boost::future< bool > is_shutdown ()
 Returns true if this executor has been shut down.
boost::future< bool > is_terminated ()
 Returns true if all tasks have completed following shut down.

Static Public Attributes

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

Friends

class spi::ProxyManager

Detailed Description

Distributed implementation of java.util.concurrent.ExecutorService.

IExecutorService provides additional methods like executing tasks on a specific member, on a member who is owner of a specific key, executing a tasks on multiple members.

Definition at line 50 of file iexecutor_service.h.

Member Function Documentation

◆ execute() [1/2]

template<typename HazelcastSerializable>
void hazelcast::client::iexecutor_service::execute ( const HazelcastSerializable & command)
inline

Executes the given command at some time in the future.

The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Parameters
commandthe runnable task
Exceptions
rejected_executionif this task cannot be accepted for execution

Definition at line 151 of file iexecutor_service.h.

152 {
154 }
executor_promise< T > submit(const HazelcastSerializable &task)
Submits a task for execution and returns a executor_promise representing that task.

◆ execute() [2/2]

template<typename HazelcastSerializable>
void hazelcast::client::iexecutor_service::execute ( const HazelcastSerializable & command,
const member_selector & member_selector )
inline

Executes a task on a randomly selected member.

Parameters
commandthe task that is executed on a randomly selected member
memberSelectormemberSelector
Exceptions
rejected_executionif no member is selected

Definition at line 165 of file iexecutor_service.h.

167 {
168 std::vector<member> members = select_members(member_selector);
169 int selectedMember = rand() % (int)members.size();
171 members[selectedMember]);
172 }
void execute_on_member(const HazelcastSerializable &command, const member &member)
Executes a task on the specified member.

◆ execute_on_all_members()

template<typename HazelcastSerializable>
void hazelcast::client::iexecutor_service::execute_on_all_members ( const HazelcastSerializable & command)
inline

Executes a task on all of the known cluster members.

Parameters
commanda task executed on all of the known cluster members

Definition at line 240 of file iexecutor_service.h.

241 {
242 std::vector<member> memberList =
243 get_context().get_client_cluster_service().get_member_list();
244 for (std::vector<member>::const_iterator it = memberList.begin();
245 it != memberList.end();
246 ++it) {
248 *it);
249 }
250 }
executor_promise< T > submit_to_member(const HazelcastSerializable &task, const member &member)
Submits a task to the specified member and returns a executor_promise representing that task.

◆ execute_on_key_owner()

template<typename HazelcastSerializable, typename K>
void hazelcast::client::iexecutor_service::execute_on_key_owner ( const HazelcastSerializable & command,
const K & key )
inline

Executes a task on the owner of the specified key.

Parameters
commanda task executed on the owner of the specified key
keythe specified key

Definition at line 181 of file iexecutor_service.h.

183 {
185 }
executor_promise< T > submit_to_key_owner(const HazelcastSerializable &task, const K &key)
Submits a task to the owner of the specified key and returns a executor_promise representing that tas...

◆ execute_on_member()

template<typename HazelcastSerializable>
void hazelcast::client::iexecutor_service::execute_on_member ( const HazelcastSerializable & command,
const member & member )
inline

Executes a task on the specified member.

Parameters
commandthe task executed on the specified member
memberthe specified member

Definition at line 194 of file iexecutor_service.h.

196 {
198 member);
199 }

◆ execute_on_members() [1/2]

template<typename HazelcastSerializable>
void hazelcast::client::iexecutor_service::execute_on_members ( const HazelcastSerializable & command,
const member_selector & member_selector )
inline

Executes a task on each of the selected members.

Parameters
commanda task executed on each of the selected members
memberSelectormemberSelector
Exceptions
rejected_executionif no member is selected

Definition at line 227 of file iexecutor_service.h.

229 {
230 std::vector<member> members = select_members(member_selector);
232 }
void execute_on_members(const HazelcastSerializable &command, const std::vector< member > &members)
Executes a task on each of the specified members.

◆ execute_on_members() [2/2]

template<typename HazelcastSerializable>
void hazelcast::client::iexecutor_service::execute_on_members ( const HazelcastSerializable & command,
const std::vector< member > & members )
inline

Executes a task on each of the specified members.

Parameters
commandthe task executed on the specified members
membersthe specified members

Definition at line 208 of file iexecutor_service.h.

210 {
211 for (std::vector<member>::const_iterator it = members.begin();
212 it != members.end();
213 ++it) {
215 *it);
216 }
217 }

◆ is_shutdown()

boost::future< bool > hazelcast::client::iexecutor_service::is_shutdown ( )

Returns true if this executor has been shut down.

Returns
true if this executor has been shut down

Definition at line 941 of file client_impl.cpp.

942{
943 auto request =
944 protocol::codec::executorservice_isshutdown_encode(get_name());
945 return invoke_and_get_future<bool>(request);
946}

◆ is_terminated()

boost::future< bool > hazelcast::client::iexecutor_service::is_terminated ( )

Returns true if all tasks have completed following shut down.

Note that isTerminated is never true unless either shutdown.

Returns
true if all tasks have completed following shut down

Definition at line 949 of file client_impl.cpp.

950{
951 return is_shutdown();
952}
boost::future< bool > is_shutdown()
Returns true if this executor has been shut down.

◆ shutdown()

void hazelcast::client::iexecutor_service::shutdown ( )

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to complete execution.

Definition at line 934 of file client_impl.cpp.

935{
936 auto request = protocol::codec::executorservice_shutdown_encode(get_name());
937 invoke(request);
938}

◆ submit() [1/2]

template<typename HazelcastSerializable, typename T>
executor_promise< T > hazelcast::client::iexecutor_service::submit ( const HazelcastSerializable & task)
inline

Submits a task for execution and returns a executor_promise representing that task.

The executor_promise's
executor_promise::get
method will return the given result upon successful completion.

Parameters
taskthe task to submit
resultthe result to return
<T>the type of the result
Returns
a executor_promise representing pending completion of the task
Exceptions
rejected_executionif the task cannot be scheduled for execution
null_pointerif the task is null

Definition at line 373 of file iexecutor_service.h.

374 {
375 serialization::pimpl::data task_data =
376 to_data<HazelcastSerializable>(task);
377
378 if (task_data.has_partition_hash()) {
379 int partitionId = get_partition_id(task_data);
380
381 return submit_to_partition_internal<T>(
382 task_data, false, partitionId);
383 } else {
384 return submit_to_random_internal<T>(task_data, false);
385 }
386 }

◆ submit() [2/2]

template<typename HazelcastSerializable, typename T>
executor_promise< T > hazelcast::client::iexecutor_service::submit ( const HazelcastSerializable & task,
const member_selector & member_selector )
inline

Submits a task to a randomly selected member and returns a executor_promise representing that task.

Parameters
tasktask submitted to a randomly selected member
memberSelectormemberSelector
<T>the result type of callable
Returns
a executor_promise representing pending completion of the task
Exceptions
rejected_executionif no member is selected

Definition at line 399 of file iexecutor_service.h.

401 {
402 std::vector<member> members = select_members(member_selector);
403 int selectedMember = rand() % (int)members.size();
405 task, members[selectedMember]);
406 }

◆ submit_to_all_members()

template<typename HazelcastSerializable, typename T>
std::unordered_map< member, executor_promise< T > > hazelcast::client::iexecutor_service::submit_to_all_members ( const HazelcastSerializable & task)
inline

Submits task to all cluster members and returns a map of Member-executor_promise pairs representing pending completion of the task on each member.

Parameters
taskthe task submitted to all cluster members
<T>the result type of callable
Returns
map of Member-executor_promise pairs representing pending completion of the task on each member

Definition at line 344 of file iexecutor_service.h.

346 {
347 std::unordered_map<member, executor_promise<T>> futureMap;
348 for (const auto& m :
349 get_context().get_client_cluster_service().get_member_list()) {
350 auto f = submit_to_target_internal<HazelcastSerializable, T>(
351 task, m, true);
352 // no need to check if emplace is success since member is unique
353 futureMap.emplace(m, std::move(f));
354 }
355 return futureMap;
356 }

◆ submit_to_key_owner()

template<typename HazelcastSerializable, typename T, typename K>
executor_promise< T > hazelcast::client::iexecutor_service::submit_to_key_owner ( const HazelcastSerializable & task,
const K & key )
inline

Submits a task to the owner of the specified key and returns a executor_promise representing that task.

Parameters
tasktask submitted to the owner of the specified key
keythe specified key
<T>the result type of callable
Returns
a executor_promise representing pending completion of the task

Definition at line 262 of file iexecutor_service.h.

264 {
265 return submit_to_key_owner_internal<HazelcastSerializable, T, K>(
266 task, key, false);
267 }

◆ submit_to_member()

template<typename HazelcastSerializable, typename T>
executor_promise< T > hazelcast::client::iexecutor_service::submit_to_member ( const HazelcastSerializable & task,
const member & member )
inline

Submits a task to the specified member and returns a executor_promise representing that task.

Parameters
taskthe task submitted to the specified member
memberthe specified member
<T>the result type of callable
Returns
a executor_promise representing pending completion of the task

Definition at line 279 of file iexecutor_service.h.

281 {
282 return submit_to_target_internal<HazelcastSerializable, T>(
283 task, member, false);
284 }

◆ submit_to_members() [1/2]

template<typename HazelcastSerializable, typename T>
std::unordered_map< member, executor_promise< T > > hazelcast::client::iexecutor_service::submit_to_members ( const HazelcastSerializable & task,
const member_selector & member_selector )
inline

Submits a task to selected members and returns a map of Member-executor_promise pairs representing pending completion of the task on each member.

Parameters
taskthe task submitted to selected members
memberSelectormemberSelector
<T>the result type of callable
Returns
map of Member-executor_promise pairs representing pending completion of the task on each member
Exceptions
rejected_executionif no member is selected

Definition at line 325 of file iexecutor_service.h.

328 {
329 std::vector<member> members = select_members(member_selector);
331 }
std::unordered_map< member, executor_promise< T > > submit_to_members(const HazelcastSerializable &task, const std::vector< member > &members)
Submits a task to given members and returns map of Member-executor_promise pairs representing pending...

◆ submit_to_members() [2/2]

template<typename HazelcastSerializable, typename T>
std::unordered_map< member, executor_promise< T > > hazelcast::client::iexecutor_service::submit_to_members ( const HazelcastSerializable & task,
const std::vector< member > & members )
inline

Submits a task to given members and returns map of Member-executor_promise pairs representing pending completion of the task on each member.

Parameters
taskthe task submitted to given members
membersthe given members
<T>the result type of callable
Returns
map of Member-executor_promise pairs representing pending completion of the task on each member

Definition at line 298 of file iexecutor_service.h.

301 {
302 std::unordered_map<member, executor_promise<T>> futureMap;
303 for (auto& member : members) {
304 auto f = submit_to_target_internal<HazelcastSerializable, T>(
305 task, member, true);
306 // no need to check if emplace is success since member is unique
307 futureMap.emplace(member, std::move(f));
308 }
309 return futureMap;
310 }

◆ spi::ProxyManager

friend class spi::ProxyManager
friend

Definition at line 52 of file iexecutor_service.h.

Member Data Documentation

◆ SERVICE_NAME

const char* hazelcast::client::iexecutor_service::SERVICE_NAME = "hz:impl:executorService"
staticconstexpr

Definition at line 55 of file iexecutor_service.h.


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