Horizon Official Technical Documentation
Server.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_SERVER_HPP
31#define HORIZON_SERVER_HPP
32
35
36#include "System.hpp"
37#include <boost/lexical_cast.hpp>
38#include <boost/uuid/uuid.hpp>
39#include <boost/uuid/uuid_io.hpp>
40#include <boost/uuid/random_generator.hpp>
41#include <queue>
42
43#include <boost/mysql/error_with_diagnostics.hpp>
44#include <boost/mysql/handshake_params.hpp>
45#include <boost/mysql/results.hpp>
46#include <boost/mysql/tcp_ssl.hpp>
47
48#include <boost/asio/io_context.hpp>
49#include <boost/asio/ip/tcp.hpp>
50#include <boost/asio/ssl/context.hpp>
51#include <boost/system/system_error.hpp>
52
53#include <boost/chrono.hpp>
54
56
57#include <sol/sol.hpp>
58#include <thread>
59
60#define TERMINAL_STR "Horizon $> "
61
63{
68};
69
70extern std::atomic<shutdown_stages> _shutdown_stage;
71extern std::atomic<int> _shutdown_signal;
72
73extern inline void set_shutdown_signal(int signal) { _shutdown_signal.exchange(signal); }
74extern inline shutdown_stages get_shutdown_stage() { return _shutdown_stage.load(); };
75extern inline void set_shutdown_stage(shutdown_stages new_stage) { _shutdown_stage.exchange(new_stage); };
76
78{
90};
91
92template <typename Key, typename Value>
94 using key_type = Key;
95 using value_type = Value;
99 // add value
100 void add(Key key, Value value) { _table.insert(key, value); }
101 // remove value
102 void remove(Key key) { _table.erase(key); }
103 // get value
104 Value get(Key key, Value const &default_value = Value()) { return _table.at(key, default_value); }
105 // get size
106 int size() { return _table.size(); }
107 // clear
108 void clear() { _table.clear(); }
109};
110
111template <class Storage>
113{
114public:
115 SharedPriorityResourceMedium(int priority, std::shared_ptr<Storage> storage) : _priority(priority), _storage(storage) { }
116
117 int64_t get_priority() { return _priority; }
118 Storage get_storage() { return _storage; }
119 // add
120 void add(typename Storage::key_type key, typename Storage::value_type value) { _storage->add(key, value); }
121 // remove
122 void remove(typename Storage::key_type key) { _storage->remove(key); }
123 // get
124 typename Storage::value_type get(typename Storage::key_type key, typename Storage::value_type default_value = typename Storage::value_type()) { return _storage->get(key, default_value); }
125 // size
126 int size() { return _storage->size(); }
127 // clear
128 void clear() { _storage->clear(); }
129
130 std::map<typename Storage::key_type, typename Storage::value_type> get_map() { return _storage->_table.get_map(); }
131
132protected:
133 int64_t _priority;
134 std::shared_ptr<Storage> _storage;
135};
136
137template <typename... SharedPriorityResourceMediums>
139public:
140 SharedPriorityResourceManager(SharedPriorityResourceMediums... mediums) : _resources(mediums...) { }
141
142 // copy constructor
144 // move constructor
146 // copy assignment
148 // move assignment
149 SharedPriorityResourceManager &operator=(SharedPriorityResourceManager &&other) { _resources = std::move(other._resources); return *this; }
150
151 template <std::size_t Priority>
152 auto& get_medium() {
153 return std::get<Priority>(_resources);
154 }
155
156 template <std::size_t Index, typename Key, typename Value>
157 void add(Key key, Value value)
158 {
159 std::get<Index>(_resources).add(key, value);
160 }
161
162 template <std::size_t Index, typename Key>
163 void remove(Key key)
164 {
165 std::get<Index>(_resources).remove(key);
166 }
167
168 template <std::size_t Index, typename Key, typename Value>
169 Value get_resource(Key key, Value const &default_value = Value())
170 {
171 return std::get<Index>(_resources).get(key, default_value);
172 }
173
174 template <std::size_t Index>
175 int size()
176 {
177 return std::get<Index>(_resources).size();
178 }
179
180 template <std::size_t Index>
181 void clear()
182 {
183 std::get<Index>(_resources).clear();
184 }
185
186private:
187 std::tuple<SharedPriorityResourceMediums...> _resources;
188};
189
190class Kernel;
191class KernelComponent : public std::enable_shared_from_this<KernelComponent>
192{
193public:
195 : _kernel(kernel), _module_type(module_type), _hsr_manager(module_type), _uuid(boost::uuids::random_generator()())
196 { }
197 virtual void initialize(int segment_number = 1)
198 {
199 set_segment_number(segment_number);
200 }
201 virtual void finalize() { }
202
203 virtual bool is_initialized() { return false; }
204 virtual bool is_finalized() { return false; }
205
206 void set_segment_number(int64_t segment_number) { _segment_number = segment_number; }
207 int64_t get_segment_number() { return _segment_number.load(); }
208
209 void system_routine_queue_push(std::shared_ptr<Horizon::System::RuntimeContext> context);
210 void system_routine_queue_push(std::shared_ptr<Horizon::System::RuntimeContextChain> context);
212 void system_routine_register(Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t, std::shared_ptr<Horizon::System::RuntimeContext> context);
213
214 const std::string get_uuid_string() { return boost::uuids::to_string(_uuid); }
215
216 const std::string get_type_string()
217 {
218 switch (_module_type)
219 {
220 case Horizon::System::RUNTIME_MAIN: return "Main";
221 case Horizon::System::RUNTIME_GAMELOGIC: return "Game-logic";
222 case Horizon::System::RUNTIME_PERSISTENCE: return "Persistence";
223 case Horizon::System::RUNTIME_DATABASE: return "Database";
224 case Horizon::System::RUNTIME_COMMANDLINE: return "Command-Line";
225 case Horizon::System::RUNTIME_SCRIPTVM: return "Script-VM";
226 case Horizon::System::RUNTIME_NETWORKING: return "Networking";
227 case Horizon::System::RUNTIME_RUNTIME: return "Runtime";
228 case Horizon::System::RUNTIME_CLIENT_NETWORKING: return "Client-Networking";
229 case Horizon::System::RUNTIME_HTTP_SERVICE: return "Http Service";
230 case Horizon::System::RUNTIME_WEB_SOCKET: return "Web Socket Service";
231 default: return "Unknown";
232 }
233 }
234
236
237 Kernel *get_kernel() { return _kernel; }
238
239 void set_thread_cpu_id(int cpu_id) { _thread_cpu_id.exchange(cpu_id); }
240 int get_thread_cpu_id() { return _thread_cpu_id.load(); }
241
242 void set_thread_update_rate(double rate) { _thread_update_rate.exchange(rate); }
243 double get_thread_update_rate() { return _thread_update_rate.load(); }
244
246 {
248
249 if (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _last_total_execution_time_update).count() >= 1) {
250 _last_total_execution_time_update = std::chrono::steady_clock::now();
253 }
254 }
256
258 {
260
261 // Update thread update rate every second to determine the number of updates per second
262 auto current_time = std::chrono::steady_clock::now();
263 auto diff_time = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time - _last_thread_update_rate_time).count();
264 if (diff_time >= 1e9) {
265 double update_rate = _update_count / (diff_time / 1e9);
266 set_thread_update_rate(update_rate);
267 _update_count = 0;
268 _last_thread_update_rate_time = current_time;
269 }
270 }
271
272private:
273 std::atomic<int64_t> _segment_number{0};
276 boost::uuids::uuid _uuid;
277
278 std::atomic<int> _thread_cpu_id{0};
279 Kernel *_kernel{nullptr};
281 std::chrono::steady_clock::time_point _last_thread_update_rate_time;
282 std::chrono::steady_clock::time_point _last_total_execution_time_update;
283 std::atomic<double> _thread_update_rate{0.0};
285 std::atomic<int> _total_execution_time_average{0};
286};
287
289{
290public:
291 typedef std::function<void(CLICommand, bool)> FinishFunc;
292
294
295 CLICommand(char *command, FinishFunc finish_func)
296 : m_command(command), m_finish_func(finish_func)
297 {
298 //
299 }
300
302 {
303 }
304
306 {
307 m_command = command.m_command;
309 }
310
312 {
313 m_command = command.m_command;
314 m_finish_func = command.m_finish_func;
315 }
316
318 {
319 return CLICommand(command);
320 }
321
322 std::string m_command;
324};
325
327{
328public:
330 void process();
331 void queue(CLICommand &&cmdMgr) { _cli_cmd_queue.push(std::move(cmdMgr)); }
332 void add_function(std::string cmd, std::function<bool(std::string)> func) { _cli_function_map.insert(std::make_pair(cmd, func)); };
333
334 /* CLI Function getter */
335 std::function<bool(std::string)> find(std::string &cmd)
336 {
337 auto it = _cli_function_map.find(cmd);
338 return (it != _cli_function_map.end()) ? it->second : nullptr;
339 }
340
341 void initialize(int segment_number = 1) override;
342 void finalize() override;
343
344 void command_complete(CLICommand /*cmd*/, bool /*success*/)
345 {
346 fflush(stdout);
347 }
348
349 void cli_thread_start();
350
354 bool clicmd_shutdown(std::string /*cmd*/);
355 bool clicmd_kernel_info(std::string /*cmd*/);
356
357 bool is_initialized() override { return _is_initialized; }
358 bool is_finalized() override { return _is_finalized; }
359
360private:
361 std::unordered_map<std::string, std::function<bool(std::string)>> _cli_function_map;
362 // CLI command holder to be thread safe
363 std::queue<CLICommand> _cli_cmd_queue;
364 std::thread _cli_thread;
365 std::atomic<bool> _is_initialized{false};
366 std::atomic<bool> _is_finalized{false};
367 std::atomic<bool> _is_running_command{false};
368};
369
371{
372public:
374 // KernelComponent dispatch module type is set to Main because DatabaseProcess doesn't run on its own thread.
377 {
378 _connection.reset();
379 _ssl_ctx.reset();
380 }
381
382 void initialize(int segment_number = 1) override
383 {
384 set_segment_number(segment_number);
385 HLog(error) << "Database not configured";
386 _is_initialized.exchange(true);
387 }
388
390 {
391 _connection.reset();
392 _ssl_ctx.reset();
393 _is_initialized.exchange(false);
394 _is_finalized.exchange(false);
395 if (_io_context != nullptr)
397 }
398
399 void initialize(boost::asio::io_context &io_context, int segment_number, std::string host, int port, std::string user, std::string pass, std::string database);
400
401 void finalize() override
402 {
403 // Close connection object.
404 if (_connection != nullptr) {
405 _connection->close();
406 }
407
408 _is_finalized.exchange(true);
409 }
410
411 std::shared_ptr<boost::mysql::tcp_ssl_connection> get_connection();
412
413 bool is_initialized() override { return _is_initialized.load(); }
414 bool is_finalized() override { return _is_finalized.load(); }
415
416protected:
417 boost::asio::io_context *_io_context;
418 std::shared_ptr<boost::asio::ssl::context> _ssl_ctx{nullptr};
419 std::shared_ptr<boost::mysql::tcp_ssl_connection> _connection{nullptr};
420 std::string _host;
421 int _port;
422 std::string _user;
423 std::string _pass;
424 std::string _database;
425 std::atomic<bool> _is_initialized{false};
426 std::atomic<bool> _is_finalized{false};
427};
428
430{
433 std::shared_ptr<KernelComponent> ptr;
435};
436
437typedef std::map<std::string, kernel_component_state_holder> KernelComponents;
438
440{
441public:
443 ~Kernel();
444
445 virtual void initialize() = 0; //< Kernel initialization routine
446 virtual void finalize() = 0; //< Kernel finalization routine
447 virtual void post_initialize() = 0; //< Post initialization routine
448 virtual void post_finalize() = 0; //< Post finalization routine
449
451
452 template <typename T>
453 std::shared_ptr<T> get_component(std::string uuid)
454 {
455 auto it = _components.find(uuid);
456 if (it == _components.end())
457 return nullptr;
458
459 return std::static_pointer_cast<T>(it->second.ptr);
460 }
461
462 template <typename T>
463 std::shared_ptr<T> get_component_of_type(Horizon::System::runtime_module_type type, int segment_number = 1)
464 {
465 for (auto c : _components) {
466 if (c.second.type == type && c.second.segment_number == segment_number) {
467 return std::static_pointer_cast<T>(c.second.ptr);
468 }
469 }
470
471 return nullptr;
472 }
473
474 template <typename T>
478 holder.type = type;
479 holder.ptr = std::make_shared<T>(std::move(component));
480 _components.insert(std::pair(component.get_uuid_string(), holder));
481 }
482
483 template <typename T>
484 void register_component(Horizon::System::runtime_module_type type, std::shared_ptr<T> component)
485 {
488 holder.type = type;
489 holder.ptr = std::static_pointer_cast<KernelComponent>(component);
490 _components.insert(std::pair(component->get_uuid_string(), holder));
491 }
492
494 {
495 for (auto c : _components) {
496 if (c.second.type == type && c.second.segment_number == segment_number) {
497 _components.erase(c.first);
498 break;
499 }
500 }
501 }
502
504 {
505 int count = 0;
506 for (auto c : _components) {
507 if (c.second.type == type)
508 count++;
509 }
510 return count;
511 }
512
513 template <typename ComponentType, std::size_t Priority, typename Key, typename Value>
514 int get_segment_number_for_resource(Horizon::System::runtime_module_type module_t, Key resource_key, Value resource_not_found_value)
515 {
516
517 for (int i = 0; i < get_registered_component_count_of_type(module_t); i++) {
518 auto component = get_component_of_type<ComponentType>(module_t, i + 1);
519 if (component->get_resource_manager().template get_resource<Priority, Key, Value>(resource_key, resource_not_found_value) != resource_not_found_value)
520 return i + 1;
521 }
522
523 return 0;
524 }
525
526 int get_component_count() { return _components.size(); }
527
529
530 void system_routine_queue_push(std::shared_ptr<Horizon::System::RuntimeContext> context);
531 void system_routine_queue_push(std::shared_ptr<Horizon::System::RuntimeContextChain> context);
533 void system_routine_register(Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t, std::shared_ptr<Horizon::System::RuntimeContext> context);
534
536
537 /* Core I/O Service*/
538 boost::asio::io_context &get_io_context();
539
542
543protected:
544 boost::asio::io_context _io_context_global;
547private:
549
550 std::atomic<bool> _signal_interrupt_command_line_loop{false};
551};
552
553class Server : public Kernel
554{
555public:
556 Server();
557 ~Server();
558
559 void parse_exec_args(const char *argv[], int argc);
560
561 virtual void initialize();
562 virtual void finalize();
563
564 virtual void post_initialize();
565 virtual void post_finalize();
566
567 void print_help();
568
569 /* General Configuration */
571 /* Common Configuration */
572 bool parse_common_configs(sol::table &cfg);
573
574 std::shared_ptr<boost::mysql::tcp_ssl_connection> get_database_connection()
575 {
576 return get_component_of_type<DatabaseProcess>(Horizon::System::RUNTIME_DATABASE)->get_connection();
577 }
578
580
581protected:
582 /* General Configuration */
584
585};
586
587#endif /* HORIZON_SERVER_HPP */
#define HLog(type)
Definition: Logger.hpp:122
shutdown_stages get_shutdown_stage()
Definition: Server.hpp:74
std::atomic< int > _shutdown_signal
Definition: Server.cpp:51
std::map< std::string, kernel_component_state_holder > KernelComponents
Definition: Server.hpp:437
void set_shutdown_signal(int signal)
Definition: Server.hpp:73
kernel_resource_priority_type
Definition: Server.hpp:78
@ RESOURCE_PRIORITY_SECONDARY
Definition: Server.hpp:80
@ RESOURCE_PRIORITY_DENARY
Definition: Server.hpp:88
@ RESOURCE_PRIORITY_SENARY
Definition: Server.hpp:84
@ RESOURCE_PRIORITY_OCTONARY
Definition: Server.hpp:86
@ RESOURCE_PRIORITY_SEPTENARY
Definition: Server.hpp:85
@ RESOURCE_PRIORITY_PRIMARY
Definition: Server.hpp:79
@ RESOURCE_PRIORITY_TERTIARY
Definition: Server.hpp:81
@ RESOURCE_PRIORITY_NONARY
Definition: Server.hpp:87
@ MAX_KERNEL_SEGMENT_PRIORITIES
Definition: Server.hpp:89
@ RESOURCE_PRIORITY_QUINARY
Definition: Server.hpp:83
@ RESOURCE_PRIORITY_QUATERNARY
Definition: Server.hpp:82
std::atomic< shutdown_stages > _shutdown_stage
Definition: Server.cpp:50
shutdown_stages
Definition: Server.hpp:63
@ SHUTDOWN_COMPLETE
Definition: Server.hpp:67
@ SHUTDOWN_NOT_STARTED
Definition: Server.hpp:64
@ SHUTDOWN_CLEANUP_COMPLETE
Definition: Server.hpp:66
@ SHUTDOWN_INITIATED
Definition: Server.hpp:65
void set_shutdown_stage(shutdown_stages new_stage)
Definition: Server.hpp:75
Definition: Server.hpp:289
FinishFunc m_finish_func
Completion handler function.
Definition: Server.hpp:323
~CLICommand()
Definition: Server.hpp:301
std::string m_command
Command string.
Definition: Server.hpp:322
CLICommand(char *command, FinishFunc finish_func)
Definition: Server.hpp:295
CLICommand()
Definition: Server.hpp:293
CLICommand(CLICommand &&command)
Definition: Server.hpp:311
CLICommand operator=(CLICommand &command)
Definition: Server.hpp:317
std::function< void(CLICommand, bool)> FinishFunc
Definition: Server.hpp:291
CLICommand(CLICommand &command)
Definition: Server.hpp:305
Definition: Server.hpp:327
void finalize() override
Definition: Server.cpp:156
bool is_initialized() override
Definition: Server.hpp:357
std::atomic< bool > _is_running_command
Definition: Server.hpp:367
bool is_finalized() override
Definition: Server.hpp:358
std::function< bool(std::string)> find(std::string &cmd)
Definition: Server.hpp:335
std::atomic< bool > _is_finalized
Definition: Server.hpp:366
void command_complete(CLICommand, bool)
Definition: Server.hpp:344
void queue(CLICommand &&cmdMgr)
Definition: Server.hpp:331
std::atomic< bool > _is_initialized
Definition: Server.hpp:365
CommandLineProcess(Kernel *kernel)
Definition: Server.hpp:329
std::queue< CLICommand > _cli_cmd_queue
Definition: Server.hpp:363
std::thread _cli_thread
Definition: Server.hpp:364
void initialize(int segment_number=1) override
Definition: Server.cpp:144
std::unordered_map< std::string, std::function< bool(std::string)> > _cli_function_map
Definition: Server.hpp:361
void cli_thread_start()
Definition: Server.cpp:197
bool clicmd_shutdown(std::string)
CLI Commands.
Definition: Server.cpp:93
void process()
Definition: Server.cpp:164
void add_function(std::string cmd, std::function< bool(std::string)> func)
Definition: Server.hpp:332
bool clicmd_kernel_info(std::string)
Definition: Server.cpp:100
Definition: Server.hpp:371
std::string _host
Definition: Server.hpp:420
DatabaseProcess()
Definition: Server.hpp:373
void finalize() override
Definition: Server.hpp:401
void reinitialize()
Definition: Server.hpp:389
std::shared_ptr< boost::mysql::tcp_ssl_connection > get_connection()
Definition: Server.cpp:254
~DatabaseProcess()
Definition: Server.hpp:376
bool is_initialized() override
Definition: Server.hpp:413
std::atomic< bool > _is_finalized
Definition: Server.hpp:426
bool is_finalized() override
Definition: Server.hpp:414
DatabaseProcess(Kernel *kernel)
Definition: Server.hpp:375
std::string _user
Definition: Server.hpp:422
std::shared_ptr< boost::mysql::tcp_ssl_connection > _connection
Definition: Server.hpp:419
std::string _pass
Definition: Server.hpp:423
int _port
Definition: Server.hpp:421
boost::asio::io_context * _io_context
Definition: Server.hpp:417
std::shared_ptr< boost::asio::ssl::context > _ssl_ctx
Definition: Server.hpp:418
std::atomic< bool > _is_initialized
Definition: Server.hpp:425
std::string _database
Definition: Server.hpp:424
void initialize(int segment_number=1) override
Definition: Server.hpp:382
Definition: System.hpp:600
Definition: Server.hpp:192
std::atomic< int > _total_execution_time_average
Definition: Server.hpp:285
std::chrono::steady_clock::time_point _last_total_execution_time_update
Definition: Server.hpp:282
virtual void initialize(int segment_number=1)
Definition: Server.hpp:197
Horizon::System::runtime_module_type _module_type
Definition: Server.hpp:274
int _total_execution_time_aggregate
Definition: Server.hpp:284
void set_thread_cpu_id(int cpu_id)
Definition: Server.hpp:239
virtual bool is_finalized()
Definition: Server.hpp:204
Kernel * get_kernel()
Definition: Server.hpp:237
Horizon::System::SystemRoutineManager & get_system_routine_manager()
Definition: Server.hpp:235
int64_t get_segment_number()
Definition: Server.hpp:207
void set_total_execution_time(int time)
Definition: Server.hpp:245
virtual bool is_initialized()
Definition: Server.hpp:203
int _update_count
Definition: Server.hpp:280
void system_routine_queue_push(std::shared_ptr< Horizon::System::RuntimeContext > context)
Definition: Server.cpp:75
std::chrono::steady_clock::time_point _last_thread_update_rate_time
Definition: Server.hpp:281
void calculate_and_set_cpu_load()
Definition: Server.hpp:257
void system_routine_process_queue()
Definition: Server.cpp:77
boost::uuids::uuid _uuid
Definition: Server.hpp:276
std::atomic< int64_t > _segment_number
Definition: Server.hpp:273
void set_thread_update_rate(double rate)
Definition: Server.hpp:242
Horizon::System::SystemRoutineManager _hsr_manager
Definition: Server.hpp:275
double get_thread_update_rate()
Definition: Server.hpp:243
virtual void finalize()
Definition: Server.hpp:201
KernelComponent(Kernel *kernel, Horizon::System::runtime_module_type module_type)
Definition: Server.hpp:194
const std::string get_uuid_string()
Definition: Server.hpp:214
std::atomic< double > _thread_update_rate
Definition: Server.hpp:283
int get_total_execution_time()
Definition: Server.hpp:255
Kernel * _kernel
Definition: Server.hpp:279
void set_segment_number(int64_t segment_number)
Definition: Server.hpp:206
const std::string get_type_string()
Definition: Server.hpp:216
int get_thread_cpu_id()
Definition: Server.hpp:240
std::atomic< int > _thread_cpu_id
Definition: Server.hpp:278
void system_routine_register(Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t, std::shared_ptr< Horizon::System::RuntimeContext > context)
Definition: Server.cpp:78
Definition: Server.hpp:440
Horizon::System::SystemRoutineManager _hsr_manager
Definition: Server.hpp:548
std::shared_ptr< T > get_component(std::string uuid)
Definition: Server.hpp:453
std::shared_ptr< T > get_component_of_type(Horizon::System::runtime_module_type type, int segment_number=1)
Definition: Server.hpp:463
Kernel(general_server_configuration &config)
Definition: Server.cpp:53
KernelComponents _components
Definition: Server.hpp:545
int get_segment_number_for_resource(Horizon::System::runtime_module_type module_t, Key resource_key, Value resource_not_found_value)
Definition: Server.hpp:514
void system_routine_queue_push(std::shared_ptr< Horizon::System::RuntimeContext > context)
Definition: Server.cpp:62
boost::asio::io_context & get_io_context()
Definition: Server.cpp:70
void register_component(Horizon::System::runtime_module_type type, T &&component)
Definition: Server.hpp:475
void system_routine_process_queue()
Definition: Server.cpp:64
void register_component(Horizon::System::runtime_module_type type, std::shared_ptr< T > component)
Definition: Server.hpp:484
bool get_signal_interrupt_command_line_loop()
Definition: Server.hpp:541
int get_registered_component_count_of_type(Horizon::System::runtime_module_type type)
Definition: Server.hpp:503
void system_routine_register(Horizon::System::runtime_module_type module_t, Horizon::System::runtime_synchronization_method sync_t, std::shared_ptr< Horizon::System::RuntimeContext > context)
Definition: Server.cpp:65
void deregister_component(Horizon::System::runtime_module_type type, int segment_number=1)
Definition: Server.hpp:493
int get_component_count()
Definition: Server.hpp:526
virtual void post_finalize()=0
Definition: Server.cpp:88
virtual void initialize()=0
std::atomic< bool > _signal_interrupt_command_line_loop
Definition: Server.hpp:550
void set_signal_interrupt_command_line_loop(bool signal)
Definition: Server.hpp:540
general_server_configuration _config
Definition: Server.hpp:546
~Kernel()
Definition: Server.cpp:54
virtual void post_initialize()=0
Definition: Server.cpp:83
virtual void finalize()=0
KernelComponents & get_components()
Definition: Server.hpp:528
Horizon::System::SystemRoutineManager & get_system_routine_manager()
Definition: Server.hpp:535
boost::asio::io_context _io_context_global
Definition: Server.hpp:544
struct general_server_configuration & general_conf()
Definition: Server.hpp:450
Definition: LockedLookupTable.hpp:44
Definition: Server.hpp:554
virtual void initialize()
Definition: Server.cpp:425
virtual void post_finalize()
Definition: Server.cpp:459
bool parse_common_configs(sol::table &cfg)
Definition: Server.cpp:372
~Server()
Definition: Server.cpp:316
virtual void finalize()
Definition: Server.cpp:439
std::shared_ptr< boost::mysql::tcp_ssl_connection > get_database_connection()
Definition: Server.hpp:574
struct general_server_configuration & general_conf()
Definition: Server.hpp:570
virtual void post_initialize()
Definition: Server.cpp:450
struct general_server_configuration general_config
Definition: Server.hpp:583
void print_help()
Definition: Server.cpp:320
Server()
Definition: Server.cpp:300
bool test_database_connection()
Definition: Server.cpp:464
void parse_exec_args(const char *argv[], int argc)
Definition: Server.cpp:325
Definition: Server.hpp:138
Value get_resource(Key key, Value const &default_value=Value())
Definition: Server.hpp:169
SharedPriorityResourceManager(const SharedPriorityResourceManager &other)
Definition: Server.hpp:143
SharedPriorityResourceManager(SharedPriorityResourceManager &&other)
Definition: Server.hpp:145
SharedPriorityResourceManager(SharedPriorityResourceMediums... mediums)
Definition: Server.hpp:140
void remove(Key key)
Definition: Server.hpp:163
SharedPriorityResourceManager & operator=(const SharedPriorityResourceManager &other)
Definition: Server.hpp:147
void add(Key key, Value value)
Definition: Server.hpp:157
int size()
Definition: Server.hpp:175
SharedPriorityResourceManager & operator=(SharedPriorityResourceManager &&other)
Definition: Server.hpp:149
std::tuple< SharedPriorityResourceMediums... > _resources
Definition: Server.hpp:187
auto & get_medium()
Definition: Server.hpp:152
void clear()
Definition: Server.hpp:181
Definition: Server.hpp:113
void clear()
Definition: Server.hpp:128
std::map< typename Storage::key_type, typename Storage::value_type > get_map()
Definition: Server.hpp:130
void remove(typename Storage::key_type key)
Definition: Server.hpp:122
void add(typename Storage::key_type key, typename Storage::value_type value)
Definition: Server.hpp:120
int64_t get_priority()
Definition: Server.hpp:117
SharedPriorityResourceMedium(int priority, std::shared_ptr< Storage > storage)
Definition: Server.hpp:115
int64_t _priority
Definition: Server.hpp:133
Storage::value_type get(typename Storage::key_type key, typename Storage::value_type default_value=typename Storage::value_type())
Definition: Server.hpp:124
Storage get_storage()
Definition: Server.hpp:118
int size()
Definition: Server.hpp:126
std::shared_ptr< Storage > _storage
Definition: Server.hpp:134
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100
runtime_module_type
Definition: System.hpp:81
@ RUNTIME_CLIENT_NETWORKING
Definition: System.hpp:89
@ RUNTIME_DATABASE
Definition: System.hpp:88
@ RUNTIME_NETWORKING
Definition: System.hpp:84
@ RUNTIME_WEB_SOCKET
Definition: System.hpp:91
@ RUNTIME_HTTP_SERVICE
Definition: System.hpp:90
@ RUNTIME_MAIN
Definition: System.hpp:82
@ RUNTIME_SCRIPTVM
Definition: System.hpp:87
@ RUNTIME_GAMELOGIC
Definition: System.hpp:86
@ RUNTIME_COMMANDLINE
Definition: System.hpp:83
@ RUNTIME_PERSISTENCE
Definition: System.hpp:85
@ RUNTIME_RUNTIME
Definition: System.hpp:92
runtime_synchronization_method
Definition: System.hpp:97
Definition: Element.hpp:7
Definition: ServerConfiguration.hpp:44
Definition: Server.hpp:430
int segment_number
Definition: Server.hpp:434
Horizon::System::runtime_module_type type
Definition: Server.hpp:432
std::shared_ptr< KernelComponent > ptr
Definition: Server.hpp:433
~kernel_component_state_holder()
Definition: Server.hpp:431
Definition: Server.hpp:93
LockedLookupTable< Key, Value > _table
Definition: Server.hpp:96
void add(Key key, Value value)
Definition: Server.hpp:100
Key key_type
Definition: Server.hpp:94
int size()
Definition: Server.hpp:106
void clear()
Definition: Server.hpp:108
void remove(Key key)
Definition: Server.hpp:102
s_segment_storage()
Definition: Server.hpp:97
Value value_type
Definition: Server.hpp:95
Value get(Key key, Value const &default_value=Value())
Definition: Server.hpp:104
~s_segment_storage()
Definition: Server.hpp:98