CCF
Loading...
Searching...
No Matches
indexer_interface.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
7#include "ccf/pal/locking.h"
8
9#include <map>
10#include <memory>
11#include <set>
12
14{
15 // This base class simply manages a collection of indexing strategies. The
16 // implementation will pass each committed transaction in-order to each
17 // installed strategy. Applications should install strategies at
18 // construction, and then retrieve those strategies and query them for indexed
19 // results during endpoint execution.
21 {
22 protected:
24 std::set<StrategyPtr> strategies;
25
26 public:
27 virtual ~IndexingStrategies() = default;
28
29 static char const* get_subsystem_name()
30 {
31 return "IndexingStrategies";
32 }
33
34 bool install_strategy(const StrategyPtr& strategy)
35 {
36 if (strategy == nullptr)
37 {
38 throw std::logic_error("Tried to install null strategy");
39 }
40
41 std::lock_guard<ccf::pal::Mutex> guard(lock);
42 return strategies.insert(strategy).second;
43 }
44
45 void uninstall_strategy(const StrategyPtr& strategy)
46 {
47 std::lock_guard<ccf::pal::Mutex> guard(lock);
48 if (strategy == nullptr || strategies.find(strategy) == strategies.end())
49 {
50 throw std::logic_error("Strategy doesn't exist");
51 }
52
53 strategies.erase(strategy);
54 }
55
56 nlohmann::json describe()
57 {
58 std::lock_guard<ccf::pal::Mutex> guard(lock);
59 auto j = nlohmann::json::array();
60
61 for (const auto& strategy : strategies)
62 {
63 j.push_back(strategy->describe());
64 }
65
66 return j;
67 }
68 };
69}
Definition node_subsystem_interface.h:8
Definition indexer_interface.h:21
nlohmann::json describe()
Definition indexer_interface.h:56
virtual ~IndexingStrategies()=default
std::set< StrategyPtr > strategies
Definition indexer_interface.h:24
static char const * get_subsystem_name()
Definition indexer_interface.h:29
void uninstall_strategy(const StrategyPtr &strategy)
Definition indexer_interface.h:45
bool install_strategy(const StrategyPtr &strategy)
Definition indexer_interface.h:34
ccf::pal::Mutex lock
Definition indexer_interface.h:23
Definition indexer_interface.h:14
std::shared_ptr< Strategy > StrategyPtr
Definition strategy.h:66
std::mutex Mutex
Definition locking.h:12