LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Private Member Functions | Private Attributes
LogCabin::RPC::ClientRPC Class Reference

This class represents an asynchronous remote procedure call. More...

#include <ClientRPC.h>

List of all members.

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.
ClientRPCoperator= (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 &)
ClientRPCoperator= (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

Detailed Description

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.


Member Typedef Documentation

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.


Member Enumeration Documentation

The return type of waitForReply().

Enumerator:
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.


Constructor & Destructor Documentation

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.

Parameters:
sessionA connection to the remote server.
serviceIdentifies the service running on the server. See Protocol::Common::ServiceId.
serviceSpecificErrorVersionThis 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.
opCodeIdentifies the remote procedure within the Service to execute.
requestThe 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.

Move constructor.

Definition at line 66 of file ClientRPC.cc.

Destructor.

Definition at line 73 of file ClientRPC.cc.


Member Function Documentation

ClientRPC & LogCabin::RPC::ClientRPC::operator= ( ClientRPC &&  other)

Move assignment.

Definition at line 78 of file ClientRPC.cc.

Abort the RPC.

The caller is no longer interested in its reply.

Definition at line 87 of file ClientRPC.cc.

Indicate whether a response or error has been received for the RPC.

Returns:
True means the reply is ready or an error has occurred; false otherwise.

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.

Parameters:
[out]responseIf not NULL, this will be filled in if this method returns OK.
[out]serviceSpecificErrorIf not NULL, this will be filled in if this method returns SERVICE_SPECIFIC_ERROR.
[in]timeoutAfter this time has elapsed, stop waiting and return TIMEOUT. In this case, response and serviceSpecificError will be left unmodified.
Returns:
See the individual values of Status.

Definition at line 99 of file ClientRPC.cc.

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.

Returns:
If an RPC failure has occurred, a message describing that error. Otherwise, an empty string.

Definition at line 202 of file ClientRPC.cc.

ClientRPC& LogCabin::RPC::ClientRPC::operator= ( const ClientRPC ) [private]

Member Data Documentation

Identifies the service running on the server.

See Protocol::Common::ServiceId.

Definition at line 188 of file ClientRPC.h.

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines