Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
swarmio::transport::BasicEndpoint Class Referenceabstract

An helper class for Endpoint implementations which implements some common basic functionality. More...

#include <BasicEndpoint.h>

Inheritance diagram for swarmio::transport::BasicEndpoint:
Inheritance graph
[legend]

Public Member Functions

bool IsRunning ()
 Checks whether the endpoint has been started. More...
 
virtual void Send (data::Message *message, const Node *node) override
 Send a message to a specific member of the swarm. Call with node set to nullptr to send a message to all members of the swarm. More...
 
virtual void Start () override
 Start a background thread and begin processing messages on this endpoint. More...
 
virtual void Stop () override
 Send a termination signal and wait until the endpoint finished processing messages. More...
 
virtual void Tag (data::Message *message) override
 Set the message identifier for a message. More...
 
- Public Member Functions inherited from swarmio::Endpoint
virtual const std::string & GetUUID ()=0
 Get the UUID of the local node. More...
 
virtual const NodeNodeForUUID (const std::string &uuid)=0
 Retreive a node by its UUID. More...
 
virtual ~Endpoint ()
 Destroy the Endpoint object. More...
 

Protected Member Functions

 BasicEndpoint ()
 Protected constructor. 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...
 
virtual bool ReceiveMessage (const Node *sender, const data::Message *message) noexcept
 Called by implementations to deliver decoded messages. More...
 
virtual bool ReceiveMessage (const Node *sender, const void *data, size_t size) noexcept
 Called by implementations to deliver raw messages. More...
 
virtual void RegisterMailbox (Mailbox *mailbox) override
 Register a Mailbox to receive messages. More...
 
virtual void ReplaceMailbox (Mailbox *oldMailbox, Mailbox *newMailbox) override
 Relocate a mailbox to another in-memory location. More...
 
virtual void Send (const void *data, size_t size, const Node *node)=0
 Called by this class to send serialized messages. Called with node set to nullptr to send a message to all members of the swarm. More...
 
virtual void UnregisterMailbox (Mailbox *mailbox) override
 Unregister a Mailbox from receiving messages. More...
 

Private Member Functions

void ReplyWithError (const Node *sender, const data::Message *message, data::Error error)
 Send a reply to a message that only contains a status code. More...
 

Private Attributes

std::atomic< uint64_t > _counter
 Atomic counter for message identifiers. More...
 
bool _isRunning
 True if the Mailbox has been started. More...
 
std::set< Mailbox * > _mailboxes
 Container for registered mailboxes. More...
 
std::recursive_mutex _mutex
 Mutex used to synchronize access to the list of mailboxes. More...
 

Additional Inherited Members

- Protected Attributes inherited from swarmio::Endpoint
friend Mailbox
 Allow Mailboxes to register themselves. More...
 

Detailed Description

An helper class for Endpoint implementations which implements some common basic functionality.

Definition at line 15 of file BasicEndpoint.h.

Constructor & Destructor Documentation

swarmio::transport::BasicEndpoint::BasicEndpoint ( )
inlineprotected

Protected constructor.

Definition at line 57 of file BasicEndpoint.h.

Member Function Documentation

bool swarmio::transport::BasicEndpoint::IsRunning ( )
inline

Checks whether the endpoint has been started.

Returns
True if it has been started

Definition at line 162 of file BasicEndpoint.h.

void BasicEndpoint::NodeDidJoin ( const Node node)
protectedvirtualnoexcept

Called when a new Node has joined the group.

Parameters
nodeThe node that has been discovered

Definition at line 102 of file BasicEndpoint.cpp.

void BasicEndpoint::NodeWasDiscovered ( const Node node)
protectedvirtualnoexcept

Called when a new Node has been discovered.

Parameters
nodeThe node that has been discovered

Definition at line 91 of file BasicEndpoint.cpp.

void BasicEndpoint::NodeWillLeave ( const Node node)
protectedvirtualnoexcept

Called when a Node signals that it will leave.

Parameters
nodeThe node that has left

Definition at line 113 of file BasicEndpoint.cpp.

bool BasicEndpoint::ReceiveMessage ( const Node sender,
const data::Message *  message 
)
protectedvirtualnoexcept

Called by implementations to deliver decoded messages.

