proxygen
proxygen::ServiceWorker Class Reference

#include <ServiceWorker.h>

Public Types

using AcceptorMap = std::map< AcceptorAddress, std::unique_ptr< wangle::Acceptor >>
 
using NamedAddressMap = std::map< std::string, AcceptorAddress >
 

Public Member Functions

 ServiceWorker (Service *service, RequestWorker *worker)
 
virtual ~ServiceWorker ()
 
ServicegetService () const
 
void addServiceAcceptor (const folly::SocketAddress &address, std::unique_ptr< wangle::Acceptor > acceptor)
 
void addServiceAcceptor (const AcceptorAddress &accAddress, std::unique_ptr< wangle::Acceptor > acceptor)
 
void drainServiceAcceptor (const folly::SocketAddress &address)
 
void drainServiceAcceptor (const AcceptorAddress &accAddress)
 
RequestWorkergetRequestWorker () const
 
const AcceptorMapgetAcceptors ()
 
wangle::AcceptorgetAcceptorByName (std::string name) const
 
const AcceptorMapgetDrainingAcceptors ()
 
virtual void flushStats ()
 
virtual void clearAcceptors ()
 
virtual void clearDrainingAcceptors ()
 
wangle::IConnectionCountergetConnectionCounter ()
 
virtual void forceStop ()
 

Protected Attributes

wangle::SimpleConnectionCounter connectionCounter_
 

Private Member Functions

 ServiceWorker (ServiceWorker const &)=delete
 
ServiceWorkeroperator= (ServiceWorker const &)=delete
 
void addAcceptor (const AcceptorAddress &accAddress, std::unique_ptr< wangle::Acceptor > acceptor, AcceptorMap &acceptors)
 

Private Attributes

Serviceservice_
 
RequestWorkerworker_
 
AcceptorMap acceptors_
 
NamedAddressMap namedAddress_
 
AcceptorMap drainingAcceptors_
 

Detailed Description

ServiceWorker contains all of the per-thread information for a Service.

ServiceWorker contains a pointer back to the single global Service. It contains a list of ProxyAcceptor objects for this worker thread, one per VIP.

ServiceWorker fits into the Proxygen object hierarchy as follows:

  • Service: one instance (globally across the entire program)
  • ServiceWorker: one instance per thread
  • ServiceAcceptor: one instance per VIP per thread

Definition at line 37 of file ServiceWorker.h.

Member Typedef Documentation

Definition at line 40 of file ServiceWorker.h.

Constructor & Destructor Documentation

proxygen::ServiceWorker::ServiceWorker ( Service service,
RequestWorker worker 
)
inline

Definition at line 44 of file ServiceWorker.h.

45  : service_(service), worker_(worker) {
46  }
RequestWorker * worker_
virtual proxygen::ServiceWorker::~ServiceWorker ( )
inlinevirtual

Definition at line 48 of file ServiceWorker.h.

48  {
49  }
proxygen::ServiceWorker::ServiceWorker ( ServiceWorker const &  )
privatedelete

Member Function Documentation

void proxygen::ServiceWorker::addAcceptor ( const AcceptorAddress accAddress,
std::unique_ptr< wangle::Acceptor acceptor,
AcceptorMap acceptors 
)
inlineprivate

Definition at line 140 of file ServiceWorker.h.

References folly::gen::move.

Referenced by addServiceAcceptor(), and drainServiceAcceptor().

142  {
143  CHECK(acceptors.find(accAddress) == acceptors.end());
144  acceptors.insert(std::make_pair(accAddress, std::move(acceptor)));
145  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void proxygen::ServiceWorker::addServiceAcceptor ( const folly::SocketAddress address,
std::unique_ptr< wangle::Acceptor acceptor 
)
inline

Definition at line 55 of file ServiceWorker.h.

References folly::gen::move, and proxygen::AcceptorAddress::TCP.

56  {
58  AcceptorAddress(address, AcceptorAddress::AcceptorType::TCP),
59  std::move(acceptor));
60  }
void addServiceAcceptor(const folly::SocketAddress &address, std::unique_ptr< wangle::Acceptor > acceptor)
Definition: ServiceWorker.h:55
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void proxygen::ServiceWorker::addServiceAcceptor ( const AcceptorAddress accAddress,
std::unique_ptr< wangle::Acceptor acceptor 
)
inline

Definition at line 62 of file ServiceWorker.h.

References acceptors_, addAcceptor(), wangle::Acceptor::getName(), folly::gen::move, and namedAddress_.

63  {
64  namedAddress_.emplace(acceptor->getName(), accAddress);
65  addAcceptor(accAddress, std::move(acceptor), acceptors_);
66  }
void addAcceptor(const AcceptorAddress &accAddress, std::unique_ptr< wangle::Acceptor > acceptor, AcceptorMap &acceptors)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
NamedAddressMap namedAddress_
const std::string & getName() const
Definition: Acceptor.h:162
virtual void proxygen::ServiceWorker::clearAcceptors ( )
inlinevirtual

Definition at line 115 of file ServiceWorker.h.

References acceptors_, drainingAcceptors_, and namedAddress_.

115  {
116  acceptors_.clear();
117  namedAddress_.clear();
118  drainingAcceptors_.clear();
119  }
NamedAddressMap namedAddress_
AcceptorMap drainingAcceptors_
virtual void proxygen::ServiceWorker::clearDrainingAcceptors ( )
inlinevirtual

