client-cpp  0.9.0
DefaultLogUploadStrategy.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEFAULTLOGUPLOADSTRATEGY_HPP_
18 #define DEFAULTLOGUPLOADSTRATEGY_HPP_
19 
20 #include <chrono>
21 #include <cstdint>
22 
26 
27 namespace kaa {
28 
54 public:
56 
58 
59  virtual void onTimeout(ILogFailoverCommand& controller);
60  virtual void onFailure(ILogFailoverCommand& controller, LogDeliveryErrorCode code);
61 
62  virtual std::size_t getTimeout() { return uploadTimeout_; }
63  void setUploadTimeout(std::size_t timeout) { uploadTimeout_ = timeout; }
64 
65  virtual std::size_t getTimeoutCheckPeriod() { return timeoutCheckPeriod_; }
66  void setTimeoutCheckPeriod(std::size_t period) { timeoutCheckPeriod_ = period; }
67 
68  virtual std::size_t getLogUploadCheckPeriod() { return logUploadCheckReriod_; };
69  void setLogUploadCheckPeriod(std::size_t period) { logUploadCheckReriod_ = period; }
70 
71  virtual std::size_t getMaxParallelUploads() { return maxParallelUploads_; }
72  void setMaxParallelUploads(std::size_t count) { maxParallelUploads_ = count; }
73 
74  std::size_t getRetryPeriod() { return retryReriod_; }
75  void setRetryPeriod(std::size_t period) { retryReriod_ = period; }
76 
77  std::size_t getVolumeThreshold() const { return uploadVolumeThreshold_; }
78  void setVolumeThreshold(std::size_t maxVolume) { uploadVolumeThreshold_ = maxVolume; }
79 
80  std::size_t getCountThreshold() const { return uploadCountThreshold_; }
81  void setCountThreshold(std::size_t maxCount) { uploadCountThreshold_ = maxCount; }
82 
83 public:
84  static const std::size_t DEFAULT_UPLOAD_TIMEOUT = 2 * 60;
87  static const std::size_t DEFAULT_TIMEOUT_CHECK_PERIOD = 10;
88 
89  static const std::size_t DEFAULT_LOG_UPLOAD_CHECK_PERIOD = 30;
90 
91  static const std::size_t DEFAULT_RETRY_PERIOD = 5 * 60;
94  static const std::size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD = 8 * 1024;
97  static const std::size_t DEFAULT_UPLOAD_COUNT_THRESHOLD = 64;
100  static const std::size_t DEFAULT_MAX_PARALLEL_UPLOADS = INT32_MAX;
103 protected:
106 
108 
110 
113 
115 
117 
118 private:
119  typedef std::chrono::system_clock Clock;
120  std::chrono::time_point<Clock> nextUploadAttemptTS_;
121 };
122 
123 } /* namespace kaa */
124 
125 #endif /* DEFAULTLOGUPLOADSTRATEGY_HPP_ */
void setRetryPeriod(std::size_t period)
The public interface for the log upload strategy.
static const std::size_t DEFAULT_LOG_UPLOAD_CHECK_PERIOD
virtual std::size_t getMaxParallelUploads()
Max amount of log batches allowed to be uploaded parallel.
virtual std::size_t getLogUploadCheckPeriod()
void setMaxParallelUploads(std::size_t count)
static const std::size_t DEFAULT_UPLOAD_COUNT_THRESHOLD
DefaultLogUploadStrategy(IKaaClientContext &context)
virtual LogUploadStrategyDecision isUploadNeeded(ILogStorageStatus &status)
Decides whether the log upload is needed.
void setTimeoutCheckPeriod(std::size_t period)
void setLogUploadCheckPeriod(std::size_t period)
The default ILogUploadStrategy implementation.
void setCountThreshold(std::size_t maxCount)
static const std::size_t DEFAULT_TIMEOUT_CHECK_PERIOD
void setVolumeThreshold(std::size_t maxVolume)
virtual std::size_t getTimeout()
Maximum time to wait the log delivery response.
virtual void onFailure(ILogFailoverCommand &controller, LogDeliveryErrorCode code)
Callback is used when the log delivery is failed.
static const std::size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD
static const std::size_t DEFAULT_RETRY_PERIOD
static const std::size_t DEFAULT_MAX_PARALLEL_UPLOADS
void setUploadTimeout(std::size_t timeout)
LogUploadStrategyDecision
Log upload decisions.
static const std::size_t DEFAULT_UPLOAD_TIMEOUT
The public interface to represent the current log storage state.
virtual void onTimeout(ILogFailoverCommand &controller)
Callback is used when the log delivery timeout detected.