Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Protected Types | Protected Member Functions | List of all members
net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT > Class Template Referenceabstract

#include "rpc_handler.h"

Inheritance diagram for net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT >:
net_instaweb::RefCounted< RpcHandler< AsyncService, RequestT, ResponseT > >

Protected Types

typedef
::grpc::ServerAsyncReaderWriter
< ResponseT, RequestT > 
ReaderWriterT
 

Protected Member Functions

 RpcHandler (AsyncService *service,::grpc::ServerCompletionQueue *cq)
 
bool Write (const ResponseT &resp)
 
bool Finish (const ::grpc::Status &status)
 
void Start ()
 

Additional Inherited Members

- Public Member Functions inherited from net_instaweb::RefCounted< RpcHandler< AsyncService, RequestT, ResponseT > >
void Release ()
 
void AddRef ()
 
bool HasOneRef ()
 

Detailed Description

template<typename AsyncService, typename RequestT, typename ResponseT>
class net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT >

Class that manages the server side of a single gRPC bi-directional streaming RPC call; the invocation of a single method on a stub. We use bi-directional streaming RPCs because they allow us to send multiple messages over a single session and detect if either end disconnects.

RpcHandler should be bootstrapped by calling Start() on an instance, after which subsequent instances are automatically created as needed. The class cleans up after itself (ie: You call new without calling delete). This is modeled after CallData in gRPCs examples/cpp/helloworld/greeter_async_server.cc.

Every message received from a client will result in a call to HandleRequest. If gRPC detects a problem with the client (Read/Write failure, disconnect) after the first call to HandleRequest() but before Finish() is called, HandleError() will be invoked.

The class is expected to be manipulated on a single thread, so it should be considered thread compatible. Template args: AsyncService should be the AsyncService member of the service in your proto. For example, given: service SampleService { rpc SaveConfiguration(stream Req) returns(stream Resp) {} } the template should be <SampleService::AsyncService, Req, Resp>

Constructor & Destructor Documentation

template<typename AsyncService, typename RequestT , typename ResponseT >
net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT >::RpcHandler ( AsyncService *  service,
::grpc::ServerCompletionQueue *  cq 
)
protected

It would be nice to put the contents of Start() in this function, but InitResponder is pure virtual at this point, so we can't downcall into it.

Member Function Documentation

template<typename AsyncService , typename RequestT , typename ResponseT >
bool net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT >::Finish ( const ::grpc::Status &  status)
protected

Disconnect the client. Returns true if the client was not already disconnected. HandleError will not be called after Finish.

template<typename AsyncService , typename RequestT , typename ResponseT >
void net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT >::Start ( )
protected

Invokes InitResponder with the various arguments that are private members of this class. This should be called in a factory used to create the initial RpcHandler. RpcHandler will take care of calling it on all the subsequent ones made with CreateHandler().

RequestFoo should only fail if the service or queue have been shutdown. So we just hook this up to CallHandleError which will silently destroy "this" without calling HandleError(), because state_ is INIT.

template<typename AsyncService , typename RequestT , typename ResponseT>
bool net_instaweb::RpcHandler< AsyncService, RequestT, ResponseT >::Write ( const ResponseT &  resp)
protected

Send a response to the client. Returns true if the Write was successfully queued or false if the message cannot be sent, which may be because the client is not connected or because there is already a message outstanding. Once the Write has queued, one of either HandleWriteDone() or HandleError() will be called, depending on success.

The single queued write is a restriction of the gRPC ReaderWriter class. If desired, it would be simple to expand this class with a write queue.


The documentation for this class was generated from the following file: