Commit b6a6c58e authored by TousakaRin's avatar TousakaRin

Modify the MethodStatus::SetConcurrencyLimiter from the public to be private.

parent 7654d8e0
...@@ -127,6 +127,29 @@ void MethodStatus::Describe( ...@@ -127,6 +127,29 @@ void MethodStatus::Describe(
_nprocessing, options, false); _nprocessing, options, false);
} }
int& MethodStatus::max_concurrency_ref() {
if (NULL == _cl) {
const ConcurrencyLimiter* cl =
ConcurrencyLimiterExtension()->Find("constant");
if (NULL == cl) {
LOG(FATAL) << "Fail to find ConcurrentLimiter by `constant`";
}
ConcurrencyLimiter* cl_copy = cl->New();
if (NULL == cl_copy) {
LOG(FATAL) << "Fail to new ConcurrencyLimiter";
}
_cl = cl_copy;
}
return _cl->MaxConcurrencyRef();
}
void MethodStatus::SetConcurrencyLimiter(ConcurrencyLimiter* cl) {
if (NULL != _cl) {
_cl->Destroy();
}
_cl = cl;
}
ScopedMethodStatus::~ScopedMethodStatus() { ScopedMethodStatus::~ScopedMethodStatus() {
if (_status) { if (_status) {
_status->OnResponded(_c->ErrorCode(), butil::cpuwide_time_us() - _start_parse_us); _status->OnResponded(_c->ErrorCode(), butil::cpuwide_time_us() - _start_parse_us);
......
...@@ -53,6 +53,8 @@ public: ...@@ -53,6 +53,8 @@ public:
// Describe internal vars, used by /status // Describe internal vars, used by /status
void Describe(std::ostream &os, const DescribeOptions&) const; void Describe(std::ostream &os, const DescribeOptions&) const;
// Current maximum concurrency of method.
// Return 0 if the maximum concurrency is not restricted.
int max_concurrency() const { int max_concurrency() const {
if (NULL == _cl) { if (NULL == _cl) {
return 0; return 0;
...@@ -61,36 +63,16 @@ public: ...@@ -61,36 +63,16 @@ public:
} }
} }
// Note: This method is not thread safe and can only be called before
// the server is started.
int& max_concurrency_ref() {
if (NULL == _cl) {
const ConcurrencyLimiter* cl =
ConcurrencyLimiterExtension()->Find("constant");
if (NULL == cl) {
LOG(FATAL) << "Fail to find ConcurrentLimiter by `constant`";
}
ConcurrencyLimiter* cl_copy = cl->New();
if (NULL == cl_copy) {
LOG(FATAL) << "Fail to new ConcurrencyLimiter";
}
_cl = cl_copy;
}
return _cl->MaxConcurrencyRef();
}
void SetConcurrencyLimiter(ConcurrencyLimiter* cl) {
if (NULL != _cl) {
_cl->Destroy();
}
_cl = cl;
}
private: private:
friend class ScopedMethodStatus; friend class ScopedMethodStatus;
friend class Server;
DISALLOW_COPY_AND_ASSIGN(MethodStatus); DISALLOW_COPY_AND_ASSIGN(MethodStatus);
// Note: Following methods are not thread safe and can only be called
// before the server is started.
int& max_concurrency_ref();
void SetConcurrencyLimiter(ConcurrencyLimiter* cl);
ConcurrencyLimiter* _cl; ConcurrencyLimiter* _cl;
bvar::Adder<int64_t> _nerror; bvar::Adder<int64_t> _nerror;
bvar::LatencyRecorder _latency_rec; bvar::LatencyRecorder _latency_rec;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment