The Sparta Modeling Framework
Loading...
Searching...
No Matches
ArchiveDispatcher.hpp
1// <ArchiveDispatcher> -*- C++ -*-
2
3#pragma once
4
5#include "sparta/statistics/dispatch/archives/ArchiveSource.hpp"
6#include "sparta/statistics/dispatch/archives/ArchiveSink.hpp"
7
8namespace sparta {
9namespace statistics {
10
16{
17public:
18 virtual ~ArchiveDispatcher() {}
19
20 void setStatisticsSource(std::unique_ptr<ArchiveSource> source) {
21 source_ = std::move(source);
22 }
23
24 void addStatisticsSink(std::unique_ptr<ArchiveSink> sink) {
25 sinks_.emplace_back(sink.release());
26 }
27
28 const std::vector<std::unique_ptr<ArchiveSink>> & getSinks() const {
29 return sinks_;
30 }
31
32 //Take a reading from the (one, and only one) data source, and
33 //send those data values out to all of the registered sinks
34 void dispatch() {
35 const std::vector<double> & values = source_->readFromSource();
36 for (auto & sink : sinks_) {
37 sink->sendToSink(values);
38 }
39 }
40
41 //Force all sinks to flush their data. Sinks may use internal
42 //data buffers, asynchronous operations, etc. to boost performance
43 //of their own sink implementation. Force a synchronous flush with
44 //a call to this method.
45 void flush() {
46 for (auto & sink : sinks_) {
47 sink->flush();
48 }
49 }
50
51protected:
52 static const std::string & getSimulationTimeStamp_() {
53 return simulation_time_stamp_;
54 }
55
56private:
57 std::unique_ptr<ArchiveSource> source_;
58 std::vector<std::unique_ptr<ArchiveSink>> sinks_;
59 static std::string simulation_time_stamp_;
60};
61
62} // namespace statistics
63} // namespace sparta
64
This class holds exactly one generic ArchiveSource, and any number of generic ArchiveSink's.
Macros for handling exponential backoff.