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.");
197 clientInvocationFuture->get(timeoutInMilliseconds, concurrent::TimeUnit::MILLISECONDS());
198 return future_status::ready;
199 }
catch (exception::TimeoutException &) {
200 return future_status::timeout;
222 return clientInvocationFuture.get() != NULL;
226 boost::shared_ptr<spi::impl::ClientInvocationFuture> clientInvocationFuture;
227 serialization::pimpl::SerializationService &serializationService;
228 Decoder decoderFunction;
237 typedef std::auto_ptr<serialization::pimpl::Data> (*Decoder)(protocol::ClientMessage &response);
242 Future(
const boost::shared_ptr<spi::impl::ClientInvocationFuture> &invocationFuture,
243 serialization::pimpl::SerializationService &serializationService,
244 Decoder decoder) : clientInvocationFuture(invocationFuture),
245 serializationService(serializationService), decoderFunction(decoder) {
253 Future(
const Future &movedFuture) : clientInvocationFuture(movedFuture.clientInvocationFuture),
254 serializationService(movedFuture.serializationService),
255 decoderFunction(movedFuture.decoderFunction) {
256 const_cast<Future &
>(movedFuture).clientInvocationFuture.reset();
266 this->clientInvocationFuture = movedFuture.clientInvocationFuture;
267 const_cast<Future &
>(movedFuture).clientInvocationFuture.reset();
268 this->decoderFunction = movedFuture.decoderFunction;
292 if (!clientInvocationFuture.get()) {
293 throw exception::FutureUninitialized(
"Future::get",
"Future needs to be initialized. " 294 "It may have been moved from.");
297 boost::shared_ptr<protocol::ClientMessage> responseMsg = clientInvocationFuture->get();
299 assert(responseMsg.get());
301 clientInvocationFuture.reset();
303 std::auto_ptr<serialization::pimpl::Data> response = decoderFunction(*responseMsg);
305 return TypedData(response, serializationService);
320 if (!clientInvocationFuture.get()) {
321 throw exception::FutureUninitialized(
"Future::get",
"Future needs to be initialized.");
325 clientInvocationFuture->get(timeoutInMilliseconds, concurrent::TimeUnit::MILLISECONDS());
326 return future_status::ready;
327 }
catch (exception::TimeoutException &) {
328 return future_status::timeout;
350 return clientInvocationFuture.get() != NULL;
354 boost::shared_ptr<spi::impl::ClientInvocationFuture> clientInvocationFuture;
355 serialization::pimpl::SerializationService &serializationService;
356 Decoder decoderFunction;
361 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:349
bool valid() const
Checks if the future refers to a shared state.
Definition: Future.h:221
void wait() const
Blocks until the result becomes available.
Definition: Future.h:338
void wait() const
Blocks until the result becomes available.
Definition: Future.h:210
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
Future & operator=(const Future &movedFuture)
Assigns the contents of another future object.
Definition: Future.h:265
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:319
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:242
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