rippled
BatchWriter.h
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 #ifndef RIPPLE_NODESTORE_BATCHWRITER_H_INCLUDED
21 #define RIPPLE_NODESTORE_BATCHWRITER_H_INCLUDED
22 
23 #include <ripple/nodestore/Scheduler.h>
24 #include <ripple/nodestore/Task.h>
25 #include <ripple/nodestore/Types.h>
26 #include <condition_variable>
27 #include <mutex>
28 
29 namespace ripple {
30 namespace NodeStore {
31 
40 class BatchWriter : private Task
41 {
42 public:
44  struct Callback
45  {
46  virtual ~Callback() = default;
47  Callback() = default;
48  Callback(Callback const&) = delete;
49  Callback&
50  operator=(Callback const&) = delete;
51 
52  virtual void
53  writeBatch(Batch const& batch) = 0;
54  };
55 
57  BatchWriter(Callback& callback, Scheduler& scheduler);
58 
63  ~BatchWriter();
64 
70  void
71  store(std::shared_ptr<NodeObject> const& object);
72 
74  int
75  getWriteLoad();
76 
77 private:
78  void
79  performScheduledTask() override;
80  void
81  writeBatch();
82  void
84 
85 private:
88 
96 };
97 
98 } // namespace NodeStore
99 } // namespace ripple
100 
101 #endif
ripple::NodeStore::BatchWriter
Batch-writing assist logic.
Definition: BatchWriter.h:40
std::shared_ptr< NodeObject >
ripple::NodeStore::BatchWriter::writeBatch
void writeBatch()
Definition: BatchWriter.cpp:74
ripple::NodeStore::BatchWriter::performScheduledTask
void performScheduledTask() override
Performs the task.
Definition: BatchWriter.cpp:68
ripple::NodeStore::BatchWriter::mWriteCondition
CondvarType mWriteCondition
Definition: BatchWriter.h:92
ripple::NodeStore::BatchWriter::mWritePending
bool mWritePending
Definition: BatchWriter.h:94
std::vector< std::shared_ptr< NodeObject > >
ripple::NodeStore::BatchWriter::Callback::Callback
Callback()=default
std::recursive_mutex
STL class.
ripple::NodeStore::BatchWriter::waitForWriting
void waitForWriting()
Definition: BatchWriter.cpp:113
std::condition_variable_any
ripple::NodeStore::Task
Derived classes perform scheduled tasks.
Definition: Task.h:27
ripple::NodeStore::BatchWriter::Callback::writeBatch
virtual void writeBatch(Batch const &batch)=0
ripple::NodeStore::BatchWriter::Callback
This callback does the actual writing.
Definition: BatchWriter.h:44
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:60
ripple::NodeStore::BatchWriter::~BatchWriter
~BatchWriter()
Destroy a batch writer.
Definition: BatchWriter.cpp:34
ripple::NodeStore::BatchWriter::mWriteMutex
LockType mWriteMutex
Definition: BatchWriter.h:91
ripple::NodeStore::BatchWriter::Callback::~Callback
virtual ~Callback()=default
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::BatchWriter::getWriteLoad
int getWriteLoad()
Get an estimate of the amount of writing I/O pending.
Definition: BatchWriter.cpp:60
ripple::NodeStore::BatchWriter::mWriteSet
Batch mWriteSet
Definition: BatchWriter.h:95
condition_variable
ripple::NodeStore::BatchWriter::BatchWriter
BatchWriter(Callback &callback, Scheduler &scheduler)
Create a batch writer.
Definition: BatchWriter.cpp:25
ripple::NodeStore::BatchWriter::store
void store(std::shared_ptr< NodeObject > const &object)
Store the object.
Definition: BatchWriter.cpp:40
ripple::NodeStore::BatchWriter::mWriteLoad
int mWriteLoad
Definition: BatchWriter.h:93
ripple::NodeStore::BatchWriter::m_callback
Callback & m_callback
Definition: BatchWriter.h:89
mutex
ripple::NodeStore::BatchWriter::Callback::operator=
Callback & operator=(Callback const &)=delete
ripple::NodeStore::BatchWriter::m_scheduler
Scheduler & m_scheduler
Definition: BatchWriter.h:90