proxygen
proxygen::Service Class Referenceabstract

#include <Service.h>

Public Member Functions

 Service ()
 
virtual ~Service ()
 
virtual void init (folly::EventBase *mainEventBase, const std::list< RequestWorker * > &workers)=0
 
virtual void finishInit ()
 
virtual void startAccepting ()
 
virtual void failHealthChecks ()
 
virtual void stopAccepting ()=0
 
virtual void pauseListening ()
 
virtual void dropConnections (double)
 
virtual void forceStop ()
 
virtual void initWorkerState (RequestWorker *)
 
virtual void cleanupWorkerState (RequestWorker *)
 
void addServiceWorker (std::unique_ptr< ServiceWorker > worker, RequestWorker *reqWorker)
 
const std::list< std::unique_ptr< ServiceWorker > > & getServiceWorkers () const
 
void clearServiceWorkers ()
 
void addWorkerEventBase (folly::EventBase *evb)
 
const std::vector< folly::EventBase * > & getWorkerEventBases ()
 

Private Member Functions

 Service (Service const &)=delete
 
Serviceoperator= (Service const &)=delete
 

Private Attributes

std::list< std::unique_ptr< ServiceWorker > > workers_
 
std::vector< folly::EventBase * > workerEvbs_
 

Detailed Description

Definition at line 32 of file Service.h.

Constructor & Destructor Documentation

proxygen::Service::Service ( )

Definition at line 17 of file Service.cpp.

Referenced by getWorkerEventBases().

17  {
18 }
proxygen::Service::~Service ( )
virtual

Definition at line 20 of file Service.cpp.

20  {
21 }
proxygen::Service::Service ( Service const &  )
privatedelete

Member Function Documentation

void proxygen::Service::addServiceWorker ( std::unique_ptr< ServiceWorker worker,
RequestWorker reqWorker 
)

Add a new ServiceWorker (subclasses should create one ServiceWorker per worker thread)

Definition at line 23 of file Service.cpp.

References proxygen::RequestWorker::addServiceWorker(), folly::gen::move, and workers_.

Referenced by cleanupWorkerState().

