7#if KCENON_WITH_COMMON_SYSTEM
14 std::shared_ptr<thread_pool_interface> pool,
BackendType backend_type) {
18 "ThreadPoolBridge requires non-null thread pool",
19 "ThreadPoolBridge::create");
21 return ok(std::shared_ptr<ThreadPoolBridge>(
26 std::shared_ptr<thread_pool_interface> pool,
28 : pool_(std::move(pool)), backend_type_(backend_type) {
41 "ThreadPoolBridge already initialized",
42 "ThreadPoolBridge::initialize");
48 "Thread pool is null",
49 "ThreadPoolBridge::initialize");
52 if (!
pool_->is_running()) {
55 "Thread pool is not running",
56 "ThreadPoolBridge::initialize");
60 auto enabled_it =
config.properties.find(
"enabled");
61 if (enabled_it !=
config.properties.end() && enabled_it->second ==
"false") {
64 "Bridge is disabled in configuration",
65 "ThreadPoolBridge::initialize");
133 const std::string& pool_name) {
139 "Failed to get thread pool from thread_integration_manager",
140 "ThreadPoolBridge::from_thread_system");
145#if KCENON_WITH_COMMON_SYSTEM
147 std::shared_ptr<::kcenon::common::interfaces::IExecutor> executor) {
151 "ThreadPoolBridge::from_common_system requires non-null executor",
152 "ThreadPoolBridge::from_common_system");
154 auto adapter_result = common_to_network_thread_adapter::create(std::move(executor));
155 if (adapter_result.is_err()) {
157 adapter_result.error().
code, adapter_result.error().message,
158 "ThreadPoolBridge::from_common_system");
static Result< std::shared_ptr< ThreadPoolBridge > > from_thread_system(const std::string &pool_name="network_pool")
Create bridge from thread_system.
BackendType get_backend_type() const
Get the backend type.
VoidResult shutdown() override
Shutdown the bridge.
std::mutex metrics_mutex_
static Result< std::shared_ptr< ThreadPoolBridge > > create(std::shared_ptr< thread_pool_interface > pool, BackendType backend_type=BackendType::Custom)
Construct bridge with custom thread pool.
BackendType
Type of thread pool backend.
@ ThreadSystem
Uses thread_system's thread pool.
@ CommonSystem
Uses common_system's IExecutor.
BackendType backend_type_
bool is_initialized() const override
Check if the bridge is initialized.
std::shared_ptr< thread_pool_interface > pool_
ThreadPoolBridge(std::shared_ptr< thread_pool_interface > pool, BackendType backend_type)
std::shared_ptr< thread_pool_interface > get_thread_pool() const
Get the underlying thread pool.
BridgeMetrics get_metrics() const override
Get current metrics.
BridgeMetrics cached_metrics_
~ThreadPoolBridge() override
Destructor.
VoidResult initialize(const BridgeConfig &config) override
Initialize the bridge with configuration.
std::atomic< bool > initialized_
static thread_integration_manager & instance()
Get the singleton instance.
std::shared_ptr< thread_pool_interface > get_thread_pool()
Get the current thread pool.
constexpr int invalid_argument
constexpr int not_initialized
constexpr int already_exists
VoidResult error_void(int code, const std::string &message, const std::string &source="network_system", const std::string &details="")
Configuration for bridge initialization.
Metrics and health information for a bridge.
std::chrono::steady_clock::time_point last_activity
Timestamp of last activity or health check.
std::map< std::string, double > custom_metrics
Bridge-specific custom metrics.
bool is_healthy
Overall health status of the bridge.
Bidirectional adapters between network_system's thread_pool_interface and common_system's IExecutor/I...
Thread pool integration bridge for network_system.