Akumuli
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
server.h
1 #pragma once
2 #include "akumuli.h"
3 #include "ingestion_pipeline.h"
4 #include "signal_handler.h"
5 
6 #include <map>
7 #include <string>
8 #include <tuple>
9 #include <tuple>
10 
11 namespace Akumuli {
12 
14  std::string name;
15  int port;
16  int nworkers;
17 };
18 
19 
22 struct ReadOperation {
23  virtual ~ReadOperation() = default;
24 
27  virtual void start() = 0;
28 
31  virtual void append(const char* data, size_t data_size) = 0;
32 
38  virtual aku_Status get_error() = 0;
39 
46  virtual std::tuple<size_t, bool> read_some(char* buf, size_t buf_size) = 0;
47 
51  virtual void close() = 0;
52 };
53 
54 
57  virtual ~ReadOperationBuilder() = default;
58  virtual ReadOperation* create() = 0;
59  virtual std::string get_all_stats() = 0;
60 };
61 
62 
64 struct Server {
65  virtual ~Server() = default;
66  virtual void start(SignalHandler* sig_handler, int id) = 0;
67 };
68 
69 struct ServerFactory {
70 
71  typedef std::function<std::shared_ptr<Server>(std::shared_ptr<IngestionPipeline>,
72  std::shared_ptr<ReadOperationBuilder>,
73  const ServerSettings&)>
74  Generator;
75 
76  std::map<std::string, Generator> gen_;
77 
78  std::shared_ptr<Server> create(std::shared_ptr<IngestionPipeline> pipeline,
79  std::shared_ptr<ReadOperationBuilder> qproc,
80  const ServerSettings& settings) {
81  auto it = gen_.find(settings.name);
82  if (it == gen_.end()) {
83  return std::shared_ptr<Server>();
84  }
85  return it->second(pipeline, qproc, settings);
86  }
87 
88  void register_type(std::string name, Generator gen) { gen_[name] = gen; }
89 
90  static ServerFactory& instance() {
91  static ServerFactory factory;
92  return factory;
93  }
94 };
95 
96 } // namespace
virtual void start()=0
Server interface.
Definition: server.h:64
virtual std::tuple< size_t, bool > read_some(char *buf, size_t buf_size)=0
Definition: server.h:13
virtual aku_Status get_error()=0
virtual void close()=0
Interface that can be used to create read operations.
Definition: server.h:56
Definition: signal_handler.h:12
Definition: server.h:22
virtual void append(const char *data, size_t data_size)=0
Definition: server.h:69