rippled
NullFactory.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 <ripple/basics/contract.h>
21 #include <ripple/nodestore/Factory.h>
22 #include <ripple/nodestore/Manager.h>
23 #include <memory>
24 
25 namespace ripple {
26 namespace NodeStore {
27 
28 class NullBackend : public Backend
29 {
30 public:
31  NullBackend() = default;
32 
33  ~NullBackend() = default;
34 
36  getName() override
37  {
38  return std::string();
39  }
40 
41  void
42  open(bool createIfMissing) override
43  {
44  }
45 
46  void
47  close() override
48  {
49  }
50 
51  Status
52  fetch(void const*, std::shared_ptr<NodeObject>*) override
53  {
54  return notFound;
55  }
56 
57  bool
58  canFetchBatch() override
59  {
60  return false;
61  }
62 
64  fetchBatch(std::size_t n, void const* const* keys) override
65  {
66  Throw<std::runtime_error>("pure virtual called");
67  return {};
68  }
69 
70  void
71  store(std::shared_ptr<NodeObject> const& object) override
72  {
73  }
74 
75  void
76  storeBatch(Batch const& batch) override
77  {
78  }
79 
80  void
82  {
83  }
84 
85  int
86  getWriteLoad() override
87  {
88  return 0;
89  }
90 
91  void
92  setDeletePath() override
93  {
94  }
95 
96  void
97  verify() override
98  {
99  }
100 
102  int
103  fdRequired() const override
104  {
105  return 0;
106  }
107 
108 private:
109 };
110 
111 //------------------------------------------------------------------------------
112 
113 class NullFactory : public Factory
114 {
115 public:
117  {
118  Manager::instance().insert(*this);
119  }
120 
121  ~NullFactory() override
122  {
123  Manager::instance().erase(*this);
124  }
125 
127  getName() const override
128  {
129  return "none";
130  }
131 
133  createInstance(size_t, Section const&, Scheduler&, beast::Journal) override
134  {
135  return std::make_unique<NullBackend>();
136  }
137 };
138 
140 
141 } // namespace NodeStore
142 } // namespace ripple
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::NodeStore::Factory
Base class for backend factories.
Definition: Factory.h:32
ripple::NodeStore::NullBackend::open
void open(bool createIfMissing) override
Open the backend.
Definition: NullFactory.cpp:42
std::string
STL class.
std::shared_ptr< NodeObject >
ripple::NodeStore::nullFactory
static NullFactory nullFactory
Definition: NullFactory.cpp:139
ripple::NodeStore::NullBackend::fdRequired
int fdRequired() const override
Returns the number of file descriptors the backend expects to need.
Definition: NullFactory.cpp:103
ripple::NodeStore::Manager::erase
virtual void erase(Factory &factory)=0
Remove a factory.
ripple::NodeStore::NullBackend::getWriteLoad
int getWriteLoad() override
Estimate the number of write operations pending.
Definition: NullFactory.cpp:86
std::vector
STL class.
ripple::NodeStore::NullBackend::setDeletePath
void setDeletePath() override
Remove contents on disk upon destruction.
Definition: NullFactory.cpp:92
ripple::NodeStore::NullBackend::fetch
Status fetch(void const *, std::shared_ptr< NodeObject > *) override
Fetch a single object.
Definition: NullFactory.cpp:52
ripple::NodeStore::NullBackend
Definition: NullFactory.cpp:28
ripple::NodeStore::NullFactory::NullFactory
NullFactory()
Definition: NullFactory.cpp:116
std::function
ripple::NodeStore::NullBackend::NullBackend
NullBackend()=default
ripple::NodeStore::NullFactory::~NullFactory
~NullFactory() override
Definition: NullFactory.cpp:121
ripple::NodeStore::NullBackend::close
void close() override
Close the backend.
Definition: NullFactory.cpp:47
ripple::NodeStore::NullBackend::storeBatch
void storeBatch(Batch const &batch) override
Store a group of objects.
Definition: NullFactory.cpp:76
ripple::NodeStore::notFound
@ notFound
Definition: nodestore/Types.h:46
ripple::NodeStore::NullBackend::canFetchBatch
bool canFetchBatch() override
Return true if batch fetches are optimized.
Definition: NullFactory.cpp:58
ripple::NodeStore::NullBackend::for_each
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
Definition: NullFactory.cpp:81
ripple::NodeStore::Manager::insert
virtual void insert(Factory &factory)=0
Add a factory.
ripple::NodeStore::NullBackend::fetchBatch
std::vector< std::shared_ptr< NodeObject > > fetchBatch(std::size_t n, void const *const *keys) override
Fetch a batch synchronously.
Definition: NullFactory.cpp:64
ripple::NodeStore::NullBackend::~NullBackend
~NullBackend()=default
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:57
memory
ripple::NodeStore::NullBackend::getName
std::string getName() override
Get the human-readable name of this backend.
Definition: NullFactory.cpp:36
ripple::NodeStore::NullFactory::getName
std::string getName() const override
Retrieve the name of this factory.
Definition: NullFactory.cpp:127
ripple::NodeStore::Status
Status
Return codes from Backend operations.
Definition: nodestore/Types.h:44
ripple::NodeStore::NullFactory
Definition: NullFactory.cpp:113
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::size_t
ripple::NodeStore::NullFactory::createInstance
std::unique_ptr< Backend > createInstance(size_t, Section const &, Scheduler &, beast::Journal) override
Create an instance of this factory's backend.
Definition: NullFactory.cpp:133
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:117
std::unique_ptr
STL class.
ripple::NodeStore::NullBackend::verify
void verify() override
Perform consistency checks on database.
Definition: NullFactory.cpp:97
ripple::NodeStore::NullBackend::store
void store(std::shared_ptr< NodeObject > const &object) override
Store a single object.
Definition: NullFactory.cpp:71
ripple::NodeStore::Backend
A backend used for the NodeStore.
Definition: Backend.h:37