8 #ifndef FACEBOOK_NETWORK_MESSAGE_QUEUE_H
9 #define FACEBOOK_NETWORK_MESSAGE_QUEUE_H
35 typedef unsigned int Id;
41 static constexpr
Id invalidId();
48 typedef std::pair<std::string, std::string>
Message;
53 typedef std::queue<Message>
Queue;
92 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);
111 bool front(
const Id id,
const double timeout, std::string& message, std::string& value);
125 std::string
pop(
const Id id,
const double timeout);
135 bool pop(
const Id id,
const double timeout, std::string& message, std::string& value);
174 unsigned int oldMessageAge_ = 500u;
177 Id idCounter_ = invalidId();
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a message queue.
Definition: MessageQueue.h:29
Lock lock_
Map lock.
Definition: MessageQueue.h:180
MessageQueue()=default
Creates a new message queue.
bool front(const Id id, std::string &message, std::string &value)
Gets the front message for a given message id.
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:171
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...
std::pair< std::string, std::string > Message
Definition of a message pair.
Definition: MessageQueue.h:48
void pop(const Id id)
Pops the front message with a specified message id from the queue.
std::unordered_map< Id, Queue > MessageMap
Definition of a map mapping message ids to message queues.
Definition: MessageQueue.h:58
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:183
MessageQueue(MessageQueue &&messageQueue)
Move constructor.
Id lastUniqueId()
Returns the last unique message id again.
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::queue< Message > Queue
Definition of a queue holding message pairs.
Definition: MessageQueue.h:53
void clear(const Id id)
Clears all messages with a specified message id.
MessageQueue & operator=(MessageQueue &&messageQueue)
Move operator.
bool front(const Id id, const double timeout, std::string &message, std::string &value)
Gets the front message for a given message id and waits a specified time if no message is available.
unsigned int Id
Definition of a message id.
Definition: MessageQueue.h:35
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15