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