Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::interfaces::IExecutor Interface Referenceabstractexport

Abstract interface for task execution systems. More...

#include <executor_interface.h>

Inheritance diagram for kcenon::common::interfaces::IExecutor:
Inheritance graph
Collaboration diagram for kcenon::common::interfaces::IExecutor:
Collaboration graph

Public Member Functions

virtual ~IExecutor ()=default
 
virtual Result< std::future< void > > execute (std::unique_ptr< IJob > &&job)=0
 Execute a job with Result-based error handling.
 
virtual Result< std::future< void > > execute_delayed (std::unique_ptr< IJob > &&job, std::chrono::milliseconds delay)=0
 Execute a job with delay.
 
virtual size_t worker_count () const =0
 Get the number of worker threads.
 
virtual bool is_running () const =0
 Check if the executor is running.
 
virtual size_t pending_tasks () const =0
 Get the number of pending tasks.
 
virtual void shutdown (bool wait_for_completion=true)=0
 Shutdown the executor gracefully.
 
virtual ~IExecutor ()=default
 
virtual Result< std::future< void > > execute (std::unique_ptr< IJob > &&job)=0
 Execute a job with Result-based error handling.
 
virtual Result< std::future< void > > execute_delayed (std::unique_ptr< IJob > &&job, std::chrono::milliseconds delay)=0
 Execute a job with delay.
 
virtual size_t worker_count () const =0
 Get the number of worker threads.
 
virtual bool is_running () const =0
 Check if the executor is running.
 
virtual size_t pending_tasks () const =0
 Get the number of pending tasks.
 
virtual void shutdown (bool wait_for_completion=true)=0
 Shutdown the executor gracefully.
 

Detailed Description

Abstract interface for task execution systems.

This interface defines the contract for any task executor implementation, allowing modules to work with different threading backends without direct dependencies.

Extended with job-based execution support for better control and testability.

// Submit a task to an executor
std::shared_ptr<IExecutor> executor = provider->get_executor();
executor->execute([] { std::cout << "Hello from thread pool\n"; });
// Submit a delayed task
executor->execute_delayed(std::chrono::seconds(5),
[] { std::cout << "Delayed task\n"; });
Examples
executor_example.cpp, and multi_system_app/main.cpp.

Definition at line 80 of file executor.cppm.

Constructor & Destructor Documentation

◆ ~IExecutor() [1/2]

virtual kcenon::common::interfaces::IExecutor::~IExecutor ( )
virtualdefault

◆ ~IExecutor() [2/2]

virtual kcenon::common::interfaces::IExecutor::~IExecutor ( )
exportvirtualdefault

Member Function Documentation

◆ execute() [1/2]

virtual Result< std::future< void > > kcenon::common::interfaces::IExecutor::execute ( std::unique_ptr< IJob > && job)
pure virtual

Execute a job with Result-based error handling.

Parameters
jobThe job to execute
Returns
Result containing future or error

Job-based execution provides better control and testability

Implemented in mock_executor.

Examples
executor_example.cpp.

Referenced by process_data_batch().

Here is the caller graph for this function:

◆ execute() [2/2]

virtual Result< std::future< void > > kcenon::common::interfaces::IExecutor::execute ( std::unique_ptr< IJob > && job)
exportpure virtual

Execute a job with Result-based error handling.

Implemented in mock_executor.

◆ execute_delayed() [1/2]

virtual Result< std::future< void > > kcenon::common::interfaces::IExecutor::execute_delayed ( std::unique_ptr< IJob > && job,
std::chrono::milliseconds delay )
pure virtual

Execute a job with delay.

Parameters
jobThe job to execute
delayThe delay before execution
Returns
Result containing future or error

Implemented in mock_executor.

Examples
executor_example.cpp.

◆ execute_delayed() [2/2]

virtual Result< std::future< void > > kcenon::common::interfaces::IExecutor::execute_delayed ( std::unique_ptr< IJob > && job,
std::chrono::milliseconds delay )
exportpure virtual

Execute a job with delay.

Implemented in mock_executor.

◆ is_running() [1/2]

virtual bool kcenon::common::interfaces::IExecutor::is_running ( ) const
pure virtual

Check if the executor is running.

Returns
true if running, false otherwise

Implemented in mock_executor.

Examples
executor_example.cpp.

◆ is_running() [2/2]

virtual bool kcenon::common::interfaces::IExecutor::is_running ( ) const
exportpure virtual

Check if the executor is running.

Implemented in mock_executor.

◆ pending_tasks() [1/2]

virtual size_t kcenon::common::interfaces::IExecutor::pending_tasks ( ) const
pure virtual

Get the number of pending tasks.

Returns
Number of tasks waiting to be executed

Implemented in mock_executor.

Examples
executor_example.cpp.

◆ pending_tasks() [2/2]

virtual size_t kcenon::common::interfaces::IExecutor::pending_tasks ( ) const
exportpure virtual

Get the number of pending tasks.

Implemented in mock_executor.

◆ shutdown() [1/2]

virtual void kcenon::common::interfaces::IExecutor::shutdown ( bool wait_for_completion = true)
pure virtual

Shutdown the executor gracefully.

Parameters
wait_for_completionWait for all pending tasks to complete

Implemented in mock_executor.

Examples
executor_example.cpp.

◆ shutdown() [2/2]

virtual void kcenon::common::interfaces::IExecutor::shutdown ( bool wait_for_completion = true)
exportpure virtual

Shutdown the executor gracefully.

Implemented in mock_executor.

◆ worker_count() [1/2]

virtual size_t kcenon::common::interfaces::IExecutor::worker_count ( ) const
pure virtual

Get the number of worker threads.

Returns
Number of available workers

Implemented in mock_executor.

Examples
executor_example.cpp.

Referenced by process_data_batch().

Here is the caller graph for this function:

◆ worker_count() [2/2]

virtual size_t kcenon::common::interfaces::IExecutor::worker_count ( ) const
exportpure virtual

Get the number of worker threads.

Implemented in mock_executor.


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