File indexing completed on 2026-04-17 08:35:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef _THRIFT_SERVER_TSERVERFRAMEWORK_H_
0021 #define _THRIFT_SERVER_TSERVERFRAMEWORK_H_ 1
0022
0023 #include <memory>
0024 #include <stdint.h>
0025 #include <thrift/TProcessor.h>
0026 #include <thrift/concurrency/Monitor.h>
0027 #include <thrift/server/TConnectedClient.h>
0028 #include <thrift/server/TServer.h>
0029 #include <thrift/transport/TServerTransport.h>
0030 #include <thrift/transport/TTransport.h>
0031
0032 namespace apache {
0033 namespace thrift {
0034 namespace server {
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 class TServerFramework : public TServer {
0049 public:
0050 TServerFramework(
0051 const std::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
0052 const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0053 const std::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
0054 const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory);
0055
0056 TServerFramework(
0057 const std::shared_ptr<apache::thrift::TProcessor>& processor,
0058 const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0059 const std::shared_ptr<apache::thrift::transport::TTransportFactory>& transportFactory,
0060 const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& protocolFactory);
0061
0062 TServerFramework(
0063 const std::shared_ptr<apache::thrift::TProcessorFactory>& processorFactory,
0064 const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0065 const std::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
0066 const std::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
0067 const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
0068 const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory);
0069
0070 TServerFramework(
0071 const std::shared_ptr<apache::thrift::TProcessor>& processor,
0072 const std::shared_ptr<apache::thrift::transport::TServerTransport>& serverTransport,
0073 const std::shared_ptr<apache::thrift::transport::TTransportFactory>& inputTransportFactory,
0074 const std::shared_ptr<apache::thrift::transport::TTransportFactory>& outputTransportFactory,
0075 const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& inputProtocolFactory,
0076 const std::shared_ptr<apache::thrift::protocol::TProtocolFactory>& outputProtocolFactory);
0077
0078 ~TServerFramework() override;
0079
0080
0081
0082
0083
0084
0085
0086
0087 void serve() override;
0088
0089
0090
0091
0092 void stop() override;
0093
0094
0095
0096
0097
0098 virtual int64_t getConcurrentClientLimit() const;
0099
0100
0101
0102
0103
0104 virtual int64_t getConcurrentClientCount() const;
0105
0106
0107
0108
0109
0110 virtual int64_t getConcurrentClientCountHWM() const;
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 virtual void setConcurrentClientLimit(int64_t newLimit);
0123
0124 protected:
0125
0126
0127
0128
0129
0130
0131
0132
0133 virtual void onClientConnected(const std::shared_ptr<TConnectedClient>& pClient) = 0;
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144 virtual void onClientDisconnected(TConnectedClient* pClient) = 0;
0145
0146 private:
0147
0148
0149
0150
0151
0152 void newlyConnectedClient(const std::shared_ptr<TConnectedClient>& pClient);
0153
0154
0155
0156
0157
0158 void disposeConnectedClient(TConnectedClient* pClient);
0159
0160
0161
0162
0163 apache::thrift::concurrency::Monitor mon_;
0164
0165
0166
0167
0168 int64_t clients_;
0169
0170
0171
0172
0173 int64_t hwm_;
0174
0175
0176
0177
0178 int64_t limit_;
0179 };
0180 }
0181 }
0182 }
0183
0184 #endif