proxygen
wangle::PipelinedServerDispatcher< Req, Resp > Class Template Reference

#include <ServerDispatcher.h>

Inheritance diagram for wangle::PipelinedServerDispatcher< Req, Resp >:
wangle::HandlerAdapter< Req, Resp > wangle::Handler< Req, Req, Resp, Resp > wangle::HandlerBase< HandlerContext< Req, Resp > >

Public Types

typedef HandlerAdapter< Req, Resp >::Context Context
 
- Public Types inherited from wangle::HandlerAdapter< Req, Resp >
typedef Handler< Req, Req, Resp, Resp >::Context Context
 
- Public Types inherited from wangle::Handler< Req, Req, Resp, Resp >
typedef Req rin
 
typedef Req rout
 
typedef Resp win
 
typedef Resp wout
 
typedef HandlerContext< Req, Resp > Context
 

Public Member Functions

 PipelinedServerDispatcher (Service< Req, Resp > *service)
 
void read (Context *, Req in) override
 
void sendResponses ()
 
- Public Member Functions inherited from wangle::HandlerAdapter< Req, Resp >
void read (Context *ctx, Reqmsg) override
 
folly::Future< folly::Unitwrite (Context *ctx, Respmsg) override
 
- Public Member Functions inherited from wangle::Handler< Req, Req, Resp, Resp >
 ~Handler () override=default
 
virtual void readEOF (Context *ctx)
 
virtual void readException (Context *ctx, folly::exception_wrapper e)
 
virtual void transportActive (Context *ctx)
 
virtual void transportInactive (Context *ctx)
 
virtual folly::Future< folly::UnitwriteException (Context *ctx, folly::exception_wrapper e)
 
virtual folly::Future< folly::Unitclose (Context *ctx)
 
- Public Member Functions inherited from wangle::HandlerBase< HandlerContext< Req, Resp > >
virtual ~HandlerBase ()=default
 
virtual void attachPipeline (HandlerContext< Req, Resp > *)
 
virtual void detachPipeline (HandlerContext< Req, Resp > *)
 
HandlerContext< Req, Resp > * getContext ()
 

Private Attributes

Service< Req, Resp > * service_
 
uint32_t requestId_ {1}
 
std::unordered_map< uint32_t, Resp > responses_
 
uint32_t lastWrittenId_ {0}
 

Additional Inherited Members

- Static Public Attributes inherited from wangle::Handler< Req, Req, Resp, Resp >
static const HandlerDir dir
 

Detailed Description

template<typename Req, typename Resp = Req>
class wangle::PipelinedServerDispatcher< Req, Resp >

Dispatch requests from pipeline as they come in. Responses are queued until they can be sent in order.

Definition at line 52 of file ServerDispatcher.h.

Member Typedef Documentation

template<typename Req , typename Resp = Req>
typedef HandlerAdapter<Req, Resp>::Context wangle::PipelinedServerDispatcher< Req, Resp >::Context

Definition at line 55 of file ServerDispatcher.h.

Constructor & Destructor Documentation

template<typename Req , typename Resp = Req>
wangle::PipelinedServerDispatcher< Req, Resp >::PipelinedServerDispatcher ( Service< Req, Resp > *  service)
inlineexplicit

Definition at line 57 of file ServerDispatcher.h.

58  : service_(service) {}
Service< Req, Resp > * service_

Member Function Documentation

template<typename Req , typename Resp = Req>
void wangle::PipelinedServerDispatcher< Req, Resp >::read ( Context ,
Req  in 
)
inlineoverride

Definition at line 60 of file ServerDispatcher.h.

References folly::gen::move.

60  {
61  auto requestId = requestId_++;
62  (*service_)(std::move(in)).then([requestId,this](Resp& resp){
63  responses_[requestId] = resp;
64  sendResponses();
65  });
66  }
std::unordered_map< uint32_t, Resp > responses_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<typename Req , typename Resp = Req>
void wangle::PipelinedServerDispatcher< Req, Resp >::sendResponses ( )
inline

Definition at line 68 of file ServerDispatcher.h.

References wangle::HandlerContext< In, Out >::fireWrite(), wangle::HandlerBase< HandlerContext< Req, Resp > >::getContext(), and folly::gen::move.

68  {
69  auto search = responses_.find(lastWrittenId_+1);
70  while (search != responses_.end()) {
71  Resp resp = std::move(search->second);
72  responses_.erase(search->first);
73  this->getContext()->fireWrite(std::move(resp));
75  search = responses_.find(lastWrittenId_+1);
76  }
77  }
std::unordered_map< uint32_t, Resp > responses_
virtual folly::Future< folly::Unit > fireWrite(Out msg)=0
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
HandlerContext< Req, Resp > * getContext()
Definition: Handler.h:34

Member Data Documentation

template<typename Req , typename Resp = Req>
uint32_t wangle::PipelinedServerDispatcher< Req, Resp >::lastWrittenId_ {0}
private

Definition at line 83 of file ServerDispatcher.h.

template<typename Req , typename Resp = Req>
uint32_t wangle::PipelinedServerDispatcher< Req, Resp >::requestId_ {1}
private

Definition at line 81 of file ServerDispatcher.h.

template<typename Req , typename Resp = Req>
std::unordered_map<uint32_t, Resp> wangle::PipelinedServerDispatcher< Req, Resp >::responses_
private

Definition at line 82 of file ServerDispatcher.h.

template<typename Req , typename Resp = Req>
Service<Req, Resp>* wangle::PipelinedServerDispatcher< Req, Resp >::service_
private

Definition at line 80 of file ServerDispatcher.h.


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