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

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

#include <OpaqueClientRPC.h>

List of all members.

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.
OpaqueClientRPCoperator= (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::BufferpeekReply ()
 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 &)
OpaqueClientRPCoperator= (const OpaqueClientRPC &)

Private Attributes

std::mutex mutex
 Protects all the members of this class.
std::shared_ptr< ClientSessionsession
 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

Detailed Description

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.


Member Typedef Documentation

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.


Member Enumeration Documentation

State of the RPC.

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

The RPC was aborted using cancel().

Definition at line 49 of file OpaqueClientRPC.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

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.

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

Definition at line 76 of file OpaqueClientRPC.cc.

See Status.

Definition at line 84 of file OpaqueClientRPC.cc.

Look at the reply buffer.

Returns:
If the reply is already available and there were no errors, returns a pointer to the reply buffer inside this OpaqueClientRPC object. Otherwise, returns NULL.

Definition at line 92 of file OpaqueClientRPC.cc.

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.

Parameters:
timeoutAfter 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.

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]

Friends And Related Function Documentation

friend class ClientSession [friend]

Definition at line 183 of file OpaqueClientRPC.h.


Member Data Documentation

std::mutex LogCabin::RPC::OpaqueClientRPC::mutex [mutable, private]

Protects all the members of this class.

Definition at line 150 of file OpaqueClientRPC.h.

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.

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.

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.

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.


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