Definition at line 121 of file ServiceWorker.h.

References drainingAcceptors_.

121  {
122  drainingAcceptors_.clear();
123  }
AcceptorMap drainingAcceptors_
void proxygen::ServiceWorker::drainServiceAcceptor ( const folly::SocketAddress address)
inline

Definition at line 68 of file ServiceWorker.h.

References proxygen::AcceptorAddress::TCP.

68  {
70  AcceptorAddress(address, AcceptorAddress::AcceptorType::TCP));
71  }
void drainServiceAcceptor(const folly::SocketAddress &address)
Definition: ServiceWorker.h:68
void proxygen::ServiceWorker::drainServiceAcceptor ( const AcceptorAddress accAddress)
inline

Definition at line 73 of file ServiceWorker.h.

References acceptors_, addAcceptor(), drainingAcceptors_, folly::gen::move, name, and namedAddress_.

73  {
74  // Move the old acceptor to drainingAcceptors_ if present
75  const auto& it = acceptors_.find(accAddress);
76  if (it != acceptors_.end()) {
77  auto name = it->second->getName();
78  addAcceptor(accAddress, std::move(it->second), drainingAcceptors_);
79  acceptors_.erase(it);
80  namedAddress_.erase(name);
81  }
82  }
void addAcceptor(const AcceptorAddress &accAddress, std::unique_ptr< wangle::Acceptor > acceptor, AcceptorMap &acceptors)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
NamedAddressMap namedAddress_
const char * name
Definition: http_parser.c:437
AcceptorMap drainingAcceptors_
virtual void proxygen::ServiceWorker::flushStats ( )
inlinevirtual

Definition at line 111 of file ServiceWorker.h.

111  {
112  }
virtual void proxygen::ServiceWorker::forceStop ( )
inlinevirtual

Definition at line 129 of file ServiceWorker.h.

129  {
130  }
wangle::Acceptor* proxygen::ServiceWorker::getAcceptorByName ( std::string  name) const
inline

Find an acceptor by name running in the same request worker.

Definition at line 95 of file ServiceWorker.h.

References acceptors_, and namedAddress_.

95  {
96  auto it = namedAddress_.find(name);
97  if (it != namedAddress_.end()) {
98  auto it2 = acceptors_.find(it->second);
99  if (it2 != acceptors_.end()) {
100  return it2->second.get();
101  }
102  }
103  return nullptr;
104  }
NamedAddressMap namedAddress_
const char * name
Definition: http_parser.c:437
const AcceptorMap& proxygen::ServiceWorker::getAcceptors ( )
inline

Definition at line 88 of file ServiceWorker.h.

References acceptors_.

88  {
89  return acceptors_;
90  }
wangle::IConnectionCounter* proxygen::ServiceWorker::getConnectionCounter ( )
inline

Definition at line 125 of file ServiceWorker.h.

References connectionCounter_.

125  {
126  return &connectionCounter_;
127  }
wangle::SimpleConnectionCounter connectionCounter_
const AcceptorMap& proxygen::ServiceWorker::getDrainingAcceptors ( )
inline

Definition at line 106 of file ServiceWorker.h.

References drainingAcceptors_.

106  {
107  return drainingAcceptors_;
108  }
AcceptorMap drainingAcceptors_
RequestWorker* proxygen::ServiceWorker::getRequestWorker ( ) const
inline

Definition at line 84 of file ServiceWorker.h.

References worker_.

84  {
85  return worker_;
86  }
RequestWorker * worker_
Service* proxygen::ServiceWorker::getService ( ) const
inline

Definition at line 51 of file ServiceWorker.h.

References service_.

51  {
52  return service_;
53  }
ServiceWorker& proxygen::ServiceWorker::operator= ( ServiceWorker const &  )
privatedelete

Member Data Documentation

AcceptorMap proxygen::ServiceWorker::acceptors_
private

A list of the Acceptor objects specific to this worker thread, one Acceptor per VIP.

Definition at line 162 of file ServiceWorker.h.

Referenced by addServiceAcceptor(), clearAcceptors(), drainServiceAcceptor(), getAcceptorByName(), and getAcceptors().

wangle::SimpleConnectionCounter proxygen::ServiceWorker::connectionCounter_
protected

Definition at line 133 of file ServiceWorker.h.

Referenced by getConnectionCounter().

AcceptorMap proxygen::ServiceWorker::drainingAcceptors_
private

A list of Acceptors that are being drained and will be deleted soon.

Definition at line 173 of file ServiceWorker.h.

Referenced by clearAcceptors(), clearDrainingAcceptors(), drainServiceAcceptor(), and getDrainingAcceptors().

NamedAddressMap proxygen::ServiceWorker::namedAddress_
private

A list of the addresses indexed by name, used to look up an acceptor by name

Definition at line 168 of file ServiceWorker.h.

Referenced by addServiceAcceptor(), clearAcceptors(), drainServiceAcceptor(), and getAcceptorByName().

Service* proxygen::ServiceWorker::service_
private

The global Service object.

Definition at line 150 of file ServiceWorker.h.

Referenced by getService().

RequestWorker* proxygen::ServiceWorker::worker_
private

The RequestWorker that is actually responsible for running the EventBase loop in this thread.

Definition at line 156 of file ServiceWorker.h.

Referenced by getRequestWorker().


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