OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
server_interface.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
7
8#include <cassert>
9
12 std::shared_ptr<broker::interface> broker,
13 std::shared_ptr<logging::log> log,
14 const cbdc::parsec::config& cfg)
15 : m_broker(std::move(broker)),
16 m_log(std::move(log)),
17 m_cfg(cfg) {
18 m_cleanup_thread = std::thread([&]() {
19 size_t id{};
20 while(m_cleanup_queue.pop(id)) {
21 std::unique_lock l(m_agents_mut);
22 m_agents.erase(id);
23 }
24 });
25 m_retry_thread = std::thread([&]() {
26 size_t id{};
27 while(m_retry_queue.pop(id)) {
28 auto a = [&]() {
29 std::unique_lock l(m_agents_mut);
30 auto it = m_agents.find(id);
31 assert(it != m_agents.end());
32 return it->second;
33 }();
34 if(!a->exec()) {
35 m_log->fatal("Error retrying agent");
36 }
37 }
38 });
39 }
40
42 m_retry_queue.clear();
43 m_retry_thread.join();
44 m_log->trace("Stopped retry thread");
45 m_cleanup_queue.clear();
46 m_cleanup_thread.join();
47 m_log->trace("Stopped runner cleanup thread");
48 {
49 std::unique_lock l(m_agents_mut);
50 m_agents.clear();
51 }
52 m_log->trace("Cleaned up all runners");
53 }
54}
server_interface(std::shared_ptr< broker::interface > broker, std::shared_ptr< logging::log > log, const cbdc::parsec::config &cfg)
Constructor.
virtual ~server_interface()
Stops retrying additional transactions and cleans up the runners.
Configuration parameters for a phase two system.