Horizon Official Technical Documentation
Horizon::Zone::ZoneNetworkThread Class Reference

#include <ClientSocketMgr.hpp>

+ Inheritance diagram for Horizon::Zone::ZoneNetworkThread:
+ Collaboration diagram for Horizon::Zone::ZoneNetworkThread:

Public Member Functions

 ZoneNetworkThread ()
 
bool start (int segment_number=1) override
 Initializes the network thread and runs. More...
 
void run () override
 Run the I/O Service loop within this network thread. More...
 
void update () override
 Updates the network thread and schedules a recursive call to itself. More...
 
virtual void initialize (int segment_number=1) override
 
virtual void finalize () override
 
virtual bool is_initialized () override
 
virtual bool is_finalized () override
 
- Public Member Functions inherited from KernelComponent
 KernelComponent (Kernel *kernel, Horizon::System::runtime_module_type module_type)
 
virtual void initialize (int segment_number=1)
 
virtual void finalize ()
 
virtual bool is_initialized ()
 
virtual bool is_finalized ()
 
void set_segment_number (int64_t segment_number)
 
int64_t get_segment_number ()
 
void system_routine_queue_push (std::shared_ptr< Horizon::System::RuntimeContext > context)
 
void system_routine_queue_push (std::shared_ptr< Horizon::System::RuntimeContextChain > context)
 
void system_routine_process_queue ()
 
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)
 
const std::string get_uuid_string ()
 
const std::string get_type_string ()
 
Horizon::System::SystemRoutineManagerget_system_routine_manager ()
 
Kernelget_kernel ()
 
void set_thread_cpu_id (int cpu_id)
 
int get_thread_cpu_id ()
 
void set_thread_update_rate (double rate)
 
double get_thread_update_rate ()
 
void set_total_execution_time (int time)
 
int get_total_execution_time ()
 
void calculate_and_set_cpu_load ()
 
- Public Member Functions inherited from Horizon::Networking::NetworkThread< ZoneSocket >
 NetworkThread ()
 
virtual ~NetworkThread ()
 Destructor of the network thread, performs a clean network finalisation routine before deleting. More...
 
virtual void finalize ()
 Halts the IO Service and marks the network thread as stopped. More...
 
void join ()
 
virtual bool start (int segment_number=1)
 Initializes the network thread and runs. More...
 
virtual void add_socket (std::shared_ptr< ZoneSocket > sock)
 Adds a new socket to a queue that is processed frequently within this network thread. More...
 
std::shared_ptr< tcp::socket > get_new_socket ()
 Gets a socket for a new connection. More...
 
int32_t connection_count () const
 Gets the total number of network connections or sockets handled by this network thread. More...
 
bool is_finalizing ()
 Issues the status of network thread whether it is finalizing or not. More...
 

Protected Types

using PrimaryResource = SharedPriorityResourceMedium< s_segment_storage< uint64_t, std::shared_ptr< ZoneSocket > > >
 
using ResourceManager = SharedPriorityResourceManager< PrimaryResource >
 

Protected Member Functions

void on_socket_removed (std::shared_ptr< ZoneSocket > socket) override
 
void on_socket_added (std::shared_ptr< ZoneSocket > socket) override
 
ResourceManagerget_resource_manager ()
 
- Protected Member Functions inherited from Horizon::Networking::NetworkThread< ZoneSocket >
virtual void run ()
 Run the I/O Service loop within this network thread. More...
 
virtual void on_socket_removed (std::shared_ptr< ZoneSocket > sock)=0
 
virtual void on_socket_added (std::shared_ptr< ZoneSocket > sock)=0
 
virtual void update ()
 Updates the network thread and schedules a recursive call to itself. More...
 
virtual void add_new_sockets ()
 Processess the new socket queue. More...
 

Protected Attributes

std::atomic< bool > _is_initialized {false}
 
std::atomic< bool > _is_finalized {false}
 
ResourceManager _resource_manager
 
