Tkrzw-RPC
Public Member Functions | Friends | List of all members
tkrzw::RemoteDBM::Stream Class Reference

Stream for better performance of intensive operations. More...

#include <tkrzw_dbm_remote.h>

Public Member Functions

 ~Stream ()
 Destructor. More...
 
 Stream (const Stream &rhs)=delete
 Copy and assignment are disabled. More...
 
Streamoperator= (const Stream &rhs)=delete
 
void Cancel ()
 Cancels the current operation. More...
 
Status Echo (std::string_view message, std::string *echo)
 Sends a message and gets back the echo message. More...
 
Status Get (std::string_view key, std::string *value=nullptr)
 Gets the value of a record of a key. More...
 
std::string GetSimple (std::string_view key, std::string_view default_value="")
 Gets the value of a record of a key, in a simple way. More...
 
Status Set (std::string_view key, std::string_view value, bool overwrite=true, bool ignore_result=false)
 Sets a record of a key and a value. More...
 
Status Remove (std::string_view key, bool ignore_result=false)
 Removes a record of a key. More...
 
Status Append (std::string_view key, std::string_view value, std::string_view delim="", bool ignore_result=false)
 Appends data at the end of a record of a key. More...
 
Status CompareExchange (std::string_view key, std::string_view expected, std::string_view desired, std::string *actual=nullptr, bool *found=nullptr, double retry_wait=0, bool notify=false)
 Compares the value of a record and exchanges if the condition meets. More...
 
Status Increment (std::string_view key, int64_t increment=1, int64_t *current=nullptr, int64_t initial=0, bool ignore_result=false)
 Increments the numeric value of a record. More...
 
int64_t IncrementSimple (std::string_view key, int64_t increment=1, int64_t initial=0)
 Increments the numeric value of a record, in a simple way. More...
 

Friends

class tkrzw::RemoteDBM
 

Detailed Description

Stream for better performance of intensive operations.

An instance of this class dominates a thread on the server so you should destroy when it is no longer in use.

Constructor & Destructor Documentation

◆ ~Stream()

tkrzw::RemoteDBM::Stream::~Stream ( )

Destructor.

◆ Stream()

tkrzw::RemoteDBM::Stream::Stream ( const Stream rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ Cancel()

void tkrzw::RemoteDBM::Stream::Cancel ( )

Cancels the current operation.

This is called by another thread than the thread doing the operation.

◆ Echo()

Status tkrzw::RemoteDBM::Stream::Echo ( std::string_view  message,
std::string *  echo 
)

Sends a message and gets back the echo message.

Parameters
messageThe message to send.
echoThe pointer to a string object to contain the echo message.
Returns
The result status.

◆ Get()

Status tkrzw::RemoteDBM::Stream::Get ( std::string_view  key,
std::string *  value = nullptr 
)

Gets the value of a record of a key.

Parameters
keyThe key of the record.
valueThe pointer to a string object to contain the result value. If it is nullptr, the value data is ignored.
Returns
The result status. If there's no matching record, NOT_FOUND_ERROR is returned.

◆ GetSimple()

std::string tkrzw::RemoteDBM::Stream::GetSimple ( std::string_view  key,
std::string_view  default_value = "" 
)

Gets the value of a record of a key, in a simple way.

Parameters
keyThe key of the record.
default_valueThe value to be returned on failure.
Returns
The value of the matching record on success, or the default value on failure.

◆ Set()

Status tkrzw::RemoteDBM::Stream::Set ( std::string_view  key,
std::string_view  value,
bool  overwrite = true,
bool  ignore_result = false 
)

Sets a record of a key and a value.

Parameters
keyThe key of the record.
valueThe value of the record.
overwriteWhether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned.
ignore_resultIf true, the result status is not checked.
Returns
The result status. If overwriting is abandoned, DUPLICATION_ERROR is returned.

◆ Remove()

Status tkrzw::RemoteDBM::Stream::Remove ( std::string_view  key,
bool  ignore_result = false 
)

Removes a record of a key.

Parameters
keyThe key of the record.
ignore_resultIf true, the result status is not checked.
Returns
The result status. If there's no matching record, NOT_FOUND_ERROR is returned.

◆ Append()

Status tkrzw::RemoteDBM::Stream::Append ( std::string_view  key,
std::string_view  value,
std::string_view  delim = "",
bool  ignore_result = false 
)

Appends data at the end of a record of a key.

Parameters
keyThe key of the record.
valueThe value to append.
delimThe delimiter to put after the existing record.
ignore_resultIf true, the result status is not checked.
Returns
The result status.

If there's no existing record, the value is set without the delimiter.

◆ CompareExchange()

Status tkrzw::RemoteDBM::Stream::CompareExchange ( std::string_view  key,
std::string_view  expected,
std::string_view  desired,
std::string *  actual = nullptr,
bool *  found = nullptr,
double  retry_wait = 0,
bool  notify = false 
)

Compares the value of a record and exchanges if the condition meets.

Parameters
keyThe key of the record.
expectedThe expected value. If the data is nullptr, no existing record is expected. If it is DBM::ANY_DATA, an existing record with any value is expacted.
desiredThe desired value. If the data is nullptr, the record is to be removed. If it is DBM::ANY_DATA, no update is done.
actualThe pointer to a string object to contain the actual value of the existing record. If it is nullptr, it is ignored.
foundThe pointer to a variable to contain whether there is an existing record. If it is nullptr, it is ignored.
retry_waitThe maximum wait time in seconds before retrying. If it is zero, no retry is done. If it is positive, retry is done after waiting for the notifications of the next update for the time at most.
notifyIf true, a notification signal is sent to wake up retrying threads.
Returns
The result status. If the condition doesn't meet, INFEASIBLE_ERROR is returned.

◆ Increment()

Status tkrzw::RemoteDBM::Stream::Increment ( std::string_view  key,
int64_t  increment = 1,
int64_t *  current = nullptr,
int64_t  initial = 0,
bool  ignore_result = false 
)

Increments the numeric value of a record.

Parameters
keyThe key of the record.
incrementThe incremental value. If it is INT64MIN, the current value is not changed and a new record is not created.
currentThe pointer to an integer to contain the current value. If it is nullptr, it is ignored.
initialThe initial value.
ignore_resultIf true, the result status is not checked.
Returns
The result status.

The record value is stored as an 8-byte big-endian integer. Negative is also supported.

◆ IncrementSimple()

int64_t tkrzw::RemoteDBM::Stream::IncrementSimple ( std::string_view  key,
int64_t  increment = 1,
int64_t  initial = 0 
)

Increments the numeric value of a record, in a simple way.

Parameters
keyThe key of the record.
incrementThe incremental value.
initialThe initial value.
Returns
The current value or INT64MIN on failure.

The record value is treated as a decimal integer. Negative is also supported.