BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
ExporterQueue.h
1 #pragma once
2 
3 #include <queue>
4 
5 #include <Poco/AtomicCounter.h>
6 #include <Poco/Mutex.h>
7 #include <Poco/SharedPtr.h>
8 
9 #include "core/Exporter.h"
10 #include "model/SensorData.h"
11 #include "util/Loggable.h"
12 #include "util/FailDetector.h"
13 
14 namespace BeeeOn {
15 
16 class ExporterQueue : protected Loggable {
17 public:
18  typedef Poco::SharedPtr<ExporterQueue> Ptr;
19 
20  const static int UNLIMITED_BATCH_SIZE = 0;
21  const static int UNLIMITED_CAPACITY = 0;
22  const static int UNLIMITED_THRESHOLD = FailDetector::TRESHOLD_UNLIMITED;
23 
30  Poco::SharedPtr<Exporter> exporter,
31  int batchSize,
32  int capacity,
33  int treshold);
34 
35  ~ExporterQueue();
36 
37  void enqueue(const SensorData &sensorData);
38  unsigned int exportBatch();
39 
40  unsigned int sent() const;
41  unsigned int dropped() const;
42 
49  bool canExport(const Poco::Timespan &deadTimeout) const;
50 
51  bool working() const;
52 
53 private:
58  bool deadTooLong(const Poco::Timespan deadTimeout) const;
59 
60  bool isEmpty() const;
61 
62  SensorData &front();
63  void pop();
64 
65 private:
66  mutable Poco::FastMutex m_queueMutex;
67 
68  Poco::SharedPtr<Exporter> m_exporter;
69 
70  Poco::AtomicCounter m_dropped;
71  Poco::AtomicCounter m_sent;
72 
73  FailDetector m_failDetector;
74  std::queue<SensorData> m_queue;
75  unsigned int m_capacity;
76  unsigned int m_batchSize;
77 };
78 
79 }
Definition: FailDetector.h:8
Definition: SensorData.h:20
Definition: ExporterQueue.h:16
bool canExport(const Poco::Timespan &deadTimeout) const
Definition: ExporterQueue.cpp:82
ExporterQueue(Poco::SharedPtr< Exporter > exporter, int batchSize, int capacity, int treshold)
Definition: ExporterQueue.cpp:11
Definition: Loggable.h:19