proxygen
|
#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 | |
Service & | operator= (Service const &)=delete |
Private Attributes | |
std::list< std::unique_ptr< ServiceWorker > > | workers_ |
std::vector< folly::EventBase * > | workerEvbs_ |
proxygen::Service::Service | ( | ) |
|
virtual |
Definition at line 20 of file Service.cpp.
|
privatedelete |
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().
|
inline |
Definition at line 164 of file Service.h.
References workerEvbs_.
|
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().
void proxygen::Service::clearServiceWorkers | ( | ) |
Delete all the workers
Definition at line 29 of file Service.cpp.
References workers_.
Referenced by getServiceWorkers().
|
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().
|
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().
|
inlinevirtual |
|
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.)
|
inline |
List of workers
Definition at line 155 of file Service.h.
References clearServiceWorkers(), and workers_.
|
inline |
Definition at line 168 of file Service.h.
References operator=(), Service(), and workerEvbs_.
|
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.
|
inlinevirtual |
Perform per-thread init.
This method will be called once for each RequestWorker thread, just after the worker thread started.
Referenced by getWorkerEventBases().
|
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.
|
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.
|
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().
|
private |
Definition at line 179 of file Service.h.
Referenced by addWorkerEventBase(), and getWorkerEventBases().
|
private |
Definition at line 178 of file Service.h.
Referenced by addServiceWorker(), clearServiceWorkers(), and getServiceWorkers().