8#ifndef FACEBOOK_NETWORK_MESSAGE_QUEUE_H
9#define FACEBOOK_NETWORK_MESSAGE_QUEUE_H
47 using Message = std::pair<std::string, std::string>;
52 using Queue = std::queue<Message>;
91 bool push(
const Id id,
const std::string& message,
const std::string& value);
101 bool front(
const Id id, std::string& message, std::string& value,
const bool popMessage =
false);
112 bool front(
const Id id,
const double timeout, std::string& message, std::string& value,
const bool popMessage =
false);
126 std::string
pop(
const Id id,
const double timeout);
136 bool pop(
const Id id,
const double timeout, std::string& message, std::string& value);
This class implements a recursive lock object.
Definition Lock.h:31
Lock lock_
Map lock.
Definition MessageQueue.h:181
MessageQueue()=default
Creates a new message queue.
void clear()
Clears the entire message queue.
bool push(const Id id, const std::string &message, const std::string &value)
Pushes a new message.
MessageMap messageMap_
Map holding all messages.
Definition MessageQueue.h:172
std::string pop(const Id id, const double timeout)
Returns and pops the front message for a given message id and waits a specified time if no message is...
Id idCounter_
Message id counter.
Definition MessageQueue.h:178
void pop(const Id id)
Pops the front message with a specified message id from the queue.
bool front(const Id id, std::string &message, std::string &value, const bool popMessage=false)
Gets the front message for a given message id.
bool front(const Id id, const double timeout, std::string &message, std::string &value, const bool popMessage=false)
Gets the front message for a given message id and waits a specified time if no message is available.
Id uniqueId()
Returns a unique message id within this message queue.
~MessageQueue()
Destructs a message queue.
static constexpr Id invalidId()
Returns an invalid message id.
Definition MessageQueue.h:184
MessageQueue(MessageQueue &&messageQueue)
Move constructor.
Id lastUniqueId()
Returns the last unique message id again.
MessageQueue & operator=(MessageQueue &&messageQueue)
Move operator.
MessageQueue(const unsigned int oldMessageAge)
Creates a new message queue.
bool pop(const Id id, const double timeout, std::string &message, std::string &value)
Returns and pops the front message for a given message id and waits a specified time if no message is...
std::pair< std::string, std::string > Message
Definition of a message pair.
Definition MessageQueue.h:47
unsigned int oldMessageAge_
Definition of an message age of old and therefore unused messages.
Definition MessageQueue.h:175
void clear(const Id id)
Clears all messages with a specified message id.
uint32_t Id
Definition of a message id.
Definition MessageQueue.h:34
std::unordered_map< Id, Queue > MessageMap
Definition of a map mapping message ids to message queues.
Definition MessageQueue.h:57
std::queue< Message > Queue
Definition of a queue holding message pairs.
Definition MessageQueue.h:52
Namespace of the Network library.
Definition Address4.h:18
The namespace covering the entire Ocean framework.
Definition Accessor.h:15