client-cpp  0.7.0
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 
57 
58  virtual void onTimeout();
59  virtual void onFailure(LogDeliveryErrorCode code);
60 
61  virtual std::size_t getBatchSize() { return batchSize_; }
62  virtual std::size_t getTimeout() { return uploadTimeout_; }
63 
64  void setBatchSize(std::size_t size) { batchSize_ = size; }
65  void setUploadTimeout(std::size_t timeout) { uploadTimeout_ = timeout; }
66  void setRetryPeriod(std::size_t period) { retryReriod_ = period; }
67  void setVolumeThreshold(std::size_t maxVolume) { uploadVolumeThreshold_ = maxVolume; }
68  void setCountThreshold(std::size_t maxCount) { uploadCountThreshold_ = maxCount; }
69 
70 public:
71  static const std::size_t DEFAULT_BATCH_SIZE = 8 * 1024;
75  static const std::size_t DEFAULT_UPLOAD_TIMEOUT = 2 * 60;
78  static const std::size_t DEFAULT_RETRY_PERIOD = 5 * 60;
81  static const std::size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD = 8 * 1024;
84  static const std::size_t DEFAULT_UPLOAD_COUNT_THRESHOLD = 64;
87 private:
88  std::size_t batchSize_ = DEFAULT_BATCH_SIZE;
89 
90  std::size_t uploadTimeout_ = DEFAULT_UPLOAD_TIMEOUT;
91  std::size_t retryReriod_ = DEFAULT_RETRY_PERIOD;
92 
93  std::size_t uploadVolumeThreshold_ = DEFAULT_UPLOAD_VOLUME_THRESHOLD;
94  std::size_t uploadCountThreshold_ = DEFAULT_UPLOAD_COUNT_THRESHOLD;
95 
96  typedef std::chrono::system_clock Clock;
97  std::chrono::time_point<Clock> nextUploadAttemptTS_;
98 
99  IKaaChannelManagerPtr channelManager_;
100 };
101 
102 } /* namespace kaa */
103 
104 #endif /* DEFAULTLOGUPLOADSTRATEGY_HPP_ */
void setRetryPeriod(std::size_t period)
The public interface for the log upload strategy.
DefaultLogUploadStrategy(IKaaChannelManagerPtr manager)
static const std::size_t DEFAULT_UPLOAD_COUNT_THRESHOLD
virtual LogUploadStrategyDecision isUploadNeeded(ILogStorageStatus &status)
Decides whether the log upload is needed.
The default ILogUploadStrategy implementation.
void setCountThreshold(std::size_t maxCount)
virtual void onTimeout()
Callback is used when the log delivery timeout detected.
void setVolumeThreshold(std::size_t maxVolume)
virtual std::size_t getTimeout()
Maximum time to wait the log delivery response.
static const std::size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD
static const std::size_t DEFAULT_RETRY_PERIOD
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...
virtual void onFailure(LogDeliveryErrorCode code)
Callback is used when the log delivery is failed.
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.