proxygen
proxygen::RequestWorker Class Reference

#include <RequestWorker.h>

Inheritance diagram for proxygen::RequestWorker:
proxygen::WorkerThread

Classes

class  FinishCallback
 

Public Member Functions

 RequestWorker (FinishCallback &callback, uint8_t threadId, const std::string &evbName=std::string())
 
void addServiceWorker (Service *service, ServiceWorker *sw)
 
ServiceWorkergetServiceWorker (Service *service) const
 
void flushStats ()
 
- Public Member Functions inherited from proxygen::WorkerThread
 WorkerThread (folly::EventBaseManager *ebm, const std::string &evbName=std::string())
 
virtual ~WorkerThread ()
 
void start ()
 
void stopWhenIdle ()
 
void forceStop ()
 
void wait ()
 
folly::EventBasegetEventBase ()
 
std::thread::native_handle_type getThreadNativeHandle () noexcept
 
std::thread::id getThreadId () const noexcept
 

Static Public Member Functions

static uint64_t nextRequestId ()
 
static RequestWorkergetRequestWorker ()
 
- Static Public Member Functions inherited from proxygen::WorkerThread
static WorkerThreadgetCurrentWorkerThread ()
 

Private Member Functions

void setup () override
 
void cleanup () override
 

Private Attributes

uint64_t nextRequestId_
 
std::map< Service *, ServiceWorker * > serviceWorkers_
 
FinishCallbackcallback_
 

Additional Inherited Members

Detailed Description

RequestWorker extends WorkerThread, and also contains a list of ServiceWorkers running in this thread.

Definition at line 25 of file RequestWorker.h.

Constructor & Destructor Documentation

proxygen::RequestWorker::RequestWorker ( FinishCallback callback,
uint8_t  threadId,
const std::string evbName = std::string() 
)

Create a new RequestWorker.

Parameters
proxygenThe object to notify when this worker finishes.
threadIdA unique ID for this worker.
evbNameThe event base will ne named to this name (thread name)

Definition at line 17 of file RequestWorker.cpp.

Referenced by proxygen::RequestWorker::FinishCallback::~FinishCallback().

20  nextRequestId_(static_cast<uint64_t>(threadId) << 56),
21  callback_(callback) {
22 }
static EventBaseManager * get()
WorkerThread(folly::EventBaseManager *ebm, const std::string &evbName=std::string())
FinishCallback & callback_
Definition: RequestWorker.h:90

Member Function Documentation

void proxygen::RequestWorker::addServiceWorker ( Service service,
ServiceWorker sw 
)
inline

Track the ServiceWorker objects in-use by this worker.

Definition at line 57 of file RequestWorker.h.

References serviceWorkers_.

Referenced by proxygen::Service::addServiceWorker().

57  {
58  CHECK(serviceWorkers_.find(service) == serviceWorkers_.end());
59  serviceWorkers_[service] = sw;
60  }
std::map< Service *, ServiceWorker * > serviceWorkers_
Definition: RequestWorker.h:88
void proxygen::RequestWorker::cleanup ( )
overrideprivatevirtual

Reimplemented from proxygen::WorkerThread.

Definition at line 40 of file RequestWorker.cpp.

References callback_, proxygen::WorkerThread::cleanup(), and proxygen::RequestWorker::FinishCallback::workerFinished().

Referenced by getServiceWorker().

40  {
43 }
virtual void cleanup()
FinishCallback & callback_
Definition: RequestWorker.h:90
virtual void workerFinished(RequestWorker *)=0
void proxygen::RequestWorker::flushStats ( )

Flush any thread-local stats being tracked by our ServiceWorkers.

This must be invoked from within worker's thread.

Definition at line 28 of file RequestWorker.cpp.

References proxygen::WorkerThread::getEventBase(), and serviceWorkers_.

Referenced by getServiceWorker().

28  {
29  CHECK(getEventBase()->isInEventBaseThread());
30  for (auto& p: serviceWorkers_) {
31  p.second->flushStats();
32  }
33 }
folly::EventBase * getEventBase()
Definition: WorkerThread.h:85
std::map< Service *, ServiceWorker * > serviceWorkers_
Definition: RequestWorker.h:88
static RequestWorker* proxygen::RequestWorker::getRequestWorker ( )
inlinestatic

Definition at line 47 of file RequestWorker.h.

References proxygen::WorkerThread::getCurrentWorkerThread().

Referenced by nextRequestId().

47  {
48  RequestWorker* self = dynamic_cast<RequestWorker*>(
50  CHECK_NOTNULL(self);
51  return self;
52  }
RequestWorker(FinishCallback &callback, uint8_t threadId, const std::string &evbName=std::string())
static WorkerThread * getCurrentWorkerThread()
Definition: WorkerThread.h:111
ServiceWorker* proxygen::RequestWorker::getServiceWorker ( Service service) const
inline

For a given service, returns the ServiceWorker associated with this RequestWorker

Definition at line 66 of file RequestWorker.h.

References cleanup(), flushStats(), serviceWorkers_, and setup().

66  {
67  auto it = serviceWorkers_.find(service);
68  CHECK(it != serviceWorkers_.end());
69  return it->second;
70  }
std::map< Service *, ServiceWorker * > serviceWorkers_
Definition: RequestWorker.h:88
uint64_t proxygen::RequestWorker::nextRequestId ( )
static

Definition at line 24 of file RequestWorker.cpp.

References getRequestWorker(), and nextRequestId_.

Referenced by proxygen::RequestWorker::FinishCallback::~FinishCallback().

24  {
25  return getRequestWorker()->nextRequestId_++;
26 }
static RequestWorker * getRequestWorker()
Definition: RequestWorker.h:47
void proxygen::RequestWorker::setup ( )
overrideprivatevirtual

Reimplemented from proxygen::WorkerThread.

Definition at line 35 of file RequestWorker.cpp.

References callback_, proxygen::WorkerThread::setup(), and proxygen::RequestWorker::FinishCallback::workerStarted().

Referenced by getServiceWorker().

35  {
38 }
virtual void setup()
virtual void workerStarted(RequestWorker *)=0
FinishCallback & callback_
Definition: RequestWorker.h:90

Member Data Documentation

FinishCallback& proxygen::RequestWorker::callback_
private

Definition at line 90 of file RequestWorker.h.

Referenced by cleanup(), and setup().

uint64_t proxygen::RequestWorker::nextRequestId_
private

Definition at line 85 of file RequestWorker.h.

Referenced by nextRequestId().

std::map<Service*, ServiceWorker*> proxygen::RequestWorker::serviceWorkers_
private

Definition at line 88 of file RequestWorker.h.

Referenced by addServiceWorker(), flushStats(), and getServiceWorker().


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