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  bool
47  isOpen() override
48  {
49  return false;
50  }
51 
52  void
53  close() override
54  {
55  }
56 
57  Status
58  fetch(void const*, std::shared_ptr<NodeObject>*) override
59  {
60  return notFound;
61  }
62 
63  bool
64  canFetchBatch() override
65  {
66  return false;
67  }
68 
70  fetchBatch(std::size_t n, void const* const* keys) override
71  {
72  Throw<std::runtime_error>("pure virtual called");
73  return {};
74  }
75 
76  void
77  store(std::shared_ptr<NodeObject> const& object) override
78  {
79  }
80 
81  void
82  storeBatch(Batch const& batch) override
83  {
84  }
85 
86  void
88  {
89  }
90 
91  int
92  getWriteLoad() override
93  {
94  return 0;
95  }
96 
97  void
98  setDeletePath() override
99  {
100  }
101 
102  void
103  verify() override
104  {
105  }
106 
108  int
109  fdRequired() const override
110  {
111  return 0;
112  }
113 
114 private:
115 };
116 
117 //------------------------------------------------------------------------------
118 
119 class NullFactory : public Factory
120 {
121 public:
123  {
124  Manager::instance().insert(*this);
125  }
126 
127  ~NullFactory() override
128  {
129  Manager::instance().erase(*this);
130  }
131 
133  getName() const override
134  {
135  return "none";
136  }
137 
140  size_t,
141  Section const&,
142  std::size_t,
143  Scheduler&,
144  beast::Journal) override
145  {
146  return std::make_unique<NullBackend>();
147  }
148 };
149 
151 
152 } // namespace NodeStore
153 } // 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:150
ripple::NodeStore::NullBackend::fdRequired
int fdRequired() const override
Returns the number of file descriptors the backend expects to need.
Definition: NullFactory.cpp:109
ripple::NodeStore::Manager::erase
virtual void erase(Factory &factory)=0
Remove a factory.
ripple::NodeStore::NullFactory::createInstance
std::unique_ptr< Backend > createInstance(size_t, Section const &, std::size_t, Scheduler &, beast::Journal) override
Create an instance of this factory's backend.
Definition: NullFactory.cpp:139
ripple::NodeStore::NullBackend::getWriteLoad
int getWriteLoad() override
Estimate the number of write operations pending.
Definition: NullFactory.cpp:92
std::vector
STL class.
ripple::NodeStore::NullBackend::setDeletePath
void setDeletePath() override
Remove contents on disk upon destruction.
Definition: NullFactory.cpp:98
ripple::NodeStore::NullBackend::fetch
Status fetch(void const *, std::shared_ptr< NodeObject > *) override
Fetch a single object.
Definition: NullFactory.cpp:58
ripple::NodeStore::NullBackend
Definition: NullFactory.cpp:28
ripple::NodeStore::NullFactory::NullFactory
NullFactory()
Definition: NullFactory.cpp:122
std::function
ripple::NodeStore::NullBackend::NullBackend
NullBackend()=default
ripple::NodeStore::NullFactory::~NullFactory
~NullFactory() override
Definition: NullFactory.cpp:127
ripple::NodeStore::NullBackend::close
void close() override
Close the backend.
Definition: NullFactory.cpp:53
ripple::NodeStore::NullBackend::storeBatch
void storeBatch(Batch const &batch) override
Store a group of objects.
Definition: NullFactory.cpp:82
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:64
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:87
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:70
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:61
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:133
ripple::NodeStore::Status
Status
Return codes from Backend operations.
Definition: nodestore/Types.h:44
ripple::NodeStore::NullFactory
Definition: NullFactory.cpp:119
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std::size_t
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:119
std::unique_ptr
STL class.
ripple::NodeStore::NullBackend::verify
void verify() override
Perform consistency checks on database.
Definition: NullFactory.cpp:103
ripple::NodeStore::NullBackend::store
void store(std::shared_ptr< NodeObject > const &object) override
Store a single object.
Definition: NullFactory.cpp:77
ripple::NodeStore::NullBackend::isOpen
bool isOpen() override
Returns true is the database is open.
Definition: NullFactory.cpp:47
ripple::NodeStore::Backend
A backend used for the NodeStore.
Definition: Backend.h:37