1
#pragma once
2

            
3
#include <chrono>
4
#include <functional>
5

            
6
#include "envoy/common/callback.h"
7
#include "envoy/common/pure.h"
8

            
9
#include "absl/base/attributes.h"
10
#include "absl/status/status.h"
11

            
12
namespace Envoy {
13
namespace Network {
14

            
15
enum class DrainDirection {
16
  /**
17
   * Not draining yet. Default value, should not be externally set.
18
   */
19
  None = 0,
20

            
21
  /**
22
   * Drain inbound connections only.
23
   */
24
  InboundOnly,
25

            
26
  /**
27
   * Drain both inbound and outbound connections.
28
   */
29
  All,
30
};
31

            
32
class DrainDecision {
33
public:
34
  using DrainCloseCb = std::function<absl::Status(std::chrono::milliseconds)>;
35

            
36
90995
  virtual ~DrainDecision() = default;
37

            
38
  /**
39
   * @return TRUE if a connection should be drained and closed. It is up to individual network
40
   *         filters to determine when this should be called for the least impact possible.
41
   * @param direction supplies the direction for which the caller is checking drain close.
42
   */
43
  virtual bool drainClose(DrainDirection scope) const PURE;
44

            
45
  /**
46
   * @brief Register a callback to be called proactively when a drain decision enters into a
47
   *        'close' state.
48
   *        NOTE: this API is used in prorietary builds of Envoy and can not be decommissioned.
49
   *        TODO(yanavlasov): cleanup unused parts of this change without removing this API.
50
   *
51
   * @param cb Callback to be called once drain decision enters close state
52
   * @return handle to remove callback
53
   */
54
  ABSL_MUST_USE_RESULT
55
  virtual Common::CallbackHandlePtr addOnDrainCloseCb(DrainDirection scope,
56
                                                      DrainCloseCb cb) const PURE;
57
};
58

            
59
} // namespace Network
60
} // namespace Envoy