8#if KCENON_WITH_COMMON_SYSTEM
10#include <kcenon/common/interfaces/monitoring_interface.h>
29 std::lock_guard<std::mutex> lock(
mutex_);
34 "NetworkSystemBridge already initialized",
35 "NetworkSystemBridge::initialize");
48 if (result.is_err()) {
51 "Failed to initialize thread pool bridge: " + result.error().message,
52 "NetworkSystemBridge::initialize");
74 std::lock_guard<std::mutex> lock(
mutex_);
100 std::lock_guard<std::mutex> lock(
mutex_);
109 aggregated.
is_healthy &= thread_metrics.is_healthy;
111 for (
const auto& [key, value] : thread_metrics.custom_metrics) {
122 std::lock_guard<std::mutex> lock(
mutex_);
127 std::lock_guard<std::mutex> lock(
mutex_);
135 std::lock_guard<std::mutex> lock(
mutex_);
140 std::lock_guard<std::mutex> lock(
mutex_);
145 std::lock_guard<std::mutex> lock(
mutex_);
150 "Cannot set thread pool bridge after initialization",
151 "NetworkSystemBridge::set_thread_pool_bridge");
157 "Thread pool bridge cannot be null",
158 "NetworkSystemBridge::set_thread_pool_bridge");
166 std::lock_guard<std::mutex> lock(
mutex_);
171 "Cannot set logger after initialization",
172 "NetworkSystemBridge::set_logger");
180 std::lock_guard<std::mutex> lock(
mutex_);
185 "Cannot set monitoring after initialization",
186 "NetworkSystemBridge::set_monitoring");
207 : pimpl_(std::make_unique<
Impl>()) {
211 : pimpl_(std::make_unique<
Impl>()) {
212 pimpl_->set_thread_pool_bridge(std::move(thread_pool));
224 "Bridge has been moved",
225 "NetworkSystemBridge::initialize");
227 return pimpl_->initialize(
config);
234 return pimpl_->shutdown();
241 return pimpl_->is_initialized();
248 return pimpl_->get_metrics();
255 return pimpl_->get_thread_pool_bridge();
262 return pimpl_->get_thread_pool();
269 return pimpl_->get_logger();
276 return pimpl_->get_monitoring();
283 "Bridge has been moved",
284 "NetworkSystemBridge::set_thread_pool_bridge");
286 return pimpl_->set_thread_pool_bridge(std::move(
bridge));
293 "Bridge has been moved",
294 "NetworkSystemBridge::set_logger");
296 return pimpl_->set_logger(std::move(logger));
303 "Bridge has been moved",
304 "NetworkSystemBridge::set_monitoring");
306 return pimpl_->set_monitoring(std::move(monitoring));
312 auto bridge = std::make_shared<NetworkSystemBridge>();
315#if KCENON_WITH_THREAD_SYSTEM
317 bridge->set_thread_pool_bridge(thread_pool_bridge);
324 const std::string& pool_name) {
325 auto bridge = std::make_shared<NetworkSystemBridge>();
327#if KCENON_WITH_THREAD_SYSTEM
329 bridge->set_thread_pool_bridge(thread_pool_bridge);
335#if KCENON_WITH_COMMON_SYSTEM
336std::shared_ptr<NetworkSystemBridge> NetworkSystemBridge::with_common_system(
337 std::shared_ptr<::kcenon::common::interfaces::IExecutor> executor,
338 std::shared_ptr<::kcenon::common::interfaces::ILogger> logger,
339 std::shared_ptr<::kcenon::common::interfaces::IMonitor> monitor) {
341 auto bridge = std::make_shared<NetworkSystemBridge>();
345 auto thread_pool_bridge = ThreadPoolBridge::from_common_system(executor);
346 bridge->set_thread_pool_bridge(thread_pool_bridge);
351 auto logger_adapter = std::make_shared<common_logger_adapter>(logger);
352 bridge->set_logger(logger_adapter);
357 auto monitoring_adapter = std::make_shared<common_monitoring_adapter>(monitor);
358 bridge->set_monitoring(monitoring_adapter);
366 std::shared_ptr<thread_pool_interface> thread_pool,
367 std::shared_ptr<logger_interface> logger,
368 std::shared_ptr<monitoring_interface> monitoring) {
370 auto bridge = std::make_shared<NetworkSystemBridge>();
373 auto thread_pool_bridge = std::make_shared<ThreadPoolBridge>(
375 bridge->set_thread_pool_bridge(thread_pool_bridge);
379 bridge->set_logger(logger);
383 bridge->set_monitoring(monitoring);
BridgeMetrics get_metrics() const
std::shared_ptr< thread_pool_interface > get_thread_pool() const
bool is_initialized() const
std::shared_ptr< monitoring_interface > get_monitoring() const
std::shared_ptr< ThreadPoolBridge > thread_pool_bridge_
VoidResult initialize(const NetworkSystemBridgeConfig &config)
VoidResult set_thread_pool_bridge(std::shared_ptr< ThreadPoolBridge > bridge)
std::shared_ptr< logger_interface > get_logger() const
std::atomic< bool > initialized_
VoidResult set_monitoring(std::shared_ptr< monitoring_interface > monitoring)
std::shared_ptr< monitoring_interface > monitoring_
std::shared_ptr< logger_interface > logger_
std::vector< std::string > initialized_bridges_
std::shared_ptr< ThreadPoolBridge > get_thread_pool_bridge() const
NetworkSystemBridgeConfig config_
VoidResult set_logger(std::shared_ptr< logger_interface > logger)
Unified facade for all network_system integration bridges.
~NetworkSystemBridge()
Destructor.
static std::shared_ptr< NetworkSystemBridge > create_default()
Create bridge with default configuration.
std::shared_ptr< thread_pool_interface > get_thread_pool() const
Get thread pool interface.
std::shared_ptr< logger_interface > get_logger() const
Get logger interface.
static std::shared_ptr< NetworkSystemBridge > with_custom(std::shared_ptr< thread_pool_interface > thread_pool=nullptr, std::shared_ptr< logger_interface > logger=nullptr, std::shared_ptr< monitoring_interface > monitoring=nullptr)
Create bridge with custom components.
std::unique_ptr< Impl > pimpl_
VoidResult set_thread_pool_bridge(std::shared_ptr< ThreadPoolBridge > bridge)
Set custom thread pool bridge.
bool is_initialized() const
Check if the bridge is initialized.
std::shared_ptr< ThreadPoolBridge > get_thread_pool_bridge() const
Get thread pool bridge.
BridgeMetrics get_metrics() const
Get aggregated metrics from all bridges.
static std::shared_ptr< NetworkSystemBridge > with_thread_system(const std::string &pool_name="network_pool")
Create bridge with thread_system integration.
std::shared_ptr< monitoring_interface > get_monitoring() const
Get monitoring interface.
VoidResult shutdown()
Shutdown all bridges.
VoidResult set_monitoring(std::shared_ptr< monitoring_interface > monitoring)
Set custom monitoring.
NetworkSystemBridge()
Default constructor.
VoidResult set_logger(std::shared_ptr< logger_interface > logger)
Set custom logger.
@ Custom
Uses custom thread_pool_interface.
static std::shared_ptr< ThreadPoolBridge > from_thread_system(const std::string &pool_name="network_pool")
Create bridge from thread_system.
Adapter for common_system integration.
constexpr int invalid_argument
constexpr int not_initialized
constexpr int internal_error
constexpr int already_exists
VoidResult error_void(int code, const std::string &message, const std::string &source="network_system", const std::string &details="")
VoidResult initialize()
Initialize the network system with default production configuration.
Unified facade for all network_system integration bridges.
Configuration for bridge initialization.
std::map< std::string, std::string > properties
Key-value properties for bridge-specific configuration.
std::string integration_name
Name identifying the external system being integrated.
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.
Configuration for NetworkSystemBridge.
Adapter that bridges thread_system::thread_pool to thread_pool_interface.