Public Member Functions | Protected Member Functions | Private Attributes | List of all members
swarmio::services::Awaiter< T > Class Template Referenceabstract

A special mailbox that handles responses to a message. More...

#include <Awaiter.h>

Inheritance diagram for swarmio::services::Awaiter< T >:
Inheritance graph
[legend]

Public Member Functions

 Awaiter (Endpoint *endpoint, uint64_t requestIdentifier)
 Construct a new ResponseAwaiter object. More...
 
 Awaiter (const T &value)
 Construct an awaiter with a cached value. More...
 
 Awaiter (Awaiter &&other)
 Move an Awaiter object. More...
 
uint64_t GetIdentifier () const
 Get request identifier. More...
 
GetResponse ()
 Get the response value. Will throw an exception if called before the response is received. More...
 
bool HasException ()
 Checks whether the result of the processing has ended with an exception. More...
 
virtual bool ReceiveMessage (const Node *sender, const data::Message *message) override
 Delivery point of all messages. More...
 
bool WaitForResponse (const std::chrono::milliseconds &timeout)
 Wait for the response to become available or util the timeout period ellapses. More...
 
- Public Member Functions inherited from swarmio::Mailbox
virtual void Disconnect ()
 Disconnect this Mailbox from the Endpoint. More...
 
EndpointGetEndpoint ()
 Get the associated Endpoint. More...
 
 Mailbox (const Mailbox &)=delete
 Remove copy constructor. More...
 
virtual void MailboxWasConnected () noexcept
 Called when the mailbox is attached to an already running endpoint or if the attached endpoint has just started. More...
 
virtual void MailboxWillBeDisconnected () noexcept
 Called right before the mailbox is disconnected from its endpoint or if the attached endpoint is about to stop. More...
 
virtual void NodeDidJoin (const Node *node) noexcept
 Called when a new Node has joined the group. More...
 
virtual void NodeWasDiscovered (const Node *node) noexcept
 Called when a new Node has been discovered. More...
 
virtual void NodeWillLeave (const Node *node) noexcept
 Called when a Node signals that it will leave. More...
 
Mailboxoperator= (const Mailbox &)=delete
 Remove assignment operator. More...
 
virtual ~Mailbox ()
 Destroy the Mailbox object. More...
 

Protected Member Functions

virtual T ExtractResponse (const Node *node, const data::Message *message)=0
 Called when a response for the original message has been received. More...
 
virtual bool IsFinished ()
 Check whether the last message has been received. More...
 
- Protected Member Functions inherited from swarmio::Mailbox
void FinishConstruction ()
 Called when the last constructor has finished its job. More...
 
void FinishMovingTo (Mailbox *other)
 Called when message handling should be passed onto the new instance. More...
 
 Mailbox ()
 Construct a disconnected Mailbox. More...
 
 Mailbox (Endpoint *endpoint)
 Construct a new Mailbox object. More...
 
 Mailbox (Mailbox &&other)
 Move a Mailbox object. More...
 

Private Attributes

std::condition_variable _conditionVariable
 Condition variable to signal when the response arrives. More...
 
std::exception_ptr _exception = nullptr
 The exception that was thrown while processing the response. More...
 
std::mutex _mutex
 Mutex for the condition variable. More...
 
uint64_t _requestIdentifier
 Request identifier. More...
 
_response
 The value of the response. More...
 
bool _valid
 Set to true after the initial response has been received. More...
 

Detailed Description

template<class T>
class swarmio::services::Awaiter< T >

A special mailbox that handles responses to a message.

Template Parameters
TReturn value type

Definition at line 19 of file Awaiter.h.

Constructor & Destructor Documentation

template<class T>
swarmio::services::Awaiter< T >::Awaiter ( Endpoint endpoint,
uint64_t  requestIdentifier 
)
inline

Construct a new ResponseAwaiter object.

Parameters
endpointEndpoint
requestIdentifierOriginal message identifier

Definition at line 90 of file Awaiter.h.

template<class T>
swarmio::services::Awaiter< T >::Awaiter ( const T &  value)
inline

Construct an awaiter with a cached value.

Parameters
valueValue

Definition at line 98 of file Awaiter.h.

template<class T>
swarmio::services::Awaiter< T >::Awaiter ( Awaiter< T > &&  other)
inline

Move an Awaiter object.

Parameters
otherOther object

Definition at line 106 of file Awaiter.h.

Member Function Documentation

template<class T>
virtual T swarmio::services::Awaiter< T >::ExtractResponse ( const Node node,
const data::Message *  message 
)
protectedpure virtual

Called when a response for the original message has been received.

Parameters
nodeSender node
messageMessage

Implemented in swarmio::services::keyvalue::ValueAwaiter, swarmio::services::ping::TimingAwaiter, swarmio::services::telemetry::UpdateAwaiter, swarmio::services::discovery::DiscoveryAwaiter, and swarmio::services::ErrorAwaiter.

template<class T>
uint64_t swarmio::services::Awaiter< T >::GetIdentifier ( ) const
inline

Get request identifier.

Returns
uint64_t Identifier

Definition at line 230 of file Awaiter.h.

template<class T>
T swarmio::services::Awaiter< T >::GetResponse ( )
inline

Get the response value. Will throw an exception if called before the response is received.

Returns
T response

Definition at line 127 of file Awaiter.h.

template<class T>
bool swarmio::services::Awaiter< T >::HasException ( )
inline

Checks whether the result of the processing has ended with an exception.

Returns
True if an exception will be thrown by GetResponse().

Definition at line 212 of file Awaiter.h.

template<class T>
virtual bool swarmio::services::Awaiter< T >::IsFinished ( )
inlineprotectedvirtual

Check whether the last message has been received.

Returns
True if no further messages should be processed

Reimplemented in swarmio::services::telemetry::UpdateAwaiter.

Definition at line 77 of file Awaiter.h.

template<class T>
virtual bool swarmio::services::Awaiter< T >::ReceiveMessage ( const Node sender,
const data::Message *  message 
)
inlineoverridevirtual

Delivery point of all messages.

Parameters
senderThe node that has sent the message
messageThe message itself
Returns
True if the message had been processed and should not be forwarded to other mailboxes

Reimplemented from swarmio::Mailbox.

Definition at line 155 of file Awaiter.h.

template<class T>
bool swarmio::services::Awaiter< T >::WaitForResponse ( const std::chrono::milliseconds &  timeout)
inline

Wait for the response to become available or util the timeout period ellapses.

Parameters
timeoutTime to wait
Returns
True if the response has been received.

Definition at line 197 of file Awaiter.h.

Member Data Documentation

template<class T>
std::condition_variable swarmio::services::Awaiter< T >::_conditionVariable
private

Condition variable to signal when the response arrives.

Definition at line 60 of file Awaiter.h.

template<class T>
std::exception_ptr swarmio::services::Awaiter< T >::_exception = nullptr
private

The exception that was thrown while processing the response.

Definition at line 47 of file Awaiter.h.

template<class T>
std::mutex swarmio::services::Awaiter< T >::_mutex
private

Mutex for the condition variable.

Definition at line 53 of file Awaiter.h.

template<class T>
uint64_t swarmio::services::Awaiter< T >::_requestIdentifier
private

Request identifier.

Definition at line 27 of file Awaiter.h.

template<class T>
T swarmio::services::Awaiter< T >::_response
private

The value of the response.

Definition at line 33 of file Awaiter.h.

template<class T>
bool swarmio::services::Awaiter< T >::_valid
private

Set to true after the initial response has been received.

Definition at line 40 of file Awaiter.h.


The documentation for this class was generated from the following file:


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48