-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (45 loc) · 1.89 KB
/
main.cpp
File metadata and controls
58 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "include/BackendServersRepository.h"
#include "include/CLIArgsParser.h"
#include "include/ConfigParser.h"
#include "include/FrontendServer.h"
#include "include/HealthChecker.h"
#include "include/HealthCheckerFactory.h"
#include "include/Logger.h"
#include "include/ProxyConnectionFactory.h"
#include "include/RoundRobin.h"
#include "include/SchedulingStrategyBuilder.h"
#include <memory>
using namespace std;
int main(int argc, char **argv) {
auto cli_args_parser = make_unique<CLIArgsParser>();
cli_args_parser->ParseCLIArgs(argc, argv);
if (!cli_args_parser->ArgsValid()) {
cli_args_parser->ShowHelp();
return EXIT_FAILURE;
}
auto config_file_path = cli_args_parser->GetConfigFilePath();
auto config_parser = make_shared<ConfigParser>(config_file_path);
config_parser->ParseConfigFile();
if (!config_parser->ConfigValid()) {
cout << "Invalid config file!\n";
return EXIT_FAILURE;
}
SET_LOGGING_LEVEL(config_parser->LogLevel());
SET_LOGGING_OUTPUT(config_parser->LogFilePath());
boost::asio::io_context io_context;
auto health_checker_factory = make_unique<HealthCheckerFactory>(io_context, config_parser);
auto backend_servers_repository = make_shared<BackendServersRepository>(
move(health_checker_factory),
config_parser);
auto scheduling_strategy_builder = make_unique<SchedulingStrategyBuilder>(config_parser);
auto scheduling_strategy = scheduling_strategy_builder->ConstructSchedulingStrategy();
auto proxy_connection_factory = make_unique<ProxyConnectionFactory>(
io_context,
backend_servers_repository,
scheduling_strategy,
config_parser);
auto frontend_server = make_shared<FrontendServer>(io_context, move(proxy_connection_factory), config_parser);
frontend_server->run();
io_context.run();
return EXIT_SUCCESS;
}