proxygen
folly::FileWriterFactory Class Reference

#include <FileWriterFactory.h>

Public Member Functions

bool processOption (StringPiece name, StringPiece value)
 
std::shared_ptr< LogWritercreateWriter (File file)
 

Private Attributes

bool async_ {true}
 
Optional< size_t > maxBufferSize_
 

Detailed Description

A helper class for creating an AsyncFileWriter or ImmediateFileWriter based on log handler options settings.

This is used by StreamHandlerFactory and FileHandlerFactory.

Definition at line 33 of file FileWriterFactory.h.

Member Function Documentation

std::shared_ptr< LogWriter > folly::FileWriterFactory::createWriter ( File  file)

Definition at line 44 of file FileWriterFactory.cpp.

References async_, folly::Optional< Value >::hasValue(), maxBufferSize_, folly::gen::move, and folly::Optional< Value >::value().

Referenced by folly::StreamHandlerFactory::WriterFactory::createWriter(), and folly::FileHandlerFactory::WriterFactory::createWriter().

44  {
45  // Determine whether we should use ImmediateFileWriter or AsyncFileWriter
46  if (async_) {
47  auto asyncWriter = make_shared<AsyncFileWriter>(std::move(file));
48  if (maxBufferSize_.hasValue()) {
49  asyncWriter->setMaxBufferSize(maxBufferSize_.value());
50  }
51  return asyncWriter;
52  } else {
53  if (maxBufferSize_.hasValue()) {
54  throw std::invalid_argument(to<string>(
55  "the \"max_buffer_size\" option is only valid for async file "
56  "handlers"));
57  }
58  return make_shared<ImmediateFileWriter>(std::move(file));
59  }
60 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
Optional< size_t > maxBufferSize_
bool folly::FileWriterFactory::processOption ( StringPiece  name,
StringPiece  value 
)

Definition at line 28 of file FileWriterFactory.cpp.

References async_, maxBufferSize_, folly::size(), and folly::value().

Referenced by folly::FileHandlerFactory::WriterFactory::processOption(), and folly::StreamHandlerFactory::WriterFactory::processOption().

28  {
29  if (name == "async") {
30  async_ = to<bool>(value);
31  return true;
32  } else if (name == "max_buffer_size") {
33  auto size = to<size_t>(value);
34  if (size == 0) {
35  throw std::invalid_argument(to<string>("must be a positive integer"));
36  }
38  return true;
39  } else {
40  return false;
41  }
42 }
const char * name
Definition: http_parser.c:437
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Optional< size_t > maxBufferSize_

Member Data Documentation

bool folly::FileWriterFactory::async_ {true}
private

Definition at line 39 of file FileWriterFactory.h.

Referenced by createWriter(), and processOption().

Optional<size_t> folly::FileWriterFactory::maxBufferSize_
private

Definition at line 40 of file FileWriterFactory.h.

Referenced by createWriter(), and processOption().


The documentation for this class was generated from the following files: