Hazelcast C++ Client
IExecutorService.h
1 /*
2  * Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HAZELCAST_CLIENT_IEXECUTORSERVICE_H_
17 #define HAZELCAST_CLIENT_IEXECUTORSERVICE_H_
18 
19 #include <vector>
20 
21 #include "hazelcast/util/HazelcastDll.h"
22 #include "hazelcast/client/cluster/memberselector/MemberSelectors.h"
23 #include "hazelcast/client/ICompletableFuture.h"
24 #include "hazelcast/client/proxy/ProxyImpl.h"
25 #include "hazelcast/client/ExecutionCallback.h"
26 #include "hazelcast/client/MultiExecutionCallback.h"
27 #include "hazelcast/client/Member.h"
28 #include "hazelcast/client/spi/ClientClusterService.h"
29 #include "hazelcast/client/spi/ClientContext.h"
30 #include "hazelcast/util/UuidUtil.h"
31 #include "hazelcast/client/spi/impl/ClientInvocation.h"
32 #include "hazelcast/util/ExceptionUtil.h"
33 #include "hazelcast/client/spi/impl/ClientExecutionServiceImpl.h"
34 #include "hazelcast/client/internal/executor/CompletedFuture.h"
35 #include "hazelcast/client/proxy/IExecutorDelegatingFuture.h"
36 
37 // CODECs
38 #include "hazelcast/client/protocol/codec/ExecutorServiceSubmitToPartitionCodec.h"
39 #include "hazelcast/client/protocol/codec/ExecutorServiceSubmitToAddressCodec.h"
40 
41 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
42 #pragma warning(push)
43 #pragma warning(disable: 4251) //for dll export
44 #endif
45 
46 namespace hazelcast {
47  namespace client {
48  namespace executor {
49  namespace impl {
50  class ExecutorServiceProxyFactory;
51  }
52  }
53 
64  class HAZELCAST_API IExecutorService : public proxy::ProxyImpl {
65  friend class executor::impl::ExecutorServiceProxyFactory;
66 
67  public:
68  static const std::string SERVICE_NAME;
69 
79  template<typename HazelcastSerializable>
80  void execute(const HazelcastSerializable &command) {
81  submit<HazelcastSerializable, bool>(command);
82  }
83 
91  template<typename HazelcastSerializable>
92  void execute(const HazelcastSerializable &command,
93  const cluster::memberselector::MemberSelector &memberSelector) {
94  std::vector<Member> members = selectMembers(memberSelector);
95  int selectedMember = rand() % (int) members.size();
96  executeOnMember<HazelcastSerializable>(command, members[selectedMember]);
97  }
98 
105  template<typename HazelcastSerializable, typename K>
106  void executeOnKeyOwner(const HazelcastSerializable &command, const K &key) {
107  submitToKeyOwner<HazelcastSerializable, K>(command, key);
108  }
109 
116  template<typename HazelcastSerializable>
117  void executeOnMember(const HazelcastSerializable &command, const Member &member) {
118  submitToMember<HazelcastSerializable, bool>(command, member);
119  }
120 
127  template<typename HazelcastSerializable>
128  void executeOnMembers(const HazelcastSerializable &command, const std::vector<Member> &members) {
129  for (std::vector<Member>::const_iterator it = members.begin(); it != members.end(); ++it) {
130  submitToMember<HazelcastSerializable, bool>(command, *it);
131  }
132  }
133 
141  template<typename HazelcastSerializable>
142  void executeOnMembers(const HazelcastSerializable &command,
143  const cluster::memberselector::MemberSelector &memberSelector) {
144  std::vector<Member> members = selectMembers(memberSelector);
145  executeOnMembers<HazelcastSerializable>(command, members);
146  }
147 
153  template<typename HazelcastSerializable>
154  void executeOnAllMembers(const HazelcastSerializable &command) {
155  std::vector<Member> memberList = getContext().getClientClusterService().getMemberList();
156  for (std::vector<Member>::const_iterator it = memberList.begin(); it != memberList.end(); ++it) {
157  submitToMember<HazelcastSerializable, bool>(command, *it);
158  }
159  }
160 
170  template<typename HazelcastSerializable, typename T, typename K>
171  boost::shared_ptr<ICompletableFuture<T> >
172  submitToKeyOwner(const HazelcastSerializable &task, const K &key) {
173  return submitToKeyOwnerInternal<HazelcastSerializable, T, K>(task, key, boost::shared_ptr<T>(), false);
174  }
175 
185  template<typename HazelcastSerializable, typename T>
186  boost::shared_ptr<ICompletableFuture<T> >
187  submitToMember(const HazelcastSerializable &task, const Member &member) {
188  const Address memberAddress = getMemberAddress(member);
189  return submitToTargetInternal<HazelcastSerializable, T>(task, memberAddress, boost::shared_ptr<T>(),
190  false);
191  }
192 
202  template<typename HazelcastSerializable, typename T>
203  std::map<Member, boost::shared_ptr<ICompletableFuture<T> > >
204  submitToMembers(const HazelcastSerializable &task, const std::vector<Member> &members) {
205  std::map<Member, boost::shared_ptr<ICompletableFuture<T> > > futureMap;
206  for (std::vector<Member>::const_iterator it = members.begin(); it != members.end(); ++it) {
207  Address memberAddress = getMemberAddress(*it);
208  boost::shared_ptr<ICompletableFuture<T> > f = submitToTargetInternal<HazelcastSerializable, T>(task,
209  memberAddress,
210  boost::shared_ptr<T>(),
211  true);
212  futureMap[*it] = f;
213  }
214  return futureMap;
215  }
216 
227  template<typename HazelcastSerializable, typename T>
228  std::map<Member, boost::shared_ptr<ICompletableFuture<T> > >
229  submitToMembers(const HazelcastSerializable &task,
230  const cluster::memberselector::MemberSelector &memberSelector) {
231  std::vector<Member> members = selectMembers(memberSelector);
232  return submitToMembers<HazelcastSerializable, T>(task, members);
233  }
234 
243  template<typename HazelcastSerializable, typename T>
244  std::map<Member, boost::shared_ptr<ICompletableFuture<T> > >
245  submitToAllMembers(const HazelcastSerializable &task) {
246  std::vector<Member> members = getContext().getClientClusterService().getMemberList();
247  std::map<Member, boost::shared_ptr<ICompletableFuture<T> > > futureMap;
248  for (std::vector<Member>::const_iterator it = members.begin(); it != members.end(); ++it) {
249  Address memberAddress = getMemberAddress(*it);
250  boost::shared_ptr<ICompletableFuture<T> > f = submitToTargetInternal<HazelcastSerializable, T>(task,
251  memberAddress,
252  boost::shared_ptr<T>(),
253  true);
254  futureMap[*it] = f;
255  }
256  return futureMap;
257  }
258 
272  template<typename HazelcastSerializable, typename T>
273  boost::shared_ptr<ICompletableFuture<T> >
274  submit(const HazelcastSerializable &task, const boost::shared_ptr<T> &result) {
275  Data taskData = toData<HazelcastSerializable>(task);
276 
277  if (taskData.hasPartitionHash()) {
278  int partitionId = getPartitionId(taskData);
279 
280  return submitToPartitionInternal<T>(taskData, result, false, partitionId);
281  } else {
282  return submitToRandomInternal<T>(taskData, result, false);
283  }
284  }
285 
304  template<typename HazelcastSerializable, typename T>
305  boost::shared_ptr<ICompletableFuture<T> > submit(const HazelcastSerializable &task) {
306  return submit<HazelcastSerializable, T>(task, boost::shared_ptr<T>());
307  }
308 
317  template<typename HazelcastSerializable, typename T>
318  void submit(const HazelcastSerializable &task, const boost::shared_ptr<ExecutionCallback<T> > &callback) {
319  Data taskData = toData<HazelcastSerializable>(task);
320 
321  if (taskData.hasPartitionHash()) {
322  int partitionId = getPartitionId(taskData);
323 
324  submitToPartitionInternal<T>(taskData, partitionId, callback);
325  } else {
326  submitToRandomInternal<T>(taskData, callback);
327  }
328  }
329 
340  template<typename HazelcastSerializable, typename T>
341  boost::shared_ptr<ICompletableFuture<T> >
342  submit(const HazelcastSerializable &task, const cluster::memberselector::MemberSelector &memberSelector) {
343  std::vector<Member> members = selectMembers(memberSelector);
344  int selectedMember = rand() % (int) members.size();
345  return submitToMember<HazelcastSerializable, T>(task, members[selectedMember]);
346  }
347 
358  template<typename HazelcastSerializable, typename T>
359  void
360  submit(const HazelcastSerializable &task, const cluster::memberselector::MemberSelector &memberSelector,
361  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
362  std::vector<Member> members = selectMembers(memberSelector);
363  int selectedMember = rand() % (int) members.size();
364  return submitToMember(task, members[selectedMember], callback);
365  }
366 
376  template<typename HazelcastSerializable, typename T, typename K>
377  void submitToKeyOwner(const HazelcastSerializable &task, const K &key,
378  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
379  submitToKeyOwnerInternal<HazelcastSerializable, T, K>(task, key, callback);
380  }
381 
391  template<typename HazelcastSerializable, typename T>
392  void submitToMember(const HazelcastSerializable &task, const Member &member,
393  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
394  const Address memberAddress = getMemberAddress(member);
395  return submitToTargetInternal<HazelcastSerializable, T>(task, memberAddress, callback);
396  }
397 
407  template<typename HazelcastSerializable, typename T>
408  void submitToMembers(const HazelcastSerializable &task, const std::vector<Member> &members,
409  const boost::shared_ptr<MultiExecutionCallback<T> > &callback) {
410  boost::shared_ptr<MultiExecutionCallbackWrapper < T> >
411  multiExecutionCallbackWrapper(new MultiExecutionCallbackWrapper<T>((int) members.size(), callback));
412 
413  for (std::vector<Member>::const_iterator it = members.begin(); it != members.end(); ++it) {
414  boost::shared_ptr<ExecutionCallbackWrapper < T> >
415  executionCallback(new ExecutionCallbackWrapper<T>(multiExecutionCallbackWrapper, *it));
416  submitToMember<HazelcastSerializable, T>(task, *it, executionCallback);
417  }
418  }
419 
430  template<typename HazelcastSerializable, typename T>
431  void submitToMembers(const HazelcastSerializable &task,
432  const cluster::memberselector::MemberSelector &memberSelector,
433  const boost::shared_ptr<MultiExecutionCallback<T> > &callback) {
434  std::vector<Member> members = selectMembers(memberSelector);
435  submitToMembers<HazelcastSerializable, T>(task, members, callback);
436  }
437 
446  template<typename HazelcastSerializable, typename T>
447  void submitToAllMembers(const HazelcastSerializable &task,
448  const boost::shared_ptr<MultiExecutionCallback<T> > &callback) {
449  std::vector<Member> memberList = getContext().getClientClusterService().getMemberList();
450  submitToMembers<HazelcastSerializable, T>(task, memberList, callback);
451  boost::shared_ptr<MultiExecutionCallbackWrapper < T> >
452  multiExecutionCallbackWrapper(new MultiExecutionCallbackWrapper<T>((int) memberList.size(), callback));
453  for (std::vector<Member>::const_iterator it = memberList.begin(); it != memberList.end(); ++it) {
454  boost::shared_ptr<ExecutionCallbackWrapper < T> >
455  executionCallback(new ExecutionCallbackWrapper<T>(multiExecutionCallbackWrapper, *it));
456  submitToMember<HazelcastSerializable, T>(task, *it, executionCallback);
457  }
458  }
459 
469  void shutdown();
470 
476  bool isShutdown();
477 
485  bool isTerminated();
486 
487  private:
488  IExecutorService(const std::string &name, spi::ClientContext *context);
489 
490  template<typename T>
491  class MultiExecutionCallbackWrapper : MultiExecutionCallback<T> {
492  public:
493  MultiExecutionCallbackWrapper(
494  int memberSize, const boost::shared_ptr<MultiExecutionCallback<T> > &multiExecutionCallback)
495  : multiExecutionCallback(multiExecutionCallback), members(memberSize) {
496  }
497 
498  public:
499  virtual void onResponse(const Member &member, const boost::shared_ptr<T> &value) {
500  multiExecutionCallback->onResponse(member, value);
501  values.put(member, value);
502 
503  int waitingResponse = --members;
504  if (waitingResponse == 0) {
505  complete();
506  }
507  }
508 
509  virtual void
510  onFailure(const Member &member, const boost::shared_ptr<exception::IException> &exception) {
511  multiExecutionCallback->onFailure(member, exception);
512  exceptions.put(member, exception);
513 
514  int waitingResponse = --members;
515  if (waitingResponse == 0) {
516  complete();
517  }
518  }
519 
520  virtual void onComplete(const std::map<Member, boost::shared_ptr<T> > &values,
521  const std::map<Member, boost::shared_ptr<exception::IException> > &exceptions) {
522  multiExecutionCallback->onComplete(values, exceptions);
523  }
524 
525  private:
526  void complete() {
527  std::map<Member, boost::shared_ptr<T> > completedValues;
528  typedef std::vector<std::pair<Member, boost::shared_ptr<T> > > ENTRYVECTOR;
529  ENTRYVECTOR entries = values.entrySet();
530  for (typename ENTRYVECTOR::const_iterator it = entries.begin();
531  it != entries.end(); ++it) {
532  completedValues[it->first] = it->second;
533  }
534 
535  std::map<Member, boost::shared_ptr<exception::IException> > completedExceptions;
536  typedef std::vector<std::pair<Member, boost::shared_ptr<exception::IException> > > EXCEPTIONVECTOR;
537  EXCEPTIONVECTOR exceptionEntries = exceptions.entrySet();
538  for (typename EXCEPTIONVECTOR::const_iterator it = exceptionEntries.begin();
539  it != exceptionEntries.end(); ++it) {
540  completedExceptions[it->first] = it->second;
541  }
542 
543  onComplete(completedValues, completedExceptions);
544  }
545 
546  const boost::shared_ptr<MultiExecutionCallback<T> > multiExecutionCallback;
547  util::SynchronizedMap<Member, T> values;
548  util::SynchronizedMap<Member, exception::IException> exceptions;
549  util::AtomicInt members;
550  };
551 
552  template<typename T>
553  class ExecutionCallbackWrapper : public ExecutionCallback<T> {
554  public:
555  ExecutionCallbackWrapper(
556  const boost::shared_ptr<MultiExecutionCallbackWrapper<T> > &multiExecutionCallbackWrapper,
557  const Member &member) : multiExecutionCallbackWrapper(multiExecutionCallbackWrapper),
558  member(member) {}
559 
560  virtual void onResponse(const boost::shared_ptr<T> &response) {
561  multiExecutionCallbackWrapper->onResponse(member, response);
562  }
563 
564  virtual void onFailure(const boost::shared_ptr<exception::IException> &e) {
565  multiExecutionCallbackWrapper->onFailure(member, e);
566  }
567 
568  private:
569  const boost::shared_ptr<MultiExecutionCallbackWrapper<T> > multiExecutionCallbackWrapper;
570  const Member member;
571  };
572 
573  std::vector<Member> selectMembers(const cluster::memberselector::MemberSelector &memberSelector);
574 
575  template<typename T>
576  boost::shared_ptr<ICompletableFuture<T> >
577  submitToPartitionInternal(const serialization::pimpl::Data &taskData,
578  const boost::shared_ptr<T> &defaultValue,
579  bool preventSync, int partitionId) {
580  std::string uuid = util::UuidUtil::newUnsecureUuidString();
581 
582  boost::shared_ptr<spi::impl::ClientInvocationFuture> f = invokeOnPartitionInternal(taskData,
583  partitionId, uuid);
584 
585  return checkSync(f, uuid, partitionId, preventSync, defaultValue);
586  }
587 
588  template<typename T>
589  void submitToPartitionInternal(const serialization::pimpl::Data &taskData, int partitionId,
590  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
591  std::string uuid = util::UuidUtil::newUnsecureUuidString();
592 
593  boost::shared_ptr<spi::impl::ClientInvocationFuture> f = invokeOnPartitionInternal(taskData,
594  partitionId, uuid);
595 
596 
597  boost::shared_ptr<ICompletableFuture<T> > delegatingFuture(
598  new internal::ClientDelegatingFuture<T>(f, getContext().getSerializationService(),
599  SUBMIT_TO_PARTITION_DECODER<T>(),
600  boost::shared_ptr<T>()));
601 
602  delegatingFuture->andThen(callback);
603  }
604 
605  boost::shared_ptr<spi::impl::ClientInvocationFuture>
606  invokeOnPartitionInternal(const Data &taskData, int partitionId, const std::string &uuid) {
607  std::auto_ptr<protocol::ClientMessage> request =
608  protocol::codec::ExecutorServiceSubmitToPartitionCodec::encodeRequest(name, uuid, taskData,
609  partitionId);
610 
611  return invokeOnPartitionOwner(request, partitionId);
612  }
613 
614  template<typename HazelcastSerializable, typename T, typename K>
615  boost::shared_ptr<ICompletableFuture<T> >
616  submitToKeyOwnerInternal(const HazelcastSerializable &task, const K &key,
617  const boost::shared_ptr<T> &defaultValue, bool preventSync) {
618 
619  Data dataKey = toData<K>(key);
620 
621  int partitionId = getPartitionId(dataKey);
622 
623  return submitToPartitionInternal<T>(toData<HazelcastSerializable>(task), defaultValue, preventSync,
624  partitionId);
625  }
626 
627  template<typename HazelcastSerializable, typename T, typename K>
628  void submitToKeyOwnerInternal(const HazelcastSerializable &task, const K &key,
629  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
630 
631  Data dataKey = toData<K>(key);
632 
633  int partitionId = getPartitionId(dataKey);
634 
635  submitToPartitionInternal<T>(toData<HazelcastSerializable>(task), partitionId, callback);
636  }
637 
638  template<typename T>
639  boost::shared_ptr<ICompletableFuture<T> >
640  submitToRandomInternal(const serialization::pimpl::Data &taskData, const boost::shared_ptr<T> &defaultValue,
641  bool preventSync) {
642 
643  int partitionId = randomPartitionId();
644 
645  return submitToPartitionInternal<T>(taskData, defaultValue, preventSync, partitionId);
646  }
647 
648  template<typename T>
649  void submitToRandomInternal(const serialization::pimpl::Data &taskData,
650  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
651 
652  int partitionId = randomPartitionId();
653 
654  submitToPartitionInternal<T>(taskData, partitionId, callback);
655  }
656 
657  template<typename HazelcastSerializable, typename T>
658  boost::shared_ptr<ICompletableFuture<T> >
659  submitToTargetInternal(const HazelcastSerializable &task, const Address &address,
660  const boost::shared_ptr<T> &defaultValue, bool preventSync) {
661  std::string uuid = util::UuidUtil::newUnsecureUuidString();
662 
663  boost::shared_ptr<spi::impl::ClientInvocationFuture> f = invokeOnAddressInternal<HazelcastSerializable>(
664  task, address, uuid);
665 
666  return checkSync<T>(f, uuid, address, preventSync, defaultValue);
667  }
668 
669  template<typename HazelcastSerializable, typename T>
670  void submitToTargetInternal(const HazelcastSerializable &task, const Address &address,
671  const boost::shared_ptr<ExecutionCallback<T> > &callback) {
672  std::string uuid = util::UuidUtil::newUnsecureUuidString();
673 
674  boost::shared_ptr<spi::impl::ClientInvocationFuture> f = invokeOnAddressInternal<HazelcastSerializable>(
675  task, address, uuid);
676 
677  boost::shared_ptr<ICompletableFuture<T> > delegatingFuture(
678  new internal::ClientDelegatingFuture<T>(f, getContext().getSerializationService(),
679  SUBMIT_TO_ADDRESS_DECODER<T>(),
680  boost::shared_ptr<T>()));
681 
682  delegatingFuture->andThen(callback);
683  }
684 
685  template<typename HazelcastSerializable>
686  boost::shared_ptr<spi::impl::ClientInvocationFuture>
687  invokeOnAddressInternal(const HazelcastSerializable &task, const Address &address,
688  const std::string &uuid) {
689  std::auto_ptr<protocol::ClientMessage> request =
690  protocol::codec::ExecutorServiceSubmitToAddressCodec::encodeRequest(name, uuid,
691  toData(
692  task), address);
693 
694  boost::shared_ptr<spi::impl::ClientInvocationFuture> f = invokeOnTarget(request, address);
695  return f;
696  }
697 
698  boost::shared_ptr<spi::impl::ClientInvocationFuture>
699  invokeOnPartitionOwner(std::auto_ptr<protocol::ClientMessage> &request, int partitionId);
700 
701  boost::shared_ptr<spi::impl::ClientInvocationFuture>
702  invokeOnTarget(std::auto_ptr<protocol::ClientMessage> &request, const Address &target);
703 
704  template<typename T>
705  boost::shared_ptr<T>
706  retrieveResultFromMessage(const boost::shared_ptr<spi::impl::ClientInvocationFuture> &f) {
707  serialization::pimpl::SerializationService &serializationService = getContext().getSerializationService();
708  std::auto_ptr<serialization::pimpl::Data> data = protocol::codec::ExecutorServiceSubmitToAddressCodec::ResponseParameters::decode(
709  *f->get()).response;
710  return boost::shared_ptr<T>(serializationService.toObject<T>(data.get()));
711  }
712 
713  template<typename T>
714  boost::shared_ptr<ICompletableFuture<T> >
715  checkSync(const boost::shared_ptr<spi::impl::ClientInvocationFuture> &f, const std::string &uuid,
716  int partitionId, bool preventSync, boost::shared_ptr<T> defaultValue) {
717  bool sync = isSyncComputation(preventSync);
718  if (sync) {
719  return retrieveResultSync<T>(f);
720  } else {
721  return boost::shared_ptr<ICompletableFuture<T> >(
722  new proxy::IExecutorDelegatingFuture<T>(f, getContext(), uuid, defaultValue,
723  SUBMIT_TO_PARTITION_DECODER<T>(), name,
724  partitionId));
725  }
726 
727  }
728 
729  template<typename T>
730  boost::shared_ptr<ICompletableFuture<T> >
731  checkSync(const boost::shared_ptr<spi::impl::ClientInvocationFuture> &f, const std::string &uuid,
732  const Address &address, bool preventSync, boost::shared_ptr<T> defaultValue) {
733  bool sync = isSyncComputation(preventSync);
734  if (sync) {
735  return retrieveResultSync<T>(f);
736  } else {
737  return boost::shared_ptr<ICompletableFuture<T> >(
738  new proxy::IExecutorDelegatingFuture<T>(f, getContext(), uuid, defaultValue,
739  SUBMIT_TO_ADDRESS_DECODER<T>(), name, address));
740  }
741 
742  }
743 
744  template<typename T>
745  boost::shared_ptr<ICompletableFuture<T> >
746  retrieveResultSync(const boost::shared_ptr<spi::impl::ClientInvocationFuture> &f) {
747  try {
748  boost::shared_ptr<T> response = retrieveResultFromMessage<T>(f);
749  boost::shared_ptr<ExecutorService> userExecutor = getContext().getClientExecutionService().getUserExecutor();
750  return boost::shared_ptr<ICompletableFuture<T> >(
751  new internal::executor::CompletedFuture<T>(response, userExecutor));
752  } catch (exception::IException &e) {
753  boost::shared_ptr<ExecutorService> userExecutor = getContext().getClientExecutionService().getUserExecutor();
754  return boost::shared_ptr<ICompletableFuture<T> >(
755  new internal::executor::CompletedFuture<T>(
756  boost::shared_ptr<exception::IException>(e.clone()), userExecutor));
757  }
758  }
759 
760  bool isSyncComputation(bool preventSync);
761 
762  Address getMemberAddress(const Member &member);
763 
764  int randomPartitionId();
765 
766  template<typename T>
767  static const boost::shared_ptr<impl::ClientMessageDecoder<T> > SUBMIT_TO_PARTITION_DECODER() {
768  return impl::DataMessageDecoder<protocol::codec::ExecutorServiceSubmitToPartitionCodec, T>::instance();
769  }
770 
771  template<typename T>
772  static const boost::shared_ptr<impl::ClientMessageDecoder<T> > SUBMIT_TO_ADDRESS_DECODER() {
773  return impl::DataMessageDecoder<protocol::codec::ExecutorServiceSubmitToAddressCodec, T>::instance();
774  }
775 
776  static const int32_t MIN_TIME_RESOLUTION_OF_CONSECUTIVE_SUBMITS = 10;
777  static const int32_t MAX_CONSECUTIVE_SUBMITS = 100;
778 
779  util::Atomic<int32_t> consecutiveSubmits;
780  util::Atomic<int64_t> lastSubmitTime;
781  };
782  }
783 }
784 
785 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
786 #pragma warning(pop)
787 #endif
788 
789 #endif /* HAZELCAST_CLIENT_IEXECUTORSERVICE_H_ */
void submit(const HazelcastSerializable &task, const cluster::memberselector::MemberSelector &memberSelector, const boost::shared_ptr< ExecutionCallback< T > > &callback)
Submits a task to randomly selected members.
Definition: IExecutorService.h:360
void execute(const HazelcastSerializable &command, const cluster::memberselector::MemberSelector &memberSelector)
Executes a task on a randomly selected member.
Definition: IExecutorService.h:92
boost::shared_ptr< ICompletableFuture< T > > submit(const HazelcastSerializable &task)
Submits a value-returning task for execution and returns a ICompletableFuture representing the pendin...
Definition: IExecutorService.h:305
boost::shared_ptr< ICompletableFuture< T > > submitToKeyOwner(const HazelcastSerializable &task, const K &key)
Submits a task to the owner of the specified key and returns a ICompletableFuture representing that t...
Definition: IExecutorService.h:172
The Client Delegating Future is used to delegate ClientInvocationFuture to a user type to be used wit...
Definition: ClientDelegatingFuture.h:40
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:53
void executeOnMembers(const HazelcastSerializable &command, const std::vector< Member > &members)
Executes a task on each of the specified members.
Definition: IExecutorService.h:128
void executeOnKeyOwner(const HazelcastSerializable &command, const K &key)
Executes a task on the owner of the specified key.
Definition: IExecutorService.h:106
void submitToMembers(const HazelcastSerializable &task, const std::vector< Member > &members, const boost::shared_ptr< MultiExecutionCallback< T > > &callback)
Submits a task to the specified members.
Definition: IExecutorService.h:408
boost::shared_ptr< ICompletableFuture< T > > submit(const HazelcastSerializable &task, const cluster::memberselector::MemberSelector &memberSelector)
Submits a task to a randomly selected member and returns a ICompletableFuture representing that task...
Definition: IExecutorService.h:342
void submitToMember(const HazelcastSerializable &task, const Member &member, const boost::shared_ptr< ExecutionCallback< T > > &callback)
Submits a task to the specified member.
Definition: IExecutorService.h:392
void executeOnAllMembers(const HazelcastSerializable &command)
Executes a task on all of the known cluster members.
Definition: IExecutorService.h:154
IP Address.
Definition: Address.h:41
void submit(const HazelcastSerializable &task, const boost::shared_ptr< ExecutionCallback< T > > &callback)
Submits a task to a random member.
Definition: IExecutorService.h:318
boost::shared_ptr< ICompletableFuture< T > > submit(const HazelcastSerializable &task, const boost::shared_ptr< T > &result)
Submits a task for execution and returns a ICompletableFuture representing that task.
Definition: IExecutorService.h:274
std::map< Member, boost::shared_ptr< ICompletableFuture< T > > > submitToMembers(const HazelcastSerializable &task, const cluster::memberselector::MemberSelector &memberSelector)
Submits a task to selected members and returns a map of Member-ICompletableFuture pairs representing ...
Definition: IExecutorService.h:229
void submitToMembers(const HazelcastSerializable &task, const cluster::memberselector::MemberSelector &memberSelector, const boost::shared_ptr< MultiExecutionCallback< T > > &callback)
Submits task to the selected members.
Definition: IExecutorService.h:431
void executeOnMembers(const HazelcastSerializable &command, const cluster::memberselector::MemberSelector &memberSelector)
Executes a task on each of the selected members.
Definition: IExecutorService.h:142
void submitToAllMembers(const HazelcastSerializable &task, const boost::shared_ptr< MultiExecutionCallback< T > > &callback)
Submits task to all the cluster members.
Definition: IExecutorService.h:447
virtual std::auto_ptr< IException > clone() const
We need this method to clone the specific derived exception when needed.
Definition: IException.cpp:91
void execute(const HazelcastSerializable &command)
Executes the given command at some time in the future.
Definition: IExecutorService.h:80
void executeOnMember(const HazelcastSerializable &command, const Member &member)
Executes a task on the specified member.
Definition: IExecutorService.h:117
Cluster member class.
Definition: Member.h:43
std::map< Member, boost::shared_ptr< ICompletableFuture< T > > > submitToMembers(const HazelcastSerializable &task, const std::vector< Member > &members)
Submits a task to given members and returns map of Member-ICompletableFuture pairs representing pendi...
Definition: IExecutorService.h:204
std::map< Member, boost::shared_ptr< ICompletableFuture< T > > > submitToAllMembers(const HazelcastSerializable &task)
Submits task to all cluster members and returns a map of Member-ICompletableFuture pairs representing...
Definition: IExecutorService.h:245
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
void submitToKeyOwner(const HazelcastSerializable &task, const K &key, const boost::shared_ptr< ExecutionCallback< T > > &callback)
Submits a task to the owner of the specified key.
Definition: IExecutorService.h:377
boost::shared_ptr< ICompletableFuture< T > > submitToMember(const HazelcastSerializable &task, const Member &member)
Submits a task to the specified member and returns a ICompletableFuture representing that task...
Definition: IExecutorService.h:187
Distributed implementation of java.util.concurrent.ExecutorService.
Definition: IExecutorService.h:64