- Protected Attributes inherited from Horizon::Networking::NetworkThread< ZoneSocket >
SocketContainer _active_sockets
 

Member Typedef Documentation

◆ PrimaryResource

◆ ResourceManager

Constructor & Destructor Documentation

◆ ZoneNetworkThread()

Horizon::Zone::ZoneNetworkThread::ZoneNetworkThread ( )
6_resource_manager(PrimaryResource(RESOURCE_PRIORITY_PRIMARY, std::make_shared<s_segment_storage<uint64_t, std::shared_ptr<ZoneSocket>>>()))
7{
8}
@ RESOURCE_PRIORITY_PRIMARY
Definition: Server.hpp:79
#define sZone
Definition: Zone.hpp:247
SharedPriorityResourceMedium< s_segment_storage< uint64_t, std::shared_ptr< ZoneSocket > > > PrimaryResource
Definition: ClientSocketMgr.hpp:122
ResourceManager _resource_manager
Definition: ClientSocketMgr.hpp:124
KernelComponent(Kernel *kernel, Horizon::System::runtime_module_type module_type)
Definition: Server.hpp:194
@ RUNTIME_NETWORKING
Definition: System.hpp:84
Definition: Server.hpp:93

Member Function Documentation

◆ finalize()

virtual void Horizon::Zone::ZoneNetworkThread::finalize ( )
inlineoverridevirtual

Reimplemented from KernelComponent.

111 {
113 _is_finalized.exchange(true);
114 }
virtual void finalize()
Halts the IO Service and marks the network thread as stopped.
Definition: NetworkThread.hpp:76
std::atomic< bool > _is_finalized
Definition: ClientSocketMgr.hpp:120

References _is_finalized, and Horizon::Networking::NetworkThread< SocketType >::finalize().

+ Here is the call graph for this function:

◆ get_resource_manager()

ResourceManager & Horizon::Zone::ZoneNetworkThread::get_resource_manager ( )
inlineprotected
126{ return _resource_manager; }

References _resource_manager.

Referenced by on_socket_added(), and on_socket_removed().

+ Here is the caller graph for this function:

◆ initialize()

virtual void Horizon::Zone::ZoneNetworkThread::initialize ( int  segment_number = 1)
inlineoverridevirtual

Reimplemented from KernelComponent.

104 {
105 set_segment_number(segment_number);
106
107 _is_initialized.exchange(true);
108 }
std::atomic< bool > _is_initialized
Definition: ClientSocketMgr.hpp:119
void set_segment_number(int64_t segment_number)
Definition: Server.hpp:206

References _is_initialized, and KernelComponent::set_segment_number().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_finalized()

virtual bool Horizon::Zone::ZoneNetworkThread::is_finalized ( )
inlineoverridevirtual

Reimplemented from KernelComponent.

117{ return _is_finalized.load(); }

References _is_finalized.

◆ is_initialized()

virtual bool Horizon::Zone::ZoneNetworkThread::is_initialized ( )
inlineoverridevirtual

Reimplemented from KernelComponent.

116{ return _is_initialized.load(); }

References _is_initialized.

◆ on_socket_added()

void Horizon::Zone::ZoneNetworkThread::on_socket_added ( std::shared_ptr< ZoneSocket socket)
inlineoverrideprotected
60 {
61 get_resource_manager().remove<RESOURCE_PRIORITY_PRIMARY>(socket->get_socket_id());
62 }
ResourceManager & get_resource_manager()
Definition: ClientSocketMgr.hpp:126
void remove(Key key)
Definition: Server.hpp:163

References get_resource_manager(), SharedPriorityResourceManager< SharedPriorityResourceMediums >::remove(), and RESOURCE_PRIORITY_PRIMARY.

+ Here is the call graph for this function:

◆ on_socket_removed()

void Horizon::Zone::ZoneNetworkThread::on_socket_removed ( std::shared_ptr< ZoneSocket socket)
inlineoverrideprotected
55 {
56 get_resource_manager().add<RESOURCE_PRIORITY_PRIMARY>(socket->get_socket_id(), socket);
57 }
void add(Key key, Value value)
Definition: Server.hpp:157

