forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.h
103 lines (86 loc) · 3.4 KB
/
worker.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include <functional>
#include "envoy/server/guarddog.h"
#include "envoy/server/overload_manager.h"
namespace Envoy {
namespace Server {
/**
* Interface for a threaded connection handling worker. All routines are thread safe.
*/
class Worker {
public:
virtual ~Worker() = default;
/**
* Completion called when a listener has been added on a worker and is listening for new
* connections.
* @param success supplies whether the addition was successful or not. FALSE can be returned
* when there is a race condition between bind() and listen().
*/
using AddListenerCompletion = std::function<void(bool success)>;
/**
* Add a listener to the worker.
* @param listener supplies the listener to add.
* @param completion supplies the completion to call when the listener has been added (or not) on
* the worker.
*/
virtual void addListener(Network::ListenerConfig& listener,
AddListenerCompletion completion) PURE;
/**
* @return uint64_t the number of connections across all listeners that the worker owns.
*/
virtual uint64_t numConnections() PURE;
/**
* Start the worker thread.
* @param guard_dog supplies the guard dog to use for thread watching.
*/
virtual void start(GuardDog& guard_dog) PURE;
/**
* Initialize stats for this worker's dispatcher, if available. The worker will output
* thread-specific stats under the given scope.
* @param scope the scope to contain the new per-dispatcher stats created here.
* @param prefix the stats prefix to identify this dispatcher.
*/
virtual void initializeStats(Stats::Scope& scope, const std::string& prefix) PURE;
/**
* Stop the worker thread.
*/
virtual void stop() PURE;
/**
* Remove a listener from the worker.
* @param listener supplies the listener to remove.
* @param completion supplies the completion to be called when the listener has been removed.
* This completion is called on the worker thread. No locking is performed by the worker.
*/
virtual void removeListener(Network::ListenerConfig& listener,
std::function<void()> completion) PURE;
/**
* Stop a listener from accepting new connections. This is used for server draining.
* @param listener supplies the listener to stop.
* @param completion supplies the completion to be called when the listener has stopped
* accepting new connections. This completion is called on the worker thread. No locking is
* performed by the worker.
*/
virtual void stopListener(Network::ListenerConfig& listener,
std::function<void()> completion) PURE;
virtual void updateListener(
uint64_t listener_tag,
std::function<bool(Network::ConnectionHandler::ActiveListener&)> listener_update_func,
std::function<void(bool)> completion) PURE;
};
using WorkerPtr = std::unique_ptr<Worker>;
/**
* Factory for creating workers.
*/
class WorkerFactory {
public:
virtual ~WorkerFactory() = default;
/**
* @param overload_manager supplies the server's overload manager.
* @param worker_name supplies the name of the worker, used for per-worker stats.
* @return WorkerPtr a new worker.
*/
virtual WorkerPtr createWorker(OverloadManager& overload_manager,
const std::string& worker_name) PURE;
};
} // namespace Server
} // namespace Envoy