Parameters
senderSender node
messageThe message itself
Returns
True if the message was handled

Definition at line 155 of file BasicEndpoint.cpp.

bool BasicEndpoint::ReceiveMessage ( const Node sender,
const void *  data,
size_t  size 
)
protectedvirtualnoexcept

Called by implementations to deliver raw messages.

Parameters
senderSender node
dataRaw message data
sizeLength of the message data
Returns
True if the message was handled

Definition at line 124 of file BasicEndpoint.cpp.

void BasicEndpoint::RegisterMailbox ( Mailbox mailbox)
overrideprotectedvirtual

Register a Mailbox to receive messages.

May be called more than once, and has no effect if the mailbox has already been registered.

Parameters
mailboxMailbox to register.

Implements swarmio::Endpoint.

Definition at line 54 of file BasicEndpoint.cpp.

void BasicEndpoint::ReplaceMailbox ( Mailbox oldMailbox,
Mailbox newMailbox 
)
overrideprotectedvirtual

Relocate a mailbox to another in-memory location.

Supports thread-safe move operations on Mailboxes.

Parameters
mailboxMailbox to register.

Implements swarmio::Endpoint.

Definition at line 82 of file BasicEndpoint.cpp.

void BasicEndpoint::ReplyWithError ( const Node sender,
const data::Message *  message,
data::Error  error 
)
private

Send a reply to a message that only contains a status code.

Parameters
senderSender of the original message
messageThe original message
errorError code to send back

Definition at line 138 of file BasicEndpoint.cpp.

virtual void swarmio::transport::BasicEndpoint::Send ( const void *  data,
size_t  size,
const Node node 
)
protectedpure virtual

Called by this class to send serialized messages. Called with node set to nullptr to send a message to all members of the swarm.

Parameters
dataRaw message data
sizeLength of the message data
nodeNode the message will be sent to

Implemented in swarmio::transport::zyre::ZyreEndpoint.

void BasicEndpoint::Send ( data::Message *  message,
const Node node 
)
overridevirtual

Send a message to a specific member of the swarm. Call with node set to nullptr to send a message to all members of the swarm.

Thread-safe.

Parameters
messageMessage
nodeNode the message will be sent to

Implements swarmio::Endpoint.

Definition at line 228 of file BasicEndpoint.cpp.

void BasicEndpoint::Start ( )
overridevirtual

Start a background thread and begin processing messages on this endpoint.

Implements swarmio::Endpoint.

Reimplemented in swarmio::transport::zyre::ZyreEndpoint.

Definition at line 11 of file BasicEndpoint.cpp.

void BasicEndpoint::Stop ( )
overridevirtual

Send a termination signal and wait until the endpoint finished processing messages.

Thread-safe.

Implements swarmio::Endpoint.

Reimplemented in swarmio::transport::zyre::ZyreEndpoint.

Definition at line 32 of file BasicEndpoint.cpp.

void BasicEndpoint::Tag ( data::Message *  message)
overridevirtual

Set the message identifier for a message.

Thread safe.

Parameters
messageMessage

Implements swarmio::Endpoint.

Definition at line 218 of file BasicEndpoint.cpp.

void BasicEndpoint::UnregisterMailbox ( Mailbox mailbox)
overrideprotectedvirtual

Unregister a Mailbox from receiving messages.

May be called more than once, and has no effect if the mailbox has already been unregistered.

Parameters
mailboxMailbox to unregister.

Implements swarmio::Endpoint.

Definition at line 68 of file BasicEndpoint.cpp.

Member Data Documentation

std::atomic<uint64_t> swarmio::transport::BasicEndpoint::_counter
private

Atomic counter for message identifiers.

Definition at line 40 of file BasicEndpoint.h.

bool swarmio::transport::BasicEndpoint::_isRunning
private

True if the Mailbox has been started.

Definition at line 23 of file BasicEndpoint.h.

std::set<Mailbox*> swarmio::transport::BasicEndpoint::_mailboxes
private

Container for registered mailboxes.

Definition at line 28 of file BasicEndpoint.h.

std::recursive_mutex swarmio::transport::BasicEndpoint::_mutex
private

Mutex used to synchronize access to the list of mailboxes.

Definition at line 34 of file BasicEndpoint.h.


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


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