cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
msgpack_rpc::executors::GeneralExecutor Class Referencefinal

Class of general-purpose executors. More...

Inheritance diagram for msgpack_rpc::executors::GeneralExecutor:
Collaboration diagram for msgpack_rpc::executors::GeneralExecutor:

Classes

struct  ContextThreadPair
 Pair of context and its thread. More...

Public Member Functions

 GeneralExecutor (const GeneralExecutor &)=delete
 GeneralExecutor (GeneralExecutor &&)=delete
 GeneralExecutor (std::shared_ptr< logging::Logger > logger, const config::ExecutorConfig &config)
 Constructor.
 ~GeneralExecutor () override
 Destructor.
AsioContextTypecontext (OperationType type) noexcept override
 Get the context in asio library.
bool is_running () override
 Check whether this executor is running.
std::exception_ptr last_exception () override
 Get the last exception thrown in asynchronous tasks.
void on_exception (std::function< void(std::exception_ptr)> exception_callback) override
 Register a function called when an exception is thrown in asynchronous tasks.
GeneralExecutoroperator= (const GeneralExecutor &)=delete
GeneralExecutoroperator= (GeneralExecutor &&)=delete
void start () override
 Start internal event loops to process asynchronous tasks.
void stop () override
 Stops operation.
Public Member Functions inherited from msgpack_rpc::executors::IAsyncExecutor
 IAsyncExecutor (const IAsyncExecutor &)=delete
 IAsyncExecutor (IAsyncExecutor &&)=delete
 ~IAsyncExecutor () noexcept override=default
 Destructor.
IAsyncExecutoroperator= (const IAsyncExecutor &)=delete
IAsyncExecutoroperator= (IAsyncExecutor &&)=delete
Public Member Functions inherited from msgpack_rpc::executors::IExecutor
 IExecutor (const IExecutor &)=delete
 IExecutor (IExecutor &&)=delete
virtual ~IExecutor () noexcept=default
 Destructor.
IExecutoroperator= (const IExecutor &)=delete
IExecutoroperator= (IExecutor &&)=delete

Private Member Functions

void async_stop_threads_gently ()
 Notify threads to stop operations gently.
void interrupt_threads ()
 Notify threads to stop operations.
void run_in_thread (AsioContextType &context)
 Run operations in a thread.
void start_threads ()
 Start threads.
void stop_threads ()
 Stop threads.

Static Private Member Functions

static std::string create_thread_id_string ()
 Create a string of the current thread ID.
static std::size_t get_context_index (std::atomic< std::size_t > &index, std::size_t size)
 Get the index of context to use.

Private Attributes

std::atomic< std::size_t > callback_context_index_ {0}
 Index of context to use for callbacks.
std::vector< ContextThreadPaircallbacks_context_thread_pairs_
 List of pairs of context and its thread for callbacks.
std::vector< std::function< void(std::exception_ptr)> > exception_callbacks_ {}
 Functions called when an exception is thrown.
std::mutex exception_callbacks_mutex_ {}
 Mutex of exception_callbacks_.
std::exception_ptr exception_in_thread_ {}
 Exception thrown in threads.
std::mutex exception_in_thread_mutex_ {}
 Mutex of exception_in_thread_.
std::atomic< bool > is_started_ {false}
 Whether this executor has been started.
std::atomic< bool > is_stopped_ {false}
 Whether this executor has been stopped.
std::shared_ptr< logging::Loggerlogger_
 Logger.
std::atomic< std::size_t > transport_context_index_ {0}
 Index of context to use for transport.
std::vector< ContextThreadPairtransport_context_thread_pairs_
 List of pairs of context and its thread for transport.

Additional Inherited Members

Protected Member Functions inherited from msgpack_rpc::executors::IAsyncExecutor
 IAsyncExecutor () noexcept=default
 Constructor.
Protected Member Functions inherited from msgpack_rpc::executors::IExecutor
 IExecutor () noexcept=default
 Constructor.

Detailed Description

Class of general-purpose executors.

Definition at line 47 of file general_executor.cpp.

Constructor & Destructor Documentation

◆ GeneralExecutor()

msgpack_rpc::executors::GeneralExecutor::GeneralExecutor ( std::shared_ptr< logging::Logger > logger,
const config::ExecutorConfig & config )
inline

Constructor.

Parameters
[in]loggerLogger.
[in]configConfiguration.

Definition at line 55 of file general_executor.cpp.

◆ ~GeneralExecutor()

msgpack_rpc::executors::GeneralExecutor::~GeneralExecutor ( )
inlineoverride

Destructor.

Definition at line 69 of file general_executor.cpp.

Member Function Documentation

◆ async_stop_threads_gently()

void msgpack_rpc::executors::GeneralExecutor::async_stop_threads_gently ( )
inlineprivate

Notify threads to stop operations gently.

Definition at line 195 of file general_executor.cpp.

◆ context()

AsioContextType & msgpack_rpc::executors::GeneralExecutor::context ( OperationType type)
inlineoverridevirtualnoexcept

Get the context in asio library.

Parameters
[in]typeOperation type.
Returns
Context.
Note
Implementation can return different objects for multiple function calls and different operation types.

Implements msgpack_rpc::executors::IExecutor.

Definition at line 99 of file general_executor.cpp.

◆ create_thread_id_string()

std::string msgpack_rpc::executors::GeneralExecutor::create_thread_id_string ( )
inlinestaticprivate

Create a string of the current thread ID.

Returns
String of the current thread ID.

Definition at line 239 of file general_executor.cpp.

◆ get_context_index()