24  {
25  reqWorker->addServiceWorker(this, worker.get());
26  workers_.emplace_back(std::move(worker));
27 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::list< std::unique_ptr< ServiceWorker > > workers_
Definition: Service.h:178
void proxygen::Service::addWorkerEventBase ( folly::EventBase evb)
inline

Definition at line 164 of file Service.h.

References workerEvbs_.

164  {
165  workerEvbs_.push_back(evb);
166  }
std::vector< folly::EventBase * > workerEvbs_
Definition: Service.h:179
virtual void proxygen::Service::cleanupWorkerState ( RequestWorker )
inlinevirtual

Perform per-thread cleanup.

This method will be called once for each RequestWorker thread, just before that thread is about to exit. Note that this method is called from the worker thread itself, not from the main thread.

failHealthChecks() and stopAccepting() will always be called in the main thread before cleanupWorkerState() is called in any of the worker threads.

forceStop() may be called in the main thread at any point during shutdown. (i.e., Some worker threads may already have finished and called cleanupWorkerState(). Once forceStop() is invoked, the remaining threads will forcibly exit and then call cleanupWorkerState().)

Definition at line 143 of file Service.h.

References addServiceWorker().

143 {}
void proxygen::Service::clearServiceWorkers ( )

Delete all the workers

Definition at line 29 of file Service.cpp.

References workers_.

Referenced by getServiceWorkers().

29  {
30  workers_.clear();
31 }
std::list< std::unique_ptr< ServiceWorker > > workers_
Definition: Service.h:178
virtual void proxygen::Service::dropConnections ( double  )
inlinevirtual

Forcibly stop "pct" (0.0 to 1.0) of the remaining client connections.

If the service does not stop on its own after stopAccepting() is called, then proxygen might call dropConnections() several times to gradually stop all processing before finally calling forceStop().

Definition at line 104 of file Service.h.

104 {}
virtual void proxygen::Service::failHealthChecks ( )
inlinevirtual

Mark the service as about to stop; invoked from main thread.

This indicates that the service will be told to stop at some later time and should continue to service requests but tell the healthchecker that it is dying.

Definition at line 76 of file Service.h.

References stopAccepting().

76 {}
virtual void proxygen::Service::finishInit ( )
inlinevirtual

Finish any service initialization that requires the use of the worker threads.

Definition at line 56 of file Service.h.

56 {}
virtual void proxygen::Service::forceStop ( )
inlinevirtual

Forcibly stop the service.

If the service does not stop on its own after stopAccepting() is called, forceStop() will eventually be called to forcibly stop all processing.

(At the moment this isn't pure virtual simply because I haven't had the time to update all existing services to implement forceStop(). Proxygen will forcibly terminate the event loop even if a service does not stop processing when forceStop() is called, so properly implementing forceStop() isn't strictly required.)

Definition at line 118 of file Service.h.

118 {}
const std::list<std::unique_ptr<ServiceWorker> >& proxygen::Service::getServiceWorkers ( ) const
inline

List of workers

Definition at line 155 of file Service.h.

References clearServiceWorkers(), and workers_.

155  {
156  return workers_;
157  }
std::list< std::unique_ptr< ServiceWorker > > workers_
Definition: Service.h:178
const std::vector<folly::EventBase*>& proxygen::Service::getWorkerEventBases ( )
inline

Definition at line 168 of file Service.h.

References operator=(), Service(), and workerEvbs_.

168  {
169  return workerEvbs_;
170  }
std::vector< folly::EventBase * > workerEvbs_
Definition: Service.h:179
virtual void proxygen::Service::init ( folly::EventBase mainEventBase,
const std::list< RequestWorker * > &  workers 
)
pure virtual

Initialize the service.

init() will be invoked from proxygen's main thread, before the worker threads have started processing their event loops.

The return value indicates if the service is enabled or not. Return true if the service is enabled and was initialized successfully, and false if the service is disabled or is intialized successfully. Throw an exception if an error occurred initializing it.

virtual void proxygen::Service::initWorkerState ( RequestWorker )
inlinevirtual

Perform per-thread init.

This method will be called once for each RequestWorker thread, just after the worker thread started.

Definition at line 126 of file Service.h.

126 {}
Service& proxygen::Service::operator= ( Service const &  )
privatedelete

Referenced by getWorkerEventBases().

virtual void proxygen::Service::pauseListening ( )
inlinevirtual

Pause listening for new connections; invoked from proxygen's main thread.

This should cause the service to pause listening for new connections. The already accepted connections must not be affected. It may or may not be followed by stopAccepting or resume listening.

Definition at line 95 of file Service.h.

95 {}
virtual void proxygen::Service::startAccepting ( )
inlinevirtual

Start to accept connection on the listening sockect(s)

All the expansive preparation work should be done befofe startAccepting(), i.g., in constructor or init(). startAccepting() should be lightweight, ideally just the call of accept() on all the listening sockects. Otherwise, the first accepted connection may experience high latency.

Definition at line 67 of file Service.h.

67 {}
virtual void proxygen::Service::stopAccepting ( )
pure virtual

Stop accepting all new work; invoked from proxygen's main thread.

This should cause the service to stop accepting new work, and begin to fully shut down. stop() may return before all work has completed, but it should eventually cause all events for this service to be removed from the main EventBase and from the worker threads.

Referenced by failHealthChecks().

Member Data Documentation

std::vector<folly::EventBase*> proxygen::Service::workerEvbs_
private

Definition at line 179 of file Service.h.

Referenced by addWorkerEventBase(), and getWorkerEventBases().

std::list<std::unique_ptr<ServiceWorker> > proxygen::Service::workers_
private

Definition at line 178 of file Service.h.

Referenced by addServiceWorker(), clearServiceWorkers(), and getServiceWorkers().


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