/proc/self/cwd/source/extensions/filters/network/dubbo_proxy/conn_manager.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "envoy/common/time.h" |
4 | | #include "envoy/extensions/filters/network/dubbo_proxy/v3/dubbo_proxy.pb.h" |
5 | | #include "envoy/network/connection.h" |
6 | | #include "envoy/network/filter.h" |
7 | | #include "envoy/stats/scope.h" |
8 | | #include "envoy/stats/stats.h" |
9 | | #include "envoy/stats/stats_macros.h" |
10 | | #include "envoy/stats/timespan.h" |
11 | | |
12 | | #include "source/common/common/logger.h" |
13 | | #include "source/extensions/filters/network/dubbo_proxy/active_message.h" |
14 | | #include "source/extensions/filters/network/dubbo_proxy/decoder.h" |
15 | | #include "source/extensions/filters/network/dubbo_proxy/decoder_event_handler.h" |
16 | | #include "source/extensions/filters/network/dubbo_proxy/filters/filter.h" |
17 | | #include "source/extensions/filters/network/dubbo_proxy/protocol.h" |
18 | | #include "source/extensions/filters/network/dubbo_proxy/serializer.h" |
19 | | #include "source/extensions/filters/network/dubbo_proxy/stats.h" |
20 | | |
21 | | namespace Envoy { |
22 | | namespace Extensions { |
23 | | namespace NetworkFilters { |
24 | | namespace DubboProxy { |
25 | | |
26 | | /** |
27 | | * Config is a configuration interface for ConnectionManager. |
28 | | */ |
29 | | class Config { |
30 | | public: |
31 | 0 | virtual ~Config() = default; |
32 | | |
33 | | virtual DubboFilters::FilterChainFactory& filterFactory() PURE; |
34 | | virtual DubboFilterStats& stats() PURE; |
35 | | virtual ProtocolPtr createProtocol() PURE; |
36 | | virtual Router::Config& routerConfig() PURE; |
37 | | }; |
38 | | |
39 | | // class ActiveMessagePtr; |
40 | | class ConnectionManager : public Network::ReadFilter, |
41 | | public Network::ConnectionCallbacks, |
42 | | public RequestDecoderCallbacks, |
43 | | Logger::Loggable<Logger::Id::dubbo> { |
44 | | public: |
45 | | using ConfigProtocolType = envoy::extensions::filters::network::dubbo_proxy::v3::ProtocolType; |
46 | | using ConfigSerializationType = |
47 | | envoy::extensions::filters::network::dubbo_proxy::v3::SerializationType; |
48 | | |
49 | | ConnectionManager(Config& config, Random::RandomGenerator& random_generator, |
50 | | TimeSource& time_system); |
51 | 0 | ~ConnectionManager() override = default; |
52 | | |
53 | | // Network::ReadFilter |
54 | | Network::FilterStatus onData(Buffer::Instance& data, bool end_stream) override; |
55 | | Network::FilterStatus onNewConnection() override; |
56 | | void initializeReadFilterCallbacks(Network::ReadFilterCallbacks&) override; |
57 | | |
58 | | // Network::ConnectionCallbacks |
59 | | void onEvent(Network::ConnectionEvent) override; |
60 | | void onAboveWriteBufferHighWatermark() override; |
61 | | void onBelowWriteBufferLowWatermark() override; |
62 | | |
63 | | // RequestDecoderCallbacks |
64 | | StreamHandler& newStream() override; |
65 | | void onHeartbeat(MessageMetadataSharedPtr metadata) override; |
66 | | |
67 | 0 | DubboFilterStats& stats() const { return stats_; } |
68 | 0 | Network::Connection& connection() const { return read_callbacks_->connection(); } |
69 | 0 | TimeSource& timeSystem() const { return time_system_; } |
70 | 0 | Random::RandomGenerator& randomGenerator() const { return random_generator_; } |
71 | 0 | Config& config() const { return config_; } |
72 | 0 | SerializationType downstreamSerializationType() const { return protocol_->serializer()->type(); } |
73 | 0 | ProtocolType downstreamProtocolType() const { return protocol_->type(); } |
74 | | |
75 | | void deferredMessage(ActiveMessage& message); |
76 | | void sendLocalReply(MessageMetadata& metadata, const DubboFilters::DirectResponse& response, |
77 | | bool end_stream); |
78 | | |
79 | | // This function is for testing only. |
80 | 0 | std::list<ActiveMessagePtr>& getActiveMessagesForTest() { return active_message_list_; } |
81 | | |
82 | | private: |
83 | | void dispatch(); |
84 | | void resetAllMessages(bool local_reset); |
85 | | |
86 | | Buffer::OwnedImpl request_buffer_; |
87 | | std::list<ActiveMessagePtr> active_message_list_; |
88 | | |
89 | | Config& config_; |
90 | | TimeSource& time_system_; |
91 | | DubboFilterStats& stats_; |
92 | | Random::RandomGenerator& random_generator_; |
93 | | |
94 | | SerializerPtr serializer_; |
95 | | ProtocolPtr protocol_; |
96 | | RequestDecoderPtr decoder_; |
97 | | Network::ReadFilterCallbacks* read_callbacks_{}; |
98 | | }; |
99 | | |
100 | | } // namespace DubboProxy |
101 | | } // namespace NetworkFilters |
102 | | } // namespace Extensions |
103 | | } // namespace Envoy |