forked from lizan/service-control-client-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregator_interface.h
133 lines (105 loc) · 5.06 KB
/
aggregator_interface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Copyright 2016 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef GOOGLE_SERVICE_CONTROL_CLIENT_AGGREGATOR_INTERFACE_H_
#define GOOGLE_SERVICE_CONTROL_CLIENT_AGGREGATOR_INTERFACE_H_
#include <string.h>
#include <memory>
#include <string>
#include "google/api/servicecontrol/v1/service_controller.pb.h"
#include "google/protobuf/stubs/status.h"
#include "include/aggregation_options.h"
namespace google {
namespace service_control_client {
// Aggregate Service_Control Report requests.
// This interface is thread safe.
class ReportAggregator {
public:
// Flush callback can be called when calling any of member functions.
// If the callback function is blocked, the called member function, such as
// Report(), will be blocked too. It is recommended that the callback function
// should be fast and non blocking.
using FlushCallback = std::function<void(
const ::google::api::servicecontrol::v1::ReportRequest&)>;
virtual ~ReportAggregator() {}
// Sets the flush callback function.
// The callback function must be light and fast. If it needs to make
// a remote call, it must be non-blocking call.
// It should NOT call into this object again from this callback.
// It will cause dead-lock.
virtual void SetFlushCallback(FlushCallback callback) = 0;
// Adds a report request to cache
virtual ::google::protobuf::util::Status Report(
const ::google::api::servicecontrol::v1::ReportRequest& request) = 0;
// When the next Flush() should be called.
// Returns in ms from now, or -1 for never
virtual int GetNextFlushInterval() = 0;
// Flushes aggregated requests longer than flush_interval.
// Called at time specified by GetNextFlushInterval().
virtual ::google::protobuf::util::Status Flush() = 0;
// Flushes out aggregated report requests, clears all cache items.
// Usually called at destructor.
virtual ::google::protobuf::util::Status FlushAll() = 0;
protected:
ReportAggregator() {}
};
// Aggregate Service_Control Check requests.
// This interface is thread safe.
class CheckAggregator {
public:
// Flush callback can be called when calling any of member functions.
// If the callback function is blocked, the called member function, such as
// Check(), will be blocked too. It is recommended that the callback function
// should be fast and non blocking.
using FlushCallback = std::function<void(
const ::google::api::servicecontrol::v1::CheckRequest&)>;
virtual ~CheckAggregator() {}
// Sets the flush callback function.
// The callback function must be light and fast. If it needs to make
// a remote call, it must be non-blocking call.
// It should NOT call into this object again from this callback.
// It will cause dead-lock.
virtual void SetFlushCallback(FlushCallback callback) = 0;
// If the check could not be handled by the cache, returns NOT_FOUND,
// caller has to send the request to service control.
// Otherwise, returns OK and cached response.
virtual ::google::protobuf::util::Status Check(
const ::google::api::servicecontrol::v1::CheckRequest& request,
::google::api::servicecontrol::v1::CheckResponse* response) = 0;
// Caches a response from a remote Service Controller Check call.
virtual ::google::protobuf::util::Status CacheResponse(
const ::google::api::servicecontrol::v1::CheckRequest& request,
const ::google::api::servicecontrol::v1::CheckResponse& response) = 0;
// When the next Flush() should be called.
// Returns in ms from now, or -1 for never
virtual int GetNextFlushInterval() = 0;
// Invalidates expired check resposnes.
// Called at time specified by GetNextFlushInterval().
virtual ::google::protobuf::util::Status Flush() = 0;
// Flushes out all cached check responses; clears all cache items.
// Usually called at destructor.
virtual ::google::protobuf::util::Status FlushAll() = 0;
protected:
CheckAggregator() {}
};
// Creates a report aggregator.
std::unique_ptr<ReportAggregator> CreateReportAggregator(
const std::string& service_name, const std::string& service_config_id,
const ReportAggregationOptions& options,
std::shared_ptr<MetricKindMap> metric_kind);
// Creates a check aggregator.
std::unique_ptr<CheckAggregator> CreateCheckAggregator(
const std::string& service_name, const std::string& service_config_id,
const CheckAggregationOptions& options,
std::shared_ptr<MetricKindMap> metric_kind);
} // namespace service_control_client
} // namespace google
#endif // GOOGLE_SERVICE_CONTROL_CLIENT_AGGREGATOR_INTERFACE_H_