rippled
Loading...
Searching...
No Matches
ManagerImp.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/nodestore/detail/DatabaseNodeImp.h>
21#include <xrpld/nodestore/detail/ManagerImp.h>
22
23#include <boost/algorithm/string/predicate.hpp>
24
25namespace ripple {
26
27namespace NodeStore {
28
29ManagerImp&
31{
32 static ManagerImp _;
33 return _;
34}
35
36void
38{
39 Throw<std::runtime_error>(
40 "Your rippled.cfg is missing a [node_db] entry, "
41 "please see the rippled-example.cfg file!");
42}
43
46 Section const& parameters,
48 Scheduler& scheduler,
49 beast::Journal journal)
50{
51 std::string const type{get(parameters, "type")};
52 if (type.empty())
54
55 auto factory{find(type)};
56 if (!factory)
57 {
59 }
60
61 return factory->createInstance(
62 NodeObject::keyBytes, parameters, burstSize, scheduler, journal);
63}
64
68 Scheduler& scheduler,
69 int readThreads,
70 Section const& config,
71 beast::Journal journal)
72{
73 auto backend{make_Backend(config, burstSize, scheduler, journal)};
74 backend->open();
76 scheduler, readThreads, std::move(backend), config, journal);
77}
78
79void
81{
83 list_.push_back(&factory);
84}
85
86void
88{
90 auto const iter =
91 std::find_if(list_.begin(), list_.end(), [&factory](Factory* other) {
92 return other == &factory;
93 });
94 XRPL_ASSERT(
95 iter != list_.end(),
96 "ripple::NodeStore::ManagerImp::erase : valid input");
97 list_.erase(iter);
98}
99
100Factory*
102{
104 auto const iter =
105 std::find_if(list_.begin(), list_.end(), [&name](Factory* other) {
106 return boost::iequals(name, other->getName());
107 });
108 if (iter == list_.end())
109 return nullptr;
110 return *iter;
111}
112
113//------------------------------------------------------------------------------
114
115Manager&
117{
118 return ManagerImp::instance();
119}
120
121} // namespace NodeStore
122} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:60
static constexpr std::size_t keyBytes
Definition NodeObject.h:52
Base class for backend factories.
Definition Factory.h:37
Factory * find(std::string const &name) override
Return a pointer to the matching factory if it exists.
std::vector< Factory * > list_
Definition ManagerImp.h:33
std::unique_ptr< Database > make_Database(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal) override
Construct a NodeStore database.
static ManagerImp & instance()
void insert(Factory &factory) override
Add a factory.
std::unique_ptr< Backend > make_Backend(Section const &parameters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal) override
Create a backend.
void erase(Factory &factory) override
Remove a factory.
Singleton for managing NodeStore factories and back ends.
Definition Manager.h:32
static Manager & instance()
Returns the instance of the manager singleton.
Scheduling for asynchronous backend activity.
Holds a collection of configuration values.
Definition BasicConfig.h:45
T find_if(T... args)
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.