client-cpp  0.7.4
DefaultLogUploadStrategy.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2015 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 
25 
26 namespace kaa {
27 
53 public:
55 
56  virtual void onTimeout(ILogFailoverCommand& controller);
57  virtual void onFailure(ILogFailoverCommand& controller, LogDeliveryErrorCode code);
58 
59  virtual std::size_t getBatchSize() { return batchSize_; }
60  void setBatchSize(std::size_t size) { batchSize_ = size; }
61 
62  virtual std::size_t getRecordsBatchCount() { return recordsBatchCount_; }
63  void setRecordsBatchCount(std::size_t count) { recordsBatchCount_ = count; }
64 
65  virtual std::size_t getTimeout() { return uploadTimeout_; }
66  void setUploadTimeout(std::size_t timeout) { uploadTimeout_ = timeout; }
67 
68  virtual std::size_t getTimeoutCheckPeriod() { return timeoutCheckPeriod_; }
69  void setTimeoutCheckPeriod(std::size_t period) { timeoutCheckPeriod_ = period; }
70 
71  virtual std::size_t getLogUploadCheckPeriod() { return logUploadCheckReriod_; };
72  void setLogUploadCheckPeriod(std::size_t period) { logUploadCheckReriod_ = period; }
73 
74  virtual std::size_t getMaxParallelUploads() { return maxParallelUploads_; }
75  void setMaxParallelUploads(std::size_t count) { maxParallelUploads_ = count; }
76 
77  std::size_t getRetryPeriod() { return retryReriod_; }
78  void setRetryPeriod(std::size_t period) { retryReriod_ = period; }
79 
80  std::size_t getVolumeThreshold() const { return uploadVolumeThreshold_; }
81  void setVolumeThreshold(std::size_t maxVolume) { uploadVolumeThreshold_ = maxVolume; }
82 
83  std::size_t getCountThreshold() const { return uploadCountThreshold_; }
84  void setCountThreshold(std::size_t maxCount) { uploadCountThreshold_ = maxCount; }
85 
86 public:
87  static const std::size_t DEFAULT_BATCH_SIZE = 8 * 1024;
91  static const std::size_t DEFAULT_RECORDS_BATCH_COUNT = 256;
92 
93  static const std::size_t DEFAULT_UPLOAD_TIMEOUT = 2 * 60;
96  static const std::size_t DEFAULT_TIMEOUT_CHECK_PERIOD = 10;
97 
98  static const std::size_t DEFAULT_LOG_UPLOAD_CHECK_PERIOD = 30;
99 
100  static const std::size_t DEFAULT_RETRY_PERIOD = 5 * 60;
103  static const std::size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD = 8 * 1024;
106  static const std::size_t DEFAULT_UPLOAD_COUNT_THRESHOLD = 64;
109  static const std::size_t DEFAULT_MAX_PARALLEL_UPLOADS = INT32_MAX;
112 protected:
114 
116 
119 
121 
123 
126 
128 
129 private:
130  typedef std::chrono::system_clock Clock;
131  std::chrono::time_point<Clock> nextUploadAttemptTS_;
132 };
133 
134 } /* namespace kaa */
135 
136 #endif /* DEFAULTLOGUPLOADSTRATEGY_HPP_ */
void setRetryPeriod(std::size_t period)
The public interface for the log upload strategy.
static const std::size_t DEFAULT_RECORDS_BATCH_COUNT
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
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
static const std::size_t DEFAULT_BATCH_SIZE
virtual std::size_t getBatchSize()
Retrieves the maximum size of the report pack that will be delivered in the single request to the Ope...
void setUploadTimeout(std::size_t timeout)
LogUploadStrategyDecision
Log upload decisions.
static const std::size_t DEFAULT_UPLOAD_TIMEOUT
void setRecordsBatchCount(std::size_t count)
The public interface to represent the current log storage state.
virtual void onTimeout(ILogFailoverCommand &controller)
Callback is used when the log delivery timeout detected.