std::size_t msgpack_rpc::executors::GeneralExecutor::get_context_index ( std::atomic< std::size_t > & index,
std::size_t size )
inlinestaticprivate

Get the index of context to use.

Parameters
[in]indexAtomic variable of the index of context.
[in]sizeNumber of context.
Returns
Index of context to use.

Definition at line 252 of file general_executor.cpp.

◆ interrupt_threads()

void msgpack_rpc::executors::GeneralExecutor::interrupt_threads ( )
inlineprivate

Notify threads to stop operations.

Definition at line 183 of file general_executor.cpp.

◆ is_running()

bool msgpack_rpc::executors::GeneralExecutor::is_running ( )
inlinenodiscardoverridevirtual

Check whether this executor is running.

Return values
trueThis executor is running.
falseThis executor is not running.

Implements msgpack_rpc::executors::IAsyncExecutor.

Definition at line 130 of file general_executor.cpp.

◆ last_exception()

std::exception_ptr msgpack_rpc::executors::GeneralExecutor::last_exception ( )
inlinenodiscardoverridevirtual

Get the last exception thrown in asynchronous tasks.

Returns
Pointer of the exception.

Implements msgpack_rpc::executors::IAsyncExecutor.

Definition at line 117 of file general_executor.cpp.

◆ on_exception()

void msgpack_rpc::executors::GeneralExecutor::on_exception ( std::function< void(std::exception_ptr)> exception_callback)
inlineoverridevirtual

Register a function called when an exception is thrown in asynchronous tasks.

Parameters
[in]exception_callbackFunction called when an exception is thrown in asynchronous tasks. The pointer of the exception is passed as an argument.

Implements msgpack_rpc::executors::IAsyncExecutor.

Definition at line 123 of file general_executor.cpp.

◆ run_in_thread()

void msgpack_rpc::executors::GeneralExecutor::run_in_thread ( AsioContextType & context)
inlineprivate

Run operations in a thread.

Parameters
[in]contextContext for this thread.

Definition at line 209 of file general_executor.cpp.

◆ start()

void msgpack_rpc::executors::GeneralExecutor::start ( )
inlineoverridevirtual

Start internal event loops to process asynchronous tasks.

Note
Internal processing stops
  • when a task throws an exception, which can be retrieved from last_exception function,
  • when stop function is called.

Implements msgpack_rpc::executors::IAsyncExecutor.

Definition at line 72 of file general_executor.cpp.

◆ start_threads()

void msgpack_rpc::executors::GeneralExecutor::start_threads ( )
inlineprivate

Start threads.

Definition at line 143 of file general_executor.cpp.

◆ stop()

void msgpack_rpc::executors::GeneralExecutor::stop ( )
inlineoverridevirtual

Stops operation.

Warning
This function stops internal threads. Do not call this function from callbacks called in this executor.

Implements msgpack_rpc::executors::IAsyncExecutor.

Definition at line 83 of file general_executor.cpp.

◆ stop_threads()

void msgpack_rpc::executors::GeneralExecutor::stop_threads ( )
inlineprivate

Stop threads.

Definition at line 166 of file general_executor.cpp.

Member Data Documentation

◆ callback_context_index_

std::atomic<std::size_t> msgpack_rpc::executors::GeneralExecutor::callback_context_index_ {0}
private

Index of context to use for callbacks.

Definition at line 285 of file general_executor.cpp.

◆ callbacks_context_thread_pairs_

std::vector<ContextThreadPair> msgpack_rpc::executors::GeneralExecutor::callbacks_context_thread_pairs_
private

List of pairs of context and its thread for callbacks.

Definition at line 279 of file general_executor.cpp.

◆ exception_callbacks_

std::vector<std::function<void(std::exception_ptr)> > msgpack_rpc::executors::GeneralExecutor::exception_callbacks_ {}
private

Functions called when an exception is thrown.

Definition at line 300 of file general_executor.cpp.

◆ exception_callbacks_mutex_

std::mutex msgpack_rpc::executors::GeneralExecutor::exception_callbacks_mutex_ {}
private

Mutex of exception_callbacks_.

Definition at line 303 of file general_executor.cpp.

◆ exception_in_thread_

std::exception_ptr msgpack_rpc::executors::GeneralExecutor::exception_in_thread_ {}
private

Exception thrown in threads.

Definition at line 294 of file general_executor.cpp.

◆ exception_in_thread_mutex_

std::mutex msgpack_rpc::executors::GeneralExecutor::exception_in_thread_mutex_ {}
private

Mutex of exception_in_thread_.

Definition at line 297 of file general_executor.cpp.

◆ is_started_

std::atomic<bool> msgpack_rpc::executors::GeneralExecutor::is_started_ {false}
private

Whether this executor has been started.

Definition at line 288 of file general_executor.cpp.

◆ is_stopped_

std::atomic<bool> msgpack_rpc::executors::GeneralExecutor::is_stopped_ {false}
private

Whether this executor has been stopped.

Definition at line 291 of file general_executor.cpp.

◆ logger_

std::shared_ptr<logging::Logger> msgpack_rpc::executors::GeneralExecutor::logger_
private

Logger.

Definition at line 306 of file general_executor.cpp.

◆ transport_context_index_

std::atomic<std::size_t> msgpack_rpc::executors::GeneralExecutor::transport_context_index_ {0}
private

Index of context to use for transport.

Definition at line 282 of file general_executor.cpp.

◆ transport_context_thread_pairs_

std::vector<ContextThreadPair> msgpack_rpc::executors::GeneralExecutor::transport_context_thread_pairs_
private

List of pairs of context and its thread for transport.

Definition at line 276 of file general_executor.cpp.


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