LogCabin
|
This class represents an asynchronous remote procedure call. More...
#include <ClientRPC.h>
Public Types | |
enum | Status { OK, SERVICE_SPECIFIC_ERROR, RPC_FAILED, RPC_CANCELED, TIMEOUT, INVALID_SERVICE, INVALID_REQUEST } |
The return type of waitForReply(). More... | |
typedef OpaqueClientRPC::Clock | Clock |
Clock used for timeouts. | |
typedef OpaqueClientRPC::TimePoint | TimePoint |
Type for absolute time values used for timeouts. | |
Public Member Functions | |
ClientRPC (std::shared_ptr< RPC::ClientSession > session, uint16_t service, uint8_t serviceSpecificErrorVersion, uint16_t opCode, const google::protobuf::Message &request) | |
Issue an RPC to a remote service. | |
ClientRPC () | |
Default constructor. | |
ClientRPC (ClientRPC &&) | |
Move constructor. | |
~ClientRPC () | |
Destructor. | |
ClientRPC & | operator= (ClientRPC &&) |
Move assignment. | |
void | cancel () |
Abort the RPC. | |
bool | isReady () |
Indicate whether a response or error has been received for the RPC. | |
Status | waitForReply (google::protobuf::Message *response, google::protobuf::Message *serviceSpecificError, TimePoint timeout) |
Wait for a reply to the RPC or an error. | |
std::string | getErrorMessage () const |
If an RPC failure occurred, return a message describing that error. | |
Private Member Functions | |
ClientRPC (const ClientRPC &) | |
ClientRPC & | operator= (const ClientRPC &) |
Private Attributes | |
uint16_t | service |
Identifies the service running on the server. | |
uint16_t | opCode |
Identifies the remote procedure within the Service to execute. | |
OpaqueClientRPC | opaqueRPC |
This class represents an asynchronous remote procedure call.
Unlike OpaqueClientRPC, this executes a particular method on a particular service.
TODO(ongaro): This abstraction should ideally contain protocol version negotiation for the higher layer. To do so, we'd want to be able to associate a small amount of state with the session.
Definition at line 41 of file ClientRPC.h.
Clock used for timeouts.
Definition at line 44 of file ClientRPC.h.
Type for absolute time values used for timeouts.
Definition at line 46 of file ClientRPC.h.
The return type of waitForReply().
OK |
The service returned a normal response. This is available in 'response'. |
SERVICE_SPECIFIC_ERROR |
The service threw an error (but at the transport level, the RPC succeeded). Service-specific details may be available in 'serviceSpecificError'. |
RPC_FAILED |
The server could not be contacted or did not reply. It is unknown whether or not the server executed the RPC. More information is available with getErrorMessage(). |
RPC_CANCELED |
The RPC was aborted using cancel(). It is unknown whether the server executed or will execute the RPC. |
TIMEOUT |
The RPC did not complete before the given timeout elapsed. It is unknown whether or not the server executed the RPC (yet). |
INVALID_SERVICE |
The server is not running the requested service. |
INVALID_REQUEST |
The server rejected the request, probably because it doesn't support the opcode, or maybe the request arguments were invalid. |
Definition at line 110 of file ClientRPC.h.
LogCabin::RPC::ClientRPC::ClientRPC | ( | std::shared_ptr< RPC::ClientSession > | session, |
uint16_t | service, | ||
uint8_t | serviceSpecificErrorVersion, | ||
uint16_t | opCode, | ||
const google::protobuf::Message & | request | ||
) |
Issue an RPC to a remote service.
session | A connection to the remote server. |
service | Identifies the service running on the server. See Protocol::Common::ServiceId. |
serviceSpecificErrorVersion | This tells the Service what service-specific errors the client understands. Clients can expect services to not send service-specific errors introduced in newer versions, but they should remain compatible with older versions. |
opCode | Identifies the remote procedure within the Service to execute. |
request | The arguments to the remote procedure. |
Definition at line 32 of file ClientRPC.cc.
Default constructor.
This doesn't create a valid RPC, but it is useful as a placeholder.
Definition at line 59 of file ClientRPC.cc.
LogCabin::RPC::ClientRPC::ClientRPC | ( | ClientRPC && | other | ) |
Move constructor.
Definition at line 66 of file ClientRPC.cc.
Destructor.
Definition at line 73 of file ClientRPC.cc.
LogCabin::RPC::ClientRPC::ClientRPC | ( | const ClientRPC & | ) | [private] |
Move assignment.
Definition at line 78 of file ClientRPC.cc.
void LogCabin::RPC::ClientRPC::cancel | ( | ) |
Abort the RPC.
The caller is no longer interested in its reply.
Definition at line 87 of file ClientRPC.cc.
bool LogCabin::RPC::ClientRPC::isReady | ( | ) |
Indicate whether a response or error has been received for the RPC.
Definition at line 93 of file ClientRPC.cc.
ClientRPC::Status LogCabin::RPC::ClientRPC::waitForReply | ( | google::protobuf::Message * | response, |
google::protobuf::Message * | serviceSpecificError, | ||
TimePoint | timeout | ||
) |
Wait for a reply to the RPC or an error.
Panics if the server responds but is not running the same protocol.
[out] | response | If not NULL, this will be filled in if this method returns OK. |
[out] | serviceSpecificError | If not NULL, this will be filled in if this method returns SERVICE_SPECIFIC_ERROR. |
[in] | timeout | After this time has elapsed, stop waiting and return TIMEOUT. In this case, response and serviceSpecificError will be left unmodified. |
Definition at line 99 of file ClientRPC.cc.
std::string LogCabin::RPC::ClientRPC::getErrorMessage | ( | ) | const |
If an RPC failure 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 202 of file ClientRPC.cc.
uint16_t LogCabin::RPC::ClientRPC::service [private] |
Identifies the service running on the server.
See Protocol::Common::ServiceId.
Definition at line 188 of file ClientRPC.h.
uint16_t LogCabin::RPC::ClientRPC::opCode [private] |
Identifies the remote procedure within the Service to execute.
Definition at line 193 of file ClientRPC.h.
Definition at line 195 of file ClientRPC.h.