16 #ifndef HAZELCAST_CLIENT_FUTURE_H_
17 #define HAZELCAST_CLIENT_FUTURE_H_
23 #include "hazelcast/client/connection/CallFuture.h"
24 #include "hazelcast/client/serialization/pimpl/SerializationService.h"
25 #include "hazelcast/client/connection/CallPromise.h"
27 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
29 #pragma warning(disable: 4251) //for dll export
44 return enum_type(lhs.value) == enum_type(rhs.value);
47 friend bool operator==(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) == rhs; }
49 friend bool operator==(enum_type lhs,
future_status rhs) {
return lhs == enum_type(rhs.value); }
52 return enum_type(lhs.value) != enum_type(rhs.value);
55 friend bool operator!=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) != rhs; }
57 friend bool operator!=(enum_type lhs,
future_status rhs) {
return lhs != enum_type(rhs.value); }
60 return enum_type(lhs.value) < enum_type(rhs.value);
63 friend bool operator<(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) < rhs; }
65 friend bool operator<(enum_type lhs,
future_status rhs) {
return lhs < enum_type(rhs.value); }
68 return enum_type(lhs.value) <= enum_type(rhs.value);
71 friend bool operator<=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) <= rhs; }
73 friend bool operator<=(enum_type lhs,
future_status rhs) {
return lhs <= enum_type(rhs.value); }
76 return enum_type(lhs.value) > enum_type(rhs.value);
79 friend bool operator>(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) > rhs; }
81 friend bool operator>(enum_type lhs,
future_status rhs) {
return lhs > enum_type(rhs.value); }
84 return enum_type(lhs.value) >= enum_type(rhs.value);
87 friend bool operator>=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) >= rhs; }
89 friend bool operator>=(enum_type lhs,
future_status rhs) {
return lhs >= enum_type(rhs.value); }
113 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
118 Future(connection::CallFuture &callFuture,
119 serialization::pimpl::SerializationService &serializationService,
120 Decoder decoder) : callFuture(new connection::CallFuture(callFuture)),
121 serializationService(serializationService), decoderFunction(decoder) {
129 Future(
const Future &movedFuture) : callFuture(movedFuture.callFuture),
130 serializationService(movedFuture.serializationService),
131 decoderFunction(movedFuture.decoderFunction) {
141 this->callFuture = movedFuture.callFuture;
142 this->decoderFunction = movedFuture.decoderFunction;
165 std::auto_ptr<V>
get() {
166 if (!callFuture.get()) {
168 "It may have been moved from.");
171 std::auto_ptr<protocol::ClientMessage> responseMsg = callFuture->get();
173 assert(responseMsg.get());
177 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
179 std::auto_ptr<V> result = serializationService.toObject<V>(response.get());
196 if (!callFuture.get()) {
200 return callFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
221 return callFuture.get() != NULL;
225 mutable std::auto_ptr<connection::CallFuture> callFuture;
226 serialization::pimpl::SerializationService &serializationService;
227 Decoder decoderFunction;
232 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:49
This is a unique Future.
Definition: Future.h:111
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:220
Future(connection::CallFuture &callFuture, serialization::pimpl::SerializationService &serializationService, Decoder decoder)
This constructor is only for internal use!!!!
Definition: Future.h:118
void wait() const
Blocks until the result becomes available.
Definition: Future.h:209
future_status wait_for(int64_t timeoutInMilliseconds) const
Waits for the result to become available.
Definition: Future.h:195
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:140
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:129