Joedb 10.2.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_multi_server.cpp
Go to the documentation of this file.
6
7#include <iostream>
8#include <list>
9#include <memory>
10
11namespace joedb
12{
13 ////////////////////////////////////////////////////////////////////////////
15 ////////////////////////////////////////////////////////////////////////////
16 {
17 private:
18 File file;
20 Server server;
21
22 public:
24 (
25 Logger &logger,
26 int log_level,
27 const std::string &file_name,
28 const std::string &endpoint_path,
29 std::chrono::milliseconds timeout
30 ):
32 client(file),
33 server
34 (
35 logger,
36 log_level,
37 1,
38 endpoint_path,
39 client,
40 timeout
41 )
42 {
43 }
44
45 void join() {server.join();}
46 };
47
48 ////////////////////////////////////////////////////////////////////////////
49 static int multi_server(Arguments &arguments)
50 ////////////////////////////////////////////////////////////////////////////
51 {
52 const float timeout_seconds = arguments.get_option<float>
53 (
54 "timeout",
55 "seconds",
56 0.0f
57 );
58
59 const int log_level = arguments.get_option<int>("log_level", "level", 100);
60
61 arguments.add_parameter("<file.joedb>+");
62
63 if (arguments.get_remaining_count() == 0)
64 {
65 arguments.print_help(std::cerr);
66 return 1;
67 }
68
69 std::list<std::unique_ptr<Server_Data>> servers;
70
71 Stream_Logger logger(std::cerr);
72
73 while (arguments.get_remaining_count())
74 {
75 const std::string file_name(arguments.get_next());
76 std::cerr << "Creating server for: " << file_name << '\n';
77 servers.emplace_back
78 (
79 new Server_Data
80 (
81 logger,
82 log_level,
83 file_name,
84 file_name + ".sock",
85 std::chrono::milliseconds(std::lround(timeout_seconds * 1000))
86 )
87 );
88 }
89
90 for (auto &server: servers)
91 server->join();
92
93 return 0;
94 }
95}
96
97/////////////////////////////////////////////////////////////////////////////
98int main(int argc, char **argv)
99/////////////////////////////////////////////////////////////////////////////
100{
101 return joedb::main_wrapper(joedb::multi_server, argc, argv);
102}
Server_Data(Logger &logger, int log_level, const std::string &file_name, const std::string &endpoint_path, std::chrono::milliseconds timeout)
int main()
Open_Mode
Definition Open_Mode.h:8
@ write_existing_or_create_new
either write_existing or create_new depending on whether the file exists. Racy in Posix,...
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.
JOEDB_FILE File
Definition File.h:25