LogCabin
|
This class represents an asynchronous remote procedure call. More...
#include <OpaqueClientRPC.h>
Public Types | |
enum | Status { NOT_READY, OK, ERROR, CANCELED } |
State of the RPC. More... | |
typedef Core::Time::SteadyClock | Clock |
Clock used for timeouts. | |
typedef Clock::time_point | TimePoint |
Type for absolute time values used for timeouts. | |
Public Member Functions | |
OpaqueClientRPC () | |
Default constructor. | |
OpaqueClientRPC (OpaqueClientRPC &&) | |
Move constructor. | |
~OpaqueClientRPC () | |
Destructor. | |
OpaqueClientRPC & | operator= (OpaqueClientRPC &&) |
Move assignment. | |
void | cancel () |
Abort the RPC. | |
std::string | getErrorMessage () const |
If an error has occurred, return a message describing that error. | |
Status | getStatus () const |
See Status. | |
Core::Buffer * | peekReply () |
Look at the reply buffer. | |
void | waitForReply (TimePoint timeout) |
Block until the reply is ready, an error has occurred, or the given timeout elapses. | |
Private Member Functions | |
void | update () |
Update the fields of this object if the RPC has not completed. | |
OpaqueClientRPC (const OpaqueClientRPC &) | |
OpaqueClientRPC & | operator= (const OpaqueClientRPC &) |
Private Attributes | |
std::mutex | mutex |
Protects all the members of this class. | |
std::shared_ptr< ClientSession > | session |
The session on which this RPC is executing. | |
uint64_t | responseToken |
A token given to the session to look up new information about the progress of this RPC's reply. | |
Status | status |
See Status. | |
Core::Buffer | reply |
The payload of a successful reply, once available. | |
std::string | errorMessage |
If an error occurred in the RPC then this holds the error message; otherwise, this is the empty string. | |
Friends | |
class | ClientSession |
This class represents an asynchronous remote procedure call.
A ClientSession returns an instance when an RPC is initiated; this can be used to wait for and retrieve the reply.
Definition at line 39 of file OpaqueClientRPC.h.
Clock used for timeouts.
Definition at line 42 of file OpaqueClientRPC.h.
Type for absolute time values used for timeouts.
Definition at line 44 of file OpaqueClientRPC.h.
State of the RPC.
NOT_READY |
The RPC is still in progress. |
OK |
The RPC has completed successfully. |
ERROR |
The RPC has failed with an error (see getErrorMessage()). |
CANCELED |
Definition at line 49 of file OpaqueClientRPC.h.
Default constructor.
This doesn't create a valid RPC, but it is useful as a placeholder.
Definition at line 24 of file OpaqueClientRPC.cc.
Move constructor.
Definition at line 34 of file OpaqueClientRPC.cc.
Destructor.
Definition at line 44 of file OpaqueClientRPC.cc.
LogCabin::RPC::OpaqueClientRPC::OpaqueClientRPC | ( | const OpaqueClientRPC & | ) | [private] |
OpaqueClientRPC & LogCabin::RPC::OpaqueClientRPC::operator= | ( | OpaqueClientRPC && | other | ) |
Move assignment.
Definition at line 50 of file OpaqueClientRPC.cc.
Abort the RPC.
The caller is no longer interested in its reply.
Definition at line 62 of file OpaqueClientRPC.cc.
std::string LogCabin::RPC::OpaqueClientRPC::getErrorMessage | ( | ) | const |
If an error has occurred, return a message describing that error.
All errors indicate that it is unknown whether or not the server executed the RPC. Unless the RPC was canceled with cancel(), the ClientSession has been disconnected and is no longer useful for initiating new RPCs.
Definition at line 76 of file OpaqueClientRPC.cc.
See Status.
Definition at line 84 of file OpaqueClientRPC.cc.
Look at the reply buffer.
Definition at line 92 of file OpaqueClientRPC.cc.
void LogCabin::RPC::OpaqueClientRPC::waitForReply | ( | TimePoint | timeout | ) |
Block until the reply is ready, an error has occurred, or the given timeout elapses.
This may be used from worker threads only, because OpaqueClientRPC objects rely on the event loop servicing their ClientSession in order to make progress.
timeout | After this time has elapsed, stop waiting and return. The RPC's results will probably not be available yet in this case (status will be NOT_READY). |
Definition at line 103 of file OpaqueClientRPC.cc.
void LogCabin::RPC::OpaqueClientRPC::update | ( | ) | [private] |
Update the fields of this object if the RPC has not completed.
Must be called with the lock held.
Definition at line 124 of file OpaqueClientRPC.cc.
OpaqueClientRPC& LogCabin::RPC::OpaqueClientRPC::operator= | ( | const OpaqueClientRPC & | ) | [private] |
friend class ClientSession [friend] |
Definition at line 183 of file OpaqueClientRPC.h.
std::mutex LogCabin::RPC::OpaqueClientRPC::mutex [mutable, private] |
Protects all the members of this class.
Definition at line 150 of file OpaqueClientRPC.h.
std::shared_ptr<ClientSession> LogCabin::RPC::OpaqueClientRPC::session [private] |
The session on which this RPC is executing.
The session itself will reset this field once the reply has been received to eagerly drop its own reference count.
Definition at line 157 of file OpaqueClientRPC.h.
uint64_t LogCabin::RPC::OpaqueClientRPC::responseToken [private] |
A token given to the session to look up new information about the progress of this RPC's reply.
Definition at line 163 of file OpaqueClientRPC.h.
Status LogCabin::RPC::OpaqueClientRPC::status [private] |
See Status.
Definition at line 168 of file OpaqueClientRPC.h.
The payload of a successful reply, once available.
This becomes valid when status is OK.
Definition at line 174 of file OpaqueClientRPC.h.
std::string LogCabin::RPC::OpaqueClientRPC::errorMessage [private] |
If an error occurred in the RPC then this holds the error message; otherwise, this is the empty string.
Definition at line 180 of file OpaqueClientRPC.h.