Hazelcast C++ Client
Hazelcast C++ Client Library
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. More...
 
template<typename HazelcastSerializable >
void execute (const HazelcastSerializable &command, const member_selector &member_selector)
 Executes a task on a randomly selected member. More...
 
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. More...
 
template<typename HazelcastSerializable >
void execute_on_member (const HazelcastSerializable &command, const member &member)
 Executes a task on the specified member. More...
 
template<typename HazelcastSerializable >
void execute_on_members (const HazelcastSerializable &command, const std::vector< member > &members)
 Executes a task on each of the specified members. More...
 
template<typename HazelcastSerializable >
void execute_on_members (const HazelcastSerializable &command, const member_selector &member_selector)
 Executes a task on each of the selected members. More...
 
template<typename HazelcastSerializable >
void execute_on_all_members (const HazelcastSerializable &command)
 Executes a task on all of the known cluster members. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void shutdown ()
 Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. More...
 
boost::future< bool > is_shutdown ()
 Returns. More...
 
boost::future< bool > is_terminated ()
 Returns. More...
 

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 119 of file iexecutor_service.h.

119  {
120  submit<HazelcastSerializable, executor_marker>(command);
121  }

◆ 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 131 of file iexecutor_service.h.

132  {
133  std::vector<member> members = select_members(member_selector);
134  int selectedMember = rand() % (int) members.size();
135  execute_on_member<HazelcastSerializable>(command, members[selectedMember]);
136  }

◆ 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 193 of file iexecutor_service.h.

193  {
194  std::vector<member> memberList = get_context().get_client_cluster_service().get_member_list();
195  for (std::vector<member>::const_iterator it = memberList.begin(); it != memberList.end(); ++it) {
196  submit_to_member<HazelcastSerializable, executor_marker>(command, *it);
197  }
198  }

◆ 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 145 of file iexecutor_service.h.

145  {
146  submit_to_key_owner<HazelcastSerializable, K>(command, key);
147  }

◆ 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 156 of file iexecutor_service.h.

156  {
157  submit_to_member<HazelcastSerializable, executor_marker>(command, member);
158  }

◆ 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 181 of file iexecutor_service.h.

182  {
183  std::vector<member> members = select_members(member_selector);
184  execute_on_members<HazelcastSerializable>(command, members);
185  }

◆ 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 167 of file iexecutor_service.h.

167  {
168  for (std::vector<member>::const_iterator it = members.begin(); it != members.end(); ++it) {
169  submit_to_member<HazelcastSerializable, executor_marker>(command, *it);
170  }
171  }

◆ 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 565 of file client_impl.cpp.

565  {
566  auto request = protocol::codec::executorservice_isshutdown_encode(
567  get_name());
568  return invoke_and_get_future<bool>(
569  request);
570  }

◆ 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

void shutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will...

.

Returns
true
if all tasks have completed following shut down

Definition at line 572 of file client_impl.cpp.

572  {
573  return is_shutdown();
574  }
boost::future< bool > is_shutdown()
Returns.

◆ 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 559 of file client_impl.cpp.

559  {
560  auto request = protocol::codec::executorservice_shutdown_encode(
561  get_name());
562  invoke(request);
563  }

◆ 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 304 of file iexecutor_service.h.

304  {
305  serialization::pimpl::data task_data = to_data<HazelcastSerializable>(task);
306 
307  if (task_data.has_partition_hash()) {
308  int partitionId = get_partition_id(task_data);
309 
310  return submit_to_partition_internal<T>(task_data, false, partitionId);
311  } else {
312  return submit_to_random_internal<T>(task_data, false);
313  }
314  }

◆ 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 328 of file iexecutor_service.h.

328  {
329  std::vector<member> members = select_members(member_selector);
330  int selectedMember = rand() % (int) members.size();
331  return submit_to_member<HazelcastSerializable, T>(task, members[selectedMember]);
332  }

◆ 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 279 of file iexecutor_service.h.

279  {
280  std::unordered_map<member, executor_promise<T>> futureMap;
281  for (const auto &m : get_context().get_client_cluster_service().get_member_list()) {
282  auto f = submit_to_target_internal<HazelcastSerializable, T>(task, m, true);
283  // no need to check if emplace is success since member is unique
284  futureMap.emplace(m, std::move(f));
285  }
286  return futureMap;
287  }

◆ 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 211 of file iexecutor_service.h.

211  {
212  return submit_to_key_owner_internal<HazelcastSerializable, T, K>(task, key, false);
213  }

◆ 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 226 of file iexecutor_service.h.

226  {
227  return submit_to_target_internal<HazelcastSerializable, T>(task, member, false);
228  }

◆ 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 263 of file iexecutor_service.h.

264  {
265  std::vector<member> members = select_members(member_selector);
266  return submit_to_members<HazelcastSerializable, T>(task, members);
267  }

◆ 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 241 of file iexecutor_service.h.

241  {
242  std::unordered_map<member, executor_promise<T>> futureMap;
243  for (auto &member : members) {
244  auto f = submit_to_target_internal<HazelcastSerializable, T>(task, member, true);
245  // no need to check if emplace is success since member is unique
246  futureMap.emplace(member, std::move(f));
247  }
248  return futureMap;
249  }

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