Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::service::SystemBalanceLoader Class Referencefinal

System Balance Loader (non-user scheduled loader) More...

#include <SystemBalanceLoader.h>

Public Member Functions

 ~SystemBalanceLoader () noexcept
 
void setThreads (size_t th) noexcept
 
void setAddress (const net::IPAddress::Ptr &addr) noexcept
 
void setAcceptTimeout (uint32_t to) noexcept
 
void setDispatchTimeout (uint32_t to) noexcept
 
bool isStarted () const
 
template<class SERVICE >
bool init () noexcept
 
template<class SERVICE >
bool init (std::function< SERVICE *()> creator) noexcept
 
void start () noexcept
 Start the current loader and service.
 
void stop () noexcept
 Shut down the current loader and unload the service.
 

Protected Attributes

std::atomic_bool _isStart {false}
 
std::atomic_bool _isStop {false}
 
uint32_t timeout = 100
 
size_t threads {2}
 
std::vector< socket_tsocketVector
 
std::vector< event::EventLoop * > eventLoopVector
 
std::vector< sese::Thread::PtrthreadVector
 
sese::net::IPAddress::Ptr address = sese::net::IPv4Address::localhost(8080)
 

Detailed Description

System Balance Loader (non-user scheduled loader)

Warning
This loader is effective only on Linux
See also
sese::service::BalanceLoader

Constructor & Destructor Documentation

◆ ~SystemBalanceLoader()

sese::service::SystemBalanceLoader::~SystemBalanceLoader ( )
noexcept

Member Function Documentation

◆ init() [1/2]

template<class SERVICE >
bool sese::service::SystemBalanceLoader::init ( )
noexcept

Initialize loader resources

Template Parameters
SERVICEThe service to be started
Returns
Whether the initialization was successful

References init().

Referenced by init().

◆ init() [2/2]

template<class SERVICE >
bool sese::service::SystemBalanceLoader::init ( std::function< SERVICE *()> creator)
noexcept

Initialize balancer resources

Template Parameters
SERVICEThe service to be started
Parameters
creatorService creation function, which returns an instance pointer if creation is successful, otherwise should return nullptr indicating failure
Returns
Whether the initialization was successful

References sese::net::Socket::close(), sese::net::Socket::listen(), sese::net::ReusableSocket::makeRawSocket(), and sese::net::Socket::setNonblocking().

◆ isStarted()

bool sese::service::SystemBalanceLoader::isStarted ( ) const
inlinenodiscard

Get the current loader status

Returns
The status of the loader

References _isStart.

◆ setAcceptTimeout()

void sese::service::SystemBalanceLoader::setAcceptTimeout ( uint32_t to)
inlinenoexcept

Set the timeout for dispatching from threads

Parameters
toTimeout in milliseconds

References timeout.

◆ setAddress()

void sese::service::SystemBalanceLoader::setAddress ( const net::IPAddress::Ptr & addr)
inlinenoexcept

Set the service startup address

Parameters
addrIP Address

References address.

◆ setDispatchTimeout()

void sese::service::SystemBalanceLoader::setDispatchTimeout ( uint32_t to)
inlinenoexcept

Set the timeout for dispatching from threads

Parameters
toTimeout in milliseconds

References timeout.

◆ setThreads()

void sese::service::SystemBalanceLoader::setThreads ( size_t th)
noexcept

Set the number of threads used by the loader

Parameters
thNumber of threads

◆ start()

void sese::service::SystemBalanceLoader::start ( )
noexcept

Start the current loader and service.

◆ stop()

void sese::service::SystemBalanceLoader::stop ( )
noexcept

Shut down the current loader and unload the service.

References sese::net::Socket::close().

Referenced by ~SystemBalanceLoader().

Member Data Documentation

◆ _isStart

std::atomic_bool sese::service::SystemBalanceLoader::_isStart {false}
protected

Referenced by isStarted(), and ~SystemBalanceLoader().

◆ _isStop

std::atomic_bool sese::service::SystemBalanceLoader::_isStop {false}
protected

Referenced by ~SystemBalanceLoader().

◆ address

sese::net::IPAddress::Ptr sese::service::SystemBalanceLoader::address = sese::net::IPv4Address::localhost(8080)
protected

Referenced by setAddress().

◆ eventLoopVector

std::vector<event::EventLoop *> sese::service::SystemBalanceLoader::eventLoopVector
protected

Referenced by ~SystemBalanceLoader().

◆ socketVector

std::vector<socket_t> sese::service::SystemBalanceLoader::socketVector
protected

Referenced by ~SystemBalanceLoader().

◆ threads

size_t sese::service::SystemBalanceLoader::threads {2}
protected

◆ threadVector

std::vector<sese::Thread::Ptr> sese::service::SystemBalanceLoader::threadVector
protected

◆ timeout

uint32_t sese::service::SystemBalanceLoader::timeout = 100
protected

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