proxygen
RequestWorker.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <cstdint>
13 #include <map>
15 
16 namespace proxygen {
17 
18 class Service;
19 class ServiceWorker;
20 
25 class RequestWorker : public WorkerThread {
26  public:
28  public:
30  virtual void workerStarted(RequestWorker*) = 0;
31  virtual void workerFinished(RequestWorker*) = 0;
32  };
33 
42  FinishCallback& callback, uint8_t threadId,
43  const std::string& evbName = std::string());
44 
45  static uint64_t nextRequestId();
46 
48  RequestWorker* self = dynamic_cast<RequestWorker*>(
50  CHECK_NOTNULL(self);
51  return self;
52  }
53 
57  void addServiceWorker(Service* service, ServiceWorker* sw) {
58  CHECK(serviceWorkers_.find(service) == serviceWorkers_.end());
59  serviceWorkers_[service] = sw;
60  }
61 
67  auto it = serviceWorkers_.find(service);
68  CHECK(it != serviceWorkers_.end());
69  return it->second;
70  }
71 
77  void flushStats();
78 
79  private:
80  void setup() override;
81  void cleanup() override;
82 
83  // The next request id within this thread. The id has its highest byte set to
84  // the thread id, so is unique across the process.
86 
87  // The ServiceWorkers executing in this worker
88  std::map<Service*, ServiceWorker*> serviceWorkers_;
89 
91 };
92 
93 }
void addServiceWorker(Service *service, ServiceWorker *sw)
Definition: RequestWorker.h:57
requires E e noexcept(noexcept(s.error(std::move(e))))
virtual void workerStarted(RequestWorker *)=0
RequestWorker(FinishCallback &callback, uint8_t threadId, const std::string &evbName=std::string())
ServiceWorker * getServiceWorker(Service *service) const
Definition: RequestWorker.h:66
FinishCallback & callback_
Definition: RequestWorker.h:90
static RequestWorker * getRequestWorker()
Definition: RequestWorker.h:47
void cleanup() override
const char * string
Definition: Conv.cpp:212
static uint64_t nextRequestId()
virtual void workerFinished(RequestWorker *)=0
std::map< Service *, ServiceWorker * > serviceWorkers_
Definition: RequestWorker.h:88
static WorkerThread * getCurrentWorkerThread()
Definition: WorkerThread.h:111