16 #ifndef HAZELCAST_CLIENT_FUTURE_H_ 17 #define HAZELCAST_CLIENT_FUTURE_H_ 22 #include <boost/shared_ptr.hpp> 24 #include "hazelcast/client/spi/impl/ClientInvocationFuture.h" 25 #include "hazelcast/client/serialization/pimpl/SerializationService.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); }
107 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
112 Future(
const boost::shared_ptr<spi::impl::ClientInvocationFuture> &invocationFuture,
113 serialization::pimpl::SerializationService &serializationService,
114 Decoder decoder) : clientInvocationFuture(invocationFuture),
115 serializationService(serializationService), decoderFunction(decoder) {
123 Future(
const Future &movedFuture) : clientInvocationFuture(movedFuture.clientInvocationFuture),
124 serializationService(movedFuture.serializationService),
125 decoderFunction(movedFuture.decoderFunction) {
126 const_cast<Future &
>(movedFuture).clientInvocationFuture.reset();
136 this->clientInvocationFuture = movedFuture.clientInvocationFuture;
137 const_cast<Future &
>(movedFuture).clientInvocationFuture.reset();
138 this->decoderFunction = movedFuture.decoderFunction;
161 std::auto_ptr<V>
get() {
162 if (!clientInvocationFuture.get()) {
163 throw exception::FutureUninitialized(
"Future::get",
"Future needs to be initialized. " 164 "It may have been moved from.");
167 boost::shared_ptr<protocol::ClientMessage> responseMsg = clientInvocationFuture->get();
169 assert(responseMsg.get());
171 clientInvocationFuture.reset();
173 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
175 std::auto_ptr<V> result = serializationService.toObject<V>(response.get());
192 if (!clientInvocationFuture.get()) {
193 throw exception::FutureUninitialized(
"Future::get",
"Future needs to be initialized.");
196 return clientInvocationFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
217 return clientInvocationFuture.get() != NULL;
221 boost::shared_ptr<spi::impl::ClientInvocationFuture> clientInvocationFuture;
222 serialization::pimpl::SerializationService &serializationService;
223 Decoder decoderFunction;
232 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
237 Future(
const boost::shared_ptr<spi::impl::ClientInvocationFuture> &invocationFuture,
238 serialization::pimpl::SerializationService &serializationService,
239 Decoder decoder) : clientInvocationFuture(invocationFuture),
240 serializationService(serializationService), decoderFunction(decoder) {
248 Future(
const Future &movedFuture) : clientInvocationFuture(movedFuture.clientInvocationFuture),
249 serializationService(movedFuture.serializationService),
250 decoderFunction(movedFuture.decoderFunction) {
251 const_cast<Future &
>(movedFuture).clientInvocationFuture.reset();
261 this->clientInvocationFuture = movedFuture.clientInvocationFuture;
262 const_cast<Future &
>(movedFuture).clientInvocationFuture.reset();
263 this->decoderFunction = movedFuture.decoderFunction;
287 if (!clientInvocationFuture.get()) {
288 throw exception::FutureUninitialized(
"Future::get",
"Future needs to be initialized. " 289 "It may have been moved from.");
292 boost::shared_ptr<protocol::ClientMessage> responseMsg = clientInvocationFuture->get();
294 assert(responseMsg.get());
296 clientInvocationFuture.reset();
298 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
300 return TypedData(response, serializationService);
315 if (!clientInvocationFuture.get()) {
316 throw exception::FutureUninitialized(
"Future::get",
"Future needs to be initialized.");
319 return clientInvocationFuture->waitFor(timeoutInMilliseconds) ? future_status::ready : future_status::timeout;
340 return clientInvocationFuture.get() != NULL;
344 boost::shared_ptr<spi::impl::ClientInvocationFuture> clientInvocationFuture;
345 serialization::pimpl::SerializationService &serializationService;
346 Decoder decoderFunction;
351 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:339
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:216
void wait() const
Blocks until the result becomes available.
Definition: Future.h:328
void wait() const
Blocks until the result becomes available.
Definition: Future.h:205
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:248
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:260
Future(const boost::shared_ptr< spi::impl::ClientInvocationFuture > &invocationFuture, serialization::pimpl::SerializationService &serializationService, Decoder decoder)
This constructor is only for internal use!!!!
Definition: Future.h:112
future_status wait_for(int64_t timeoutInMilliseconds) const
Waits for the result to become available.
Definition: Future.h:191
This is a unique Future.
Definition: Future.h:105
future_status wait_for(int64_t timeoutInMilliseconds) const
Waits for the result to become available.
Definition: Future.h:314
Future(const boost::shared_ptr< spi::impl::ClientInvocationFuture > &invocationFuture, serialization::pimpl::SerializationService &serializationService, Decoder decoder)
This constructor is only for internal use!!!!
Definition: Future.h:237
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:135
Future(const Future &movedFuture)
This is actually a move constructor Constructs a Future with the shared state of movedFuture using mo...
Definition: Future.h:123
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40