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"
26 #include "hazelcast/client/TypedData.h"
28 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
30 #pragma warning(disable: 4251) //for dll export
45 return enum_type(lhs.value) == enum_type(rhs.value);
48 friend bool operator==(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) == rhs; }
50 friend bool operator==(enum_type lhs,
future_status rhs) {
return lhs == enum_type(rhs.value); }
53 return enum_type(lhs.value) != enum_type(rhs.value);
56 friend bool operator!=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) != rhs; }
58 friend bool operator!=(enum_type lhs,
future_status rhs) {
return lhs != enum_type(rhs.value); }
61 return enum_type(lhs.value) < enum_type(rhs.value);
64 friend bool operator<(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) < rhs; }
66 friend bool operator<(enum_type lhs,
future_status rhs) {
return lhs < enum_type(rhs.value); }
69 return enum_type(lhs.value) <= enum_type(rhs.value);
72 friend bool operator<=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) <= rhs; }
74 friend bool operator<=(enum_type lhs,
future_status rhs) {
return lhs <= enum_type(rhs.value); }
77 return enum_type(lhs.value) > enum_type(rhs.value);
80 friend bool operator>(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) > rhs; }
82 friend bool operator>(enum_type lhs,
future_status rhs) {
return lhs > enum_type(rhs.value); }
85 return enum_type(lhs.value) >= enum_type(rhs.value);
88 friend bool operator>=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) >= rhs; }
90 friend bool operator>=(enum_type lhs,
future_status rhs) {
return lhs >= enum_type(rhs.value); }
114 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
119 Future(connection::CallFuture &callFuture,
120 serialization::pimpl::SerializationService &serializationService,
121 Decoder decoder) : callFuture(new connection::CallFuture(callFuture)),
122 serializationService(serializationService), decoderFunction(decoder) {
130 Future(
const Future &movedFuture) : callFuture(movedFuture.callFuture),
131 serializationService(movedFuture.serializationService),
132 decoderFunction(movedFuture.decoderFunction) {
142 this->callFuture = movedFuture.callFuture;
143 this->decoderFunction = movedFuture.decoderFunction;
166 std::auto_ptr<V>
get() {
167 if (!callFuture.get()) {
169 "It may have been moved from.");
172 std::auto_ptr<protocol::ClientMessage> responseMsg = callFuture->get();
174 assert(responseMsg.get());
178 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
180 std::auto_ptr<V> result = serializationService.toObject<V>(response.get());
197 if (!callFuture.get()) {
201 return callFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
222 return callFuture.get() != NULL;
226 mutable std::auto_ptr<connection::CallFuture> callFuture;
227 serialization::pimpl::SerializationService &serializationService;
228 Decoder decoderFunction;
237 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
242 Future(connection::CallFuture &callFuture,
243 serialization::pimpl::SerializationService &serializationService,
244 Decoder decoder) : callFuture(new connection::CallFuture(callFuture)),
245 serializationService(serializationService), decoderFunction(decoder) {
253 Future(
const Future &movedFuture) : callFuture(movedFuture.callFuture),
254 serializationService(movedFuture.serializationService),
255 decoderFunction(movedFuture.decoderFunction) {
265 this->callFuture = movedFuture.callFuture;
266 this->decoderFunction = movedFuture.decoderFunction;
290 if (!callFuture.get()) {
292 "It may have been moved from.");
295 std::auto_ptr<protocol::ClientMessage> responseMsg = callFuture->get();
297 assert(responseMsg.get());
301 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
303 return TypedData(response, serializationService);
318 if (!callFuture.get()) {
322 return callFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
343 return callFuture.get() != NULL;
347 mutable std::auto_ptr<connection::CallFuture> callFuture;
348 serialization::pimpl::SerializationService &serializationService;
349 Decoder decoderFunction;
354 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
Future(connection::CallFuture &callFuture, serialization::pimpl::SerializationService &serializationService, Decoder decoder)
This constructor is only for internal use!!!!
Definition: Future.h:242
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:253
Base class for all exception originated from Hazelcast methods.
Definition: IException.h:49
future_status wait_for(int64_t timeoutInMilliseconds) const
Waits for the result to become available.
Definition: Future.h:317
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:264
void wait() const
Blocks until the result becomes available.
Definition: Future.h:331
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:342
This is a unique Future.
Definition: Future.h:112
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:221
Future(connection::CallFuture &callFuture, serialization::pimpl::SerializationService &serializationService, Decoder decoder)
This constructor is only for internal use!!!!
Definition: Future.h:119
void wait() const
Blocks until the result becomes available.
Definition: Future.h:210
future_status wait_for(int64_t timeoutInMilliseconds) const
Waits for the result to become available.
Definition: Future.h:196
Definition: MapEntryView.h:32
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:141
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:130
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40