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  void
64  store(std::shared_ptr<NodeObject> const& object) override
65  {
66  }
67 
68  void
69  storeBatch(Batch const& batch) override
70  {
71  }
72 
73  void
75  {
76  }
77 
78  int
79  getWriteLoad() override
80  {
81  return 0;
82  }
83 
84  void
85  setDeletePath() override
86  {
87  }
88 
89  void
90  verify() override
91  {
92  }
93 
95  int
96  fdRequired() const override
97  {
98  return 0;
99  }
100 
101 private:
102 };
103 
104 //------------------------------------------------------------------------------
105 
106 class NullFactory : public Factory
107 {
108 public:
110  {
111  Manager::instance().insert(*this);
112  }
113 
114  ~NullFactory() override
115  {
116  Manager::instance().erase(*this);
117  }
118 
120  getName() const override
121  {
122  return "none";
123  }
124 
127  size_t,
128  Section const&,
129  std::size_t,
130  Scheduler&,
131  beast::Journal) override
132  {
133  return std::make_unique<NullBackend>();
134  }
135 };
136 
138 
139 } // namespace NodeStore
140 } // 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:137
ripple::NodeStore::NullBackend::fdRequired
int fdRequired() const override
Returns the number of file descriptors the backend expects to need.
Definition: NullFactory.cpp:96
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:126
ripple::NodeStore::NullBackend::getWriteLoad
int getWriteLoad() override
Estimate the number of write operations pending.
Definition: NullFactory.cpp:79
std::vector< std::shared_ptr< NodeObject > >
ripple::NodeStore::NullBackend::setDeletePath
void setDeletePath() override
Remove contents on disk upon destruction.
Definition: NullFactory.cpp:85
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:109
std::function
ripple::NodeStore::NullBackend::NullBackend
NullBackend()=default
ripple::NodeStore::NullFactory::~NullFactory
~NullFactory() override
Definition: NullFactory.cpp:114
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:69
ripple::NodeStore::notFound
@ notFound
Definition: nodestore/Types.h:46
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:74
ripple::NodeStore::Manager::insert
virtual void insert(Factory &factory)=0
Add a factory.
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:60
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:120
ripple::NodeStore::Status
Status
Return codes from Backend operations.
Definition: nodestore/Types.h:44
ripple::NodeStore::NullFactory
Definition: NullFactory.cpp:106
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:90
ripple::NodeStore::NullBackend::store
void store(std::shared_ptr< NodeObject > const &object) override
Store a single object.
Definition: NullFactory.cpp:64
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