References SharedPriorityResourceManager< SharedPriorityResourceMediums >::add(), get_resource_manager(), and RESOURCE_PRIORITY_PRIMARY.

+ Here is the call graph for this function:

◆ run()

void Horizon::Zone::ZoneNetworkThread::run ( )
inlineoverridevirtual

Run the I/O Service loop within this network thread.

Before running, this method gives the I/O service some work by asynchronously running a deadline timer on

See also
update()

Reimplemented from Horizon::Networking::NetworkThread< ZoneSocket >.

76 {
78 }
virtual void run()
Run the I/O Service loop within this network thread.
Definition: NetworkThread.hpp:143

References Horizon::Networking::NetworkThread< SocketType >::run().

+ Here is the call graph for this function:

◆ start()

bool Horizon::Zone::ZoneNetworkThread::start ( int  segment_number = 1)
inlineoverridevirtual

Initializes the network thread and runs.

Returns
true on success, false if thread is a nullptr.

Reimplemented from Horizon::Networking::NetworkThread< ZoneSocket >.

67 {
69 return false;
70
71 initialize(segment_number);
72 return true;
73 }
virtual bool start(int segment_number=1)
Initializes the network thread and runs.
Definition: NetworkThread.hpp:94
virtual void initialize(int segment_number=1) override
Definition: ClientSocketMgr.hpp:103

References initialize().

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

void Horizon::Zone::ZoneNetworkThread::update ( )
inlineoverridevirtual

Updates the network thread and schedules a recursive call to itself.

This method is responsible for the following tasks - 1) Issuing a routine to process the new sockets queue. 2) Closes sockets that cannot be updated.

See also
Socket<SocketType>::update()

Reimplemented from Horizon::Networking::NetworkThread< ZoneSocket >.

82 {
83 std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
85
87
88#if WIN32
89 DWORD cpu = GetCurrentProcessorNumber();
90 if (get_thread_cpu_id() != (int) cpu)
92#elif __linux__
93 int cpu = sched_getcpu();
94 if (get_thread_cpu_id() != cpu)
96#endif
98 std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
99 std::chrono::nanoseconds time_span = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start);
100 set_total_execution_time(time_span.count());
101 }
virtual void update()
Updates the network thread and schedules a recursive call to itself.
Definition: NetworkThread.hpp:163
void process_queue()
Definition: System.hpp:676
bool start(int segment_number=1) override
Initializes the network thread and runs.
Definition: ClientSocketMgr.hpp:66
void set_thread_cpu_id(int cpu_id)
Definition: Server.hpp:239
Horizon::System::SystemRoutineManager & get_system_routine_manager()
Definition: Server.hpp:235
void set_total_execution_time(int time)
Definition: Server.hpp:245
void calculate_and_set_cpu_load()
Definition: Server.hpp:257
int get_thread_cpu_id()
Definition: Server.hpp:240

References KernelComponent::calculate_and_set_cpu_load(), KernelComponent::get_system_routine_manager(), KernelComponent::get_thread_cpu_id(), Horizon::System::SystemRoutineManager::process_queue(), KernelComponent::set_thread_cpu_id(), KernelComponent::set_total_execution_time(), start(), and Horizon::Networking::NetworkThread< SocketType >::update().

+ Here is the call graph for this function:

Member Data Documentation

◆ _is_finalized

std::atomic<bool> Horizon::Zone::ZoneNetworkThread::_is_finalized {false}
protected

Referenced by finalize(), and is_finalized().

◆ _is_initialized

std::atomic<bool> Horizon::Zone::ZoneNetworkThread::_is_initialized {false}
protected

Referenced by initialize(), and is_initialized().

◆ _resource_manager

ResourceManager Horizon::Zone::ZoneNetworkThread::_resource_manager
protected

Referenced by get_resource_manager().


The documentation for this class was generated from the following files: