Loading...
Searching...
No Matches
server_factory.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
27
28namespace resdb {
29
31 public:
32 std::unique_ptr<ServiceNetwork> CreateResDBServer(
33 char* config_file, char* private_key_file, char* cert_file,
34 std::unique_ptr<TransactionManager> executor, char* logging_dir,
35 std::function<void(ResDBConfig* config)> config_handler);
36
37 template <typename ConsensusProtocol = ConsensusManagerPBFT>
38 std::unique_ptr<ServiceNetwork> CustomCreateResDBServer(
39 char* config_file, char* private_key_file, char* cert_file,
40 std::unique_ptr<TransactionManager> executor, char* logging_dir,
41 std::function<void(ResDBConfig* config)> config_handler);
42
43 template <typename ConsensusProtocol = ConsensusManagerPBFT>
44 std::unique_ptr<ServiceNetwork> CustomCreateResDBServer(
45 char* config_file, char* private_key_file, char* cert_file,
46 std::unique_ptr<TransactionManager> executor,
47 std::unique_ptr<CustomQuery> query_executor,
48 std::function<void(ResDBConfig* config)> config_handler);
49};
50
51std::unique_ptr<ServiceNetwork> GenerateResDBServer(
52 char* config_file, char* private_key_file, char* cert_file,
53 std::unique_ptr<TransactionManager> executor, char* logging_dir = nullptr,
54 std::function<void(ResDBConfig* config)> config_handler = nullptr);
55
56template <typename ConsensusProtocol>
57std::unique_ptr<ServiceNetwork> CustomGenerateResDBServer(
58 char* config_file, char* private_key_file, char* cert_file,
59 std::unique_ptr<TransactionManager> executor, char* logging_dir = nullptr,
60 std::function<void(ResDBConfig* config)> config_handler = nullptr);
61
62template <typename ConsensusProtocol>
63std::unique_ptr<ServiceNetwork> CustomGenerateResDBServer(
64 char* config_file, char* private_key_file, char* cert_file,
65 std::unique_ptr<TransactionManager> executor,
66 std::unique_ptr<CustomQuery> query_executor,
67 std::function<void(ResDBConfig* config)> config_handler = nullptr);
68
69// ===================================================================
70template <typename ConsensusProtocol>
71std::unique_ptr<ServiceNetwork> ServerFactory::CustomCreateResDBServer(
72 char* config_file, char* private_key_file, char* cert_file,
73 std::unique_ptr<TransactionManager> executor, char* logging_dir,
74 std::function<void(ResDBConfig* config)> config_handler) {
75 std::unique_ptr<ResDBConfig> config =
76 GenerateResDBConfig(config_file, private_key_file, cert_file);
77
78 if (config_handler) {
79 config_handler(config.get());
80 }
81 return std::make_unique<ServiceNetwork>(
82 *config,
83 std::make_unique<ConsensusProtocol>(*config, std::move(executor)));
84}
85
86template <typename ConsensusProtocol>
87std::unique_ptr<ServiceNetwork> ServerFactory::CustomCreateResDBServer(
88 char* config_file, char* private_key_file, char* cert_file,
89 std::unique_ptr<TransactionManager> executor,
90 std::unique_ptr<CustomQuery> query_executor,
91 std::function<void(ResDBConfig* config)> config_handler) {
92 std::unique_ptr<ResDBConfig> config =
93 GenerateResDBConfig(config_file, private_key_file, cert_file);
94
95 if (config_handler) {
96 config_handler(config.get());
97 }
98 return std::make_unique<ServiceNetwork>(
99 *config, std::make_unique<ConsensusProtocol>(*config, std::move(executor),
100 std::move(query_executor)));
101}
102
103template <typename ConsensusProtocol>
104std::unique_ptr<ServiceNetwork> CustomGenerateResDBServer(
105 char* config_file, char* private_key_file, char* cert_file,
106 std::unique_ptr<TransactionManager> executor, char* logging_dir,
107 std::function<void(ResDBConfig* config)> config_handler) {
108 return ServerFactory().CustomCreateResDBServer<ConsensusProtocol>(
109 config_file, private_key_file, cert_file, std::move(executor),
110 logging_dir, config_handler);
111}
112
113template <typename ConsensusProtocol>
114std::unique_ptr<ServiceNetwork> CustomGenerateResDBServer(
115 char* config_file, char* private_key_file, char* cert_file,
116 std::unique_ptr<TransactionManager> executor,
117 std::unique_ptr<CustomQuery> query_executor,
118 std::function<void(ResDBConfig* config)> config_handler) {
119 return ServerFactory().CustomCreateResDBServer<ConsensusProtocol>(
120 config_file, private_key_file, cert_file, std::move(executor),
121 std::move(query_executor), config_handler);
122}
123
124} // namespace resdb
std::unique_ptr< ServiceNetwork > CustomCreateResDBServer(char *config_file, char *private_key_file, char *cert_file, std::unique_ptr< TransactionManager > executor, char *logging_dir, std::function< void(ResDBConfig *config)> config_handler)
std::unique_ptr< ServiceNetwork > CreateResDBServer(char *config_file, char *private_key_file, char *cert_file, std::unique_ptr< TransactionManager > executor, char *logging_dir, std::function< void(ResDBConfig *config)> config_handler)
std::unique_ptr< ServiceNetwork > GenerateResDBServer(char *config_file, char *private_key_file, char *cert_file, std::unique_ptr< TransactionManager > executor, char *logging_dir, std::function< void(ResDBConfig *config)> config_handler)
std::unique_ptr< ServiceNetwork > CustomGenerateResDBServer(char *config_file, char *private_key_file, char *cert_file, std::unique_ptr< TransactionManager > executor, char *logging_dir=nullptr, std::function< void(ResDBConfig *config)> config_handler=nullptr)
std::unique_ptr< ResDBConfig > GenerateResDBConfig(const std::string &config_file, const std::string &private_key_file, const std::string &cert_file, std::optional< ReplicaInfo > self_info, std::optional< ConfigGenFunc > gen_func)