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"
27 #include "hazelcast/client/protocol/ClientMessage.h"
29 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
31 #pragma warning(disable: 4251) //for dll export
46 return enum_type(lhs.value) == enum_type(rhs.value);
49 friend bool operator==(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) == rhs; }
51 friend bool operator==(enum_type lhs,
future_status rhs) {
return lhs == enum_type(rhs.value); }
54 return enum_type(lhs.value) != enum_type(rhs.value);
57 friend bool operator!=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) != rhs; }
59 friend bool operator!=(enum_type lhs,
future_status rhs) {
return lhs != enum_type(rhs.value); }
62 return enum_type(lhs.value) < enum_type(rhs.value);
65 friend bool operator<(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) < rhs; }
67 friend bool operator<(enum_type lhs,
future_status rhs) {
return lhs < enum_type(rhs.value); }
70 return enum_type(lhs.value) <= enum_type(rhs.value);
73 friend bool operator<=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) <= rhs; }
75 friend bool operator<=(enum_type lhs,
future_status rhs) {
return lhs <= enum_type(rhs.value); }
78 return enum_type(lhs.value) > enum_type(rhs.value);
81 friend bool operator>(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) > rhs; }
83 friend bool operator>(enum_type lhs,
future_status rhs) {
return lhs > enum_type(rhs.value); }
86 return enum_type(lhs.value) >= enum_type(rhs.value);
89 friend bool operator>=(
future_status lhs, enum_type rhs) {
return enum_type(lhs.value) >= rhs; }
91 friend bool operator>=(enum_type lhs,
future_status rhs) {
return lhs >= enum_type(rhs.value); }
115 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
120 Future(connection::CallFuture &callFuture,
121 serialization::pimpl::SerializationService &serializationService,
122 Decoder decoder) : callFuture(new connection::CallFuture(callFuture)),
123 serializationService(serializationService), decoderFunction(decoder) {
131 Future(
const Future &movedFuture) : callFuture(movedFuture.callFuture),
132 serializationService(movedFuture.serializationService),
133 decoderFunction(movedFuture.decoderFunction) {
143 this->callFuture = movedFuture.callFuture;
144 this->decoderFunction = movedFuture.decoderFunction;
167 std::auto_ptr<V>
get() {
168 if (!callFuture.get()) {
170 "It may have been moved from.");
173 std::auto_ptr<protocol::ClientMessage> responseMsg = callFuture->get();
175 assert(responseMsg.get());
179 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
181 std::auto_ptr<V> result = serializationService.toObject<V>(response.get());
198 if (!callFuture.get()) {
202 return callFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
223 return callFuture.get() != NULL;
227 mutable std::auto_ptr<connection::CallFuture> callFuture;
228 serialization::pimpl::SerializationService &serializationService;
229 Decoder decoderFunction;
238 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
243 Future(connection::CallFuture &callFuture,
244 serialization::pimpl::SerializationService &serializationService,
245 Decoder decoder) : callFuture(new connection::CallFuture(callFuture)),
246 serializationService(serializationService), decoderFunction(decoder) {
254 Future(
const Future &movedFuture) : callFuture(movedFuture.callFuture),
255 serializationService(movedFuture.serializationService),
256 decoderFunction(movedFuture.decoderFunction) {
266 this->callFuture = movedFuture.callFuture;
267 this->decoderFunction = movedFuture.decoderFunction;
291 if (!callFuture.get()) {
293 "It may have been moved from.");
296 std::auto_ptr<protocol::ClientMessage> responseMsg = callFuture->get();
298 assert(responseMsg.get());
302 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
304 return TypedData(response, serializationService);
319 if (!callFuture.get()) {
323 return callFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
344 return callFuture.get() != NULL;
348 mutable std::auto_ptr<connection::CallFuture> callFuture;
349 serialization::pimpl::SerializationService &serializationService;
350 Decoder decoderFunction;
355 #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:243
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:254
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:318
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:265
void wait() const
Blocks until the result becomes available.
Definition: Future.h:332
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:343
This is a unique Future.
Definition: Future.h:113
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:222
Future(connection::CallFuture &callFuture, serialization::pimpl::SerializationService &serializationService, Decoder decoder)
This constructor is only for internal use!!!!
Definition: Future.h:120
void wait() const
Blocks until the result becomes available.
Definition: Future.h:211
future_status wait_for(int64_t timeoutInMilliseconds) const
Waits for the result to become available.
Definition: Future.h:197
Definition: MapEntryView.h:32
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:142
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:131
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40