Tkrzw
Public Member Functions | Friends | List of all members
tkrzw::MessageQueue::Reader Class Referencefinal

Messsage reader. More...

#include <tkrzw_message_queue.h>

Public Member Functions

 ~Reader ()
 Destructor. More...
 
Status Read (int64_t *timestamp, std::string *message, double wait_time=0)
 Reads a message from the queue. More...
 
Status Wait (double wait_time=0)
 Waits until the reader is ready to read tne next message. More...
 
int64_t GetTimestamp ()
 Gets the latest timestamp. More...
 

Friends

class MessageQueue
 

Detailed Description

Messsage reader.

Constructor & Destructor Documentation

◆ ~Reader()

tkrzw::MessageQueue::Reader::~Reader ( )

Destructor.

Member Function Documentation

◆ Read()

Status tkrzw::MessageQueue::Reader::Read ( int64_t *  timestamp,
std::string *  message,
double  wait_time = 0 
)

Reads a message from the queue.

Parameters
timestampThe pointer to a variable to store the timestamp in milliseconds of the message. This is set if the result is SUCCESS or INFEASIBLE_ERROR.
messageThe pointer to a string object to store the msssage data.
wait_timeThe time in seconds to wait for the next log. Zero means no wait. Negative means unlimited.
Returns
The result status. If the queue is in the read-only mode and there's no record to read, NOT_FOUND_ERROR is returned. If the time wait time passes, INFEASIBLE_ERROR is returned. If the writer closes the file while waiting, CANCELED_ERROR is returned.

◆ Wait()

Status tkrzw::MessageQueue::Reader::Wait ( double  wait_time = 0)

Waits until the reader is ready to read tne next message.

Parameters
wait_timeThe time in seconds to wait for the next log. Zero means no wait. Negative means unlimited.
Returns
The result status. If the queue is in the read-only mode and there's no record to read, NOT_FOUND_ERROR is returned. If the time wait time passes, INFEASIBLE_ERROR is returned. If the writer closes the file while waiting, CANCELED_ERROR is returned.

◆ GetTimestamp()

int64_t tkrzw::MessageQueue::Reader::GetTimestamp ( )

Gets the latest timestamp.

Returns
The latest timestamp, or -1 if nothing has been read.