Line data Source code
1 : #ifndef __AGENT_PKT_FLOW_TOKEN_H__ 2 : #define __AGENT_PKT_FLOW_TOKEN_H__ 3 : 4 : #include <memory> 5 : #include <atomic> 6 : #include <base/util.h> 7 : 8 : class Token; 9 : class TokenPool; 10 : class FlowEntry; 11 : class Proto; 12 : 13 : typedef boost::shared_ptr<Token> TokenPtr; 14 : 15 : class Token { 16 : public: 17 : Token(TokenPool *pool); 18 : virtual ~Token(); 19 : 20 : protected: 21 : TokenPool *pool_; 22 : DISALLOW_COPY_AND_ASSIGN(Token); 23 : }; 24 : 25 : class TokenPool { 26 : public: 27 : TokenPool(const std::string &name, Proto *proto, int count); 28 : virtual ~TokenPool(); 29 : 30 : virtual TokenPtr GetToken(); 31 0 : int token_count() const { return token_count_; } 32 : bool TokenCheck() const; 33 0 : uint64_t failures() const { return failures_; } 34 0 : void IncrementRestarts() { restarts_++; } 35 0 : uint64_t restarts() const { return restarts_; } 36 : protected: 37 : friend class Token; 38 : 39 : // Token destructor invokes this 40 : void FreeToken(); 41 : 42 : std::string name_; 43 : int max_tokens_; 44 : int min_tokens_; 45 : int low_water_mark_; 46 : std::atomic<int> token_count_; 47 : mutable uint64_t failures_; 48 : uint64_t restarts_; 49 : Proto *proto_; 50 : DISALLOW_COPY_AND_ASSIGN(TokenPool); 51 : }; 52 : 53 : class FlowTokenPool : public TokenPool { 54 : public: 55 4 : FlowTokenPool(const std::string &name, Proto *proto, int count): 56 4 : TokenPool(name, proto, count) {} 57 4 : virtual ~FlowTokenPool() {} 58 : TokenPtr GetToken(FlowEntry *entry); 59 : }; 60 : 61 : class FlowToken : public Token { 62 : public: 63 144 : FlowToken(TokenPool *pool, FlowEntry *entry): 64 144 : Token(pool), flow_entry_(entry) {} 65 288 : virtual ~FlowToken() {} 66 : private: 67 : FlowEntry *flow_entry_; 68 : }; 69 : #endif // __AGENT_PKT_FLOW_TOKEN_H__