client-cpp  0.8.1
RecordCountWithTimeLimitLogUploadStrategy.hpp
Go to the documentation of this file.
1 
18 #ifndef RECORDCOUNTWITHTIMELIMITLOGUPLOADSTRATEGY_HPP_
19 #define RECORDCOUNTWITHTIMELIMITLOGUPLOADSTRATEGY_HPP_
20 
21 #include <cstdlib>
22 #include <chrono>
23 
24 #include "kaa/logging/Log.hpp"
27 
28 namespace kaa {
29 
31 public:
32  RecordCountWithTimeLimitLogUploadStrategy(std::size_t countThreshold, std::size_t logUploadCheckReriod, IKaaClientContext &context)
33  : DefaultLogUploadStrategy(context), lastUploadTime_(Clock::now())
34  {
35  setCountThreshold(countThreshold);
36  setLogUploadCheckPeriod(logUploadCheckReriod);
37  }
38 
40  {
41  auto now = Clock::now();
42  auto currentRecordCount = status.getRecordsCount();
43 
44  if ((currentRecordCount >= uploadCountThreshold_) || (now >= (lastUploadTime_ + std::chrono::seconds(logUploadCheckReriod_)))) {
45  KAA_LOG_INFO(boost::format("Need to upload logs - current count: %llu, threshold: %llu, lastUploadedTime: %llu, timeLimit: %llu sec")
46  % currentRecordCount % uploadCountThreshold_ % lastUploadTime_.time_since_epoch().count() % logUploadCheckReriod_);
47  lastUploadTime_ = now;
49  }
50 
52  }
53 
54 private:
55  typedef std::chrono::system_clock Clock;
56  std::chrono::time_point<Clock> lastUploadTime_;
57 };
58 
59 }
60 
61 #endif /* RECORDCOUNTWITHTIMELIMITLOGUPLOADSTRATEGY_HPP_ */
void setLogUploadCheckPeriod(std::size_t period)
The default ILogUploadStrategy implementation.
void setCountThreshold(std::size_t maxCount)
#define KAA_LOG_INFO(message)
Definition: Log.hpp:64
RecordCountWithTimeLimitLogUploadStrategy(std::size_t countThreshold, std::size_t logUploadCheckReriod, IKaaClientContext &context)
virtual LogUploadStrategyDecision isUploadNeeded(ILogStorageStatus &status) override
Decides whether the log upload is needed.
LogUploadStrategyDecision
Log upload decisions.
virtual std::size_t getRecordsCount()=0
Returns the number of collected logs.
The public interface to represent the current log storage state.