proxygen
ConnectionCounter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cstdint>
19 
20 namespace wangle {
21 
23  public:
24  virtual uint64_t getNumConnections() const = 0;
25 
31  virtual uint64_t getMaxConnections() const = 0;
32 
36  virtual void onConnectionAdded() = 0;
37 
41  virtual void onConnectionRemoved() = 0;
42  virtual ~IConnectionCounter() = default;
43 };
44 
46  public:
47  uint64_t getNumConnections() const override { return numConnections_; }
48  uint64_t getMaxConnections() const override { return maxConnections_; }
49  void setMaxConnections(uint64_t maxConnections) {
50  maxConnections_ = maxConnections;
51  }
52 
53  void onConnectionAdded() override { numConnections_++; }
54  void onConnectionRemoved() override { numConnections_--; }
55  ~SimpleConnectionCounter() override = default;
56 
57  protected:
58  uint64_t maxConnections_{0};
59  uint64_t numConnections_{0};
60 };
61 
62 } // namespace wangle
virtual void onConnectionRemoved()=0
uint64_t getMaxConnections() const override
void setMaxConnections(uint64_t maxConnections)
virtual void onConnectionAdded()=0
virtual uint64_t getMaxConnections() const =0
uint64_t getNumConnections() const override
virtual ~IConnectionCounter()=default
virtual uint64_t getNumConnections() const =0