8 #include <condition_variable> 91 :
Mailbox(endpoint), _requestIdentifier(requestIdentifier), _valid(false) { }
99 :
Mailbox(), _requestIdentifier(0), _valid(true), _response(value) { }
110 std::unique_lock<std::mutex> guard(other._mutex);
113 other.FinishMovingTo(
this);
116 _valid = other._valid;
117 _response = other._response;
118 _requestIdentifier = other._requestIdentifier;
129 std::unique_lock<std::mutex> guard(_mutex);
134 std::rethrow_exception(_exception);
143 throw Exception(
"Response is not yet available");
162 std::unique_lock<std::mutex> guard(_mutex);
168 _exception =
nullptr;
172 _exception = std::current_exception();
178 _conditionVariable.notify_all();
200 std::unique_lock<std::mutex> guard(_mutex);
203 return _conditionVariable.wait_for(guard, timeout, [
this]{
return _valid; });
214 std::unique_lock<std::mutex> guard(_mutex);
221 throw Exception(
"Response is not yet available");
std::exception_ptr _exception
The exception that was thrown while processing the response.
std::mutex _mutex
Mutex for the condition variable.
A special mailbox that handles responses to a message.
T _response
The value of the response.
Exception class thrown by all library classes.
virtual bool ReceiveMessage(const Node *sender, const data::Message *message) override
Delivery point of all messages.
Awaiter(Endpoint *endpoint, uint64_t requestIdentifier)
Construct a new ResponseAwaiter object.
bool HasException()
Checks whether the result of the processing has ended with an exception.
virtual bool IsFinished()
Check whether the last message has been received.
bool _valid
Set to true after the initial response has been received.
std::condition_variable _conditionVariable
Condition variable to signal when the response arrives.
Abstract base class for Endpoint implementations.
virtual T ExtractResponse(const Node *node, const data::Message *message)=0
Called when a response for the original message has been received.
Awaiter(const T &value)
Construct an awaiter with a cached value.
T GetResponse()
Get the response value. Will throw an exception if called before the response is received.
uint64_t GetIdentifier() const
Get request identifier.
bool WaitForResponse(const std::chrono::milliseconds &timeout)
Wait for the response to become available or util the timeout period ellapses.
Awaiter(Awaiter &&other)
Move an Awaiter object.
Represents a Node the Endpoint knows about and can send messages to.
Abstract base class for Mailbox implementations.
uint64_t _requestIdentifier
Request identifier.