Skip to content

Commit

Permalink
Add timer for batching reports. (envoyproxy#73)
Browse files Browse the repository at this point in the history
* Add periodic timer.

* change timer class.

* rename Reset to Start.
  • Loading branch information
qiwzhang authored Jun 5, 2017
1 parent 9287180 commit 8100db5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions mixerclient/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ cc_library(
"include/attribute.h",
"include/client.h",
"include/options.h",
"include/timer.h",
],
visibility = ["//visibility:public"],
deps = [
Expand Down
4 changes: 4 additions & 0 deletions mixerclient/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "google/protobuf/stubs/status.h"
#include "mixer/v1/service.pb.h"
#include "options.h"
#include "timer.h"

namespace istio {
namespace mixer_client {
Expand Down Expand Up @@ -64,6 +65,9 @@ struct MixerClientOptions {
TransportCheckFunc check_transport;
TransportReportFunc report_transport;
TransportQuotaFunc quota_transport;

// Timer create function.
TimerCreateFunc timer_create_func;
};

class MixerClient {
Expand Down
47 changes: 47 additions & 0 deletions mixerclient/include/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright 2017 Istio Authors. 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 MIXERCLIENT_TIMER_H
#define MIXERCLIENT_TIMER_H

#include <memory>

namespace istio {
namespace mixer_client {

// Represent a timer created by caller's environment.
class Timer {
public:
// Delete the timer, stopping it first if needed.
virtual ~Timer() {}

// Stop a pending timeout without destroying the underlying timer.
virtual void Stop() = 0;

// Start a pending timeout. If a timeout is already pending,
// it will be reset to the new timeout.
virtual void Start(int interval_ms) = 0;
};

// Defines a function to create a timer calling the function
// with desired interval. The returned object can be used to stop
// the timer.
using TimerCreateFunc =
std::function<std::unique_ptr<Timer>(std::function<void()> timer_func)>;

} // namespace mixer_client
} // namespace istio

#endif // MIXERCLIENT_TIMER_H

0 comments on commit 8100db5

Please sign in to comment.