CatapultServer  v0.5.0.1 (Elephant)
FileQueue.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "BufferedFileStream.h"
23 #include "IndexFile.h"
24 #include "catapult/functions.h"
25 #include <boost/filesystem/path.hpp>
26 
27 namespace catapult { namespace io {
28 
31  class FileQueueWriter final : public OutputStream {
32  public:
34  explicit FileQueueWriter(const std::string& directory);
35 
37  FileQueueWriter(const std::string& directory, const std::string& indexFilename);
38 
39  public:
40  void write(const RawBuffer& buffer) override;
41  void flush() override;
42 
43  private:
44  boost::filesystem::path m_directory;
46  uint64_t m_indexValue;
47  std::unique_ptr<BufferedOutputFileStream> m_pOutputStream;
48  };
49 
51  class FileQueueReader final {
52  public:
54  explicit FileQueueReader(const std::string& directory);
55 
58  FileQueueReader(const std::string& directory, const std::string& readerIndexFilename, const std::string& writerIndexFilename);
59 
60  public:
62  size_t pending() const;
63 
64  public:
66  bool tryReadNextMessage(const consumer<std::vector<uint8_t>>& consumer);
67 
69  void skip(uint32_t count);
70 
71  private:
72  bool process(const consumer<const std::string&>& processFilename);
73 
74  private:
75  boost::filesystem::path m_directory;
78  };
79 }}
catapult::io::IndexFile::get
uint64_t get() const
Gets the index value.
Definition: IndexFile.cpp:36
catapult::io::FileQueueReader::m_writerIndexFile
IndexFile m_writerIndexFile
Definition: FileQueue.h:77
exceptions.h
FileQueue.h
catapult::io::RawFile
Wrapper for low-level i/o operations on files.
Definition: RawFile.h:49
catapult::io::OpenMode::Read_Write
Open file for both reading and writing. Removes the file if it exists.
catapult::io::IndexFile
Index file containing a uint64_t value.
Definition: IndexFile.h:28
catapult::io::FileQueueReader::m_readerIndexFile
IndexFile m_readerIndexFile
Definition: FileQueue.h:76
catapult::utils::HexFormat
constexpr void HexFormat(const ByteArray< N, TTag > &)
catapult::io::FileQueueWriter::write
void write(const RawBuffer &buffer) override
Definition: FileQueue.cpp:63
catapult::io::OpenMode::Read_Only
Open file in read-only mode.
catapult::io::LockMode
LockMode
Defines locking mode for the file.
Definition: RawFile.h:40
catapult::io::FileQueueWriter::m_indexFile
IndexFile m_indexFile
Definition: FileQueue.h:45
functions.h
catapult::io::FileQueueWriter::m_indexValue
uint64_t m_indexValue
Definition: FileQueue.h:46
CATAPULT_THROW_RUNTIME_ERROR_1
#define CATAPULT_THROW_RUNTIME_ERROR_1(MESSAGE, PARAM1)
Macro used to throw a catapult runtime error with a single parameter.
Definition: exceptions.h:171
catapult::io::FileQueueWriter::m_directory
boost::filesystem::path m_directory
Definition: FileQueue.h:44
IndexFile.h
BufferedFileStream.h
HexFormatter.h
catapult::io::FileQueueReader
File based queue reader where each message is represented by a file (with incrementing names) in a di...
Definition: FileQueue.h:51
catapult::io::FileQueueWriter
Definition: FileQueue.h:31
catapult::io::FileQueueReader::skip
void skip(uint32_t count)
Skips at most the next count messages.
Definition: FileQueue.cpp:121
catapult::io::FileQueueReader::m_directory
boost::filesystem::path m_directory
Definition: FileQueue.h:75
catapult::io::FileQueueWriter::m_pOutputStream
std::unique_ptr< BufferedOutputFileStream > m_pOutputStream
Definition: FileQueue.h:47
catapult::io::IndexFile::exists
bool exists() const
true if the index file exists.
Definition: IndexFile.cpp:32
catapult::io::FileQueueReader::process
bool process(const consumer< const std::string & > &processFilename)
Definition: FileQueue.cpp:126
catapult::io::FileQueueReader::tryReadNextMessage
bool tryReadNextMessage(const consumer< std::vector< uint8_t >> &consumer)
Tries to read the next message and forwards it to consumer if successful.
Definition: FileQueue.cpp:114
catapult::io::FileQueueReader::FileQueueReader
FileQueueReader(const std::string &directory)
Creates a file queue reader around directory.
Definition: FileQueue.cpp:95
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::io::FileQueueReader::pending
size_t pending() const
Gets the number of pending messages.
Definition: FileQueue.cpp:108
catapult::io::FileQueueWriter::FileQueueWriter
FileQueueWriter(const std::string &directory)
Creates a file queue writer around directory.
Definition: FileQueue.cpp:54
catapult::io::IndexFile::increment
uint64_t increment()
Increments the index value by one and returns the new value.
Definition: IndexFile.cpp:47
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::io::OutputStream
Writer interface.
Definition: Stream.h:41
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62
catapult::io::FileQueueWriter::flush
void flush() override
Definition: FileQueue.cpp:73