| doc_id | NET-INTR-002 |
|---|---|
| doc_title | Integration Guide |
| doc_version | 1.0.0 |
| doc_date | 2026-04-04 |
| doc_status | Released |
| project | network_system |
| category | INTR |
SSOT: This document is the single source of truth for Integration Guide.
Language: English | 한국어
This guide explains how to integrate network_system with external systems and libraries.
- Thread System Integration
- Container System Integration
- Logger System Integration
- Monitoring System Integration
- Build Configuration
The network_system can optionally integrate with an external thread pool for improved performance.
cmake .. -DBUILD_WITH_THREAD_SYSTEM=ONWhen BUILD_WITH_THREAD_SYSTEM is enabled, the basic_thread_pool class internally delegates to thread_system::thread_pool. This provides:
- Unified Thread Management: All thread operations go through thread_system
- Advanced Features: Access to adaptive_job_queue, hazard pointers, and worker health monitoring
- Consistent Metrics: Thread pool metrics are reported through thread_system's metrics infrastructure
- Automatic Benefits: No code changes required - existing
basic_thread_poolusage automatically gets thread_system features
// basic_thread_pool now internally uses thread_system::thread_pool
class basic_thread_pool::impl {
std::shared_ptr<kcenon::thread::thread_pool> pool_;
// ... delegates all operations to pool_
};When thread_system is not available, basic_thread_pool falls back to a standalone std::thread-based implementation.
When thread_system is available, network operations will automatically utilize the thread pool for:
- Connection handling
- Message processing
- Async operations
- Send coroutine fallback (non-coroutine path uses
thread_integration_manager::submit_task())
For direct access to thread_system features, you can use the thread_system_pool_adapter:
#include <kcenon/network/integration/thread_system_adapter.h>
// Create adapter from service container or create new pool
auto adapter = thread_system_pool_adapter::from_service_or_default("network_pool");
// Or bind thread_system directly to the integration manager
bind_thread_system_pool_into_manager("my_pool");The io_context_thread_manager provides unified management of asio::io_context execution across all messaging components:
#include <kcenon/network/integration/io_context_thread_manager.h>
// Run an io_context on the shared thread pool
auto io_ctx = std::make_shared<asio::io_context>();
auto future = io_context_thread_manager::instance()
.run_io_context(io_ctx, "my_component");
// Stop when done
io_context_thread_manager::instance().stop_io_context(io_ctx);
future.wait();
// Get metrics
auto metrics = io_context_thread_manager::instance().get_metrics();
// metrics.active_contexts, metrics.total_started, metrics.total_completedBenefits:
- Centralized Management: All io_context instances use the same thread pool
- Consistent Shutdown: Uniform shutdown behavior across components
- Reduced Complexity: Components don't manage their own threads
- Better Observability: Metrics for all io_context instances in one place
- thread_system must be installed in
../thread_system - Headers should be available at
../thread_system/include
Enable advanced serialization and deserialization capabilities.
cmake .. -DBUILD_WITH_CONTAINER_SYSTEM=ON- Binary serialization
- JSON serialization
- Protocol buffer support
- Custom container types
#include <network_system/integration/container_integration.h>
// Serialize custom data
auto serialized = container_adapter::serialize(my_data);
client->send_packet(serialized);Provides structured logging with configurable log levels and output formats.
cmake .. -DBUILD_WITH_LOGGER_SYSTEM=ON- Log Levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Source Location Tracking: Automatic file, line, and function recording
- Timestamp Formatting: Millisecond precision timestamps
- Conditional Compilation: Falls back to console output when logger_system is unavailable
#include <network_system/integration/logger_integration.h>
// Use convenience macros
NETWORK_LOG_INFO("Server started on port " + std::to_string(port));
NETWORK_LOG_ERROR("Connection failed: " + error_message);
NETWORK_LOG_DEBUG("Received " + std::to_string(bytes) + " bytes");// Get logger instance
auto& logger_mgr = kcenon::network::integration::logger_integration_manager::instance();
auto logger = logger_mgr.get_logger();
// Check if log level is enabled
if (logger->is_enabled(kcenon::network::integration::log_level::debug)) {
// Perform expensive debug logging
std::string detailed_state = generate_detailed_state();
NETWORK_LOG_DEBUG(detailed_state);
}
// Direct logging without macros
logger->log(kcenon::network::integration::log_level::warn,
"Custom warning message",
__FILE__, __LINE__, __FUNCTION__);The logger integration provides two implementations:
-
basic_logger: Standalone console logger
- Used when BUILD_WITH_LOGGER_SYSTEM is OFF
- Outputs to std::cout (INFO and below) or std::cerr (WARN and above)
- Simple timestamp formatting
-
logger_system_adapter: External logger integration
- Used when BUILD_WITH_LOGGER_SYSTEM is ON
- Wraps kcenon::logger for full-featured logging
- Supports log file rotation, remote logging, etc.
- When BUILD_WITH_LOGGER_SYSTEM=ON:
- logger_system must be installed in
../logger_system - Headers should be available at
../logger_system/include
- logger_system must be installed in
- C++17 or later for string_view support
Provides metrics collection and observability capabilities via EventBus-based metric publishing.
No compile-time monitoring_system dependency is needed. External consumers subscribe to network_metric_event via EventBus.
- Counter metrics: Track connection counts, bytes transferred
- Gauge metrics: Monitor active connections, buffer usage
- Histogram metrics: Measure latency distributions
- Health reporting: Track connection health status
#include <kcenon/network/integration/monitoring_integration.h>
using namespace kcenon::network::integration;
auto& monitor = monitoring_integration_manager::instance();
// Report metrics
monitor.report_counter("network.connections.total", 1, {{"type", "tcp"}});
monitor.report_gauge("network.connections.active", 42);
monitor.report_histogram("network.latency_ms", 12.5);monitor.report_health("connection_1",
true, // is_alive
15.3, // response_time_ms
0, // missed_heartbeats
0.0); // packet_loss_rateFor detailed documentation, see integration/with-monitoring.md.
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_WITH_THREAD_SYSTEM=ON \
-DBUILD_WITH_CONTAINER_SYSTEM=ON \
-DBUILD_WITH_LOGGER_SYSTEM=ONcmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_WITH_THREAD_SYSTEM=OFF \
-DBUILD_WITH_CONTAINER_SYSTEM=OFF \
-DBUILD_WITH_LOGGER_SYSTEM=OFFThe system provides macros to check which integrations are available:
#if KCENON_WITH_THREAD_SYSTEM
// Thread system is available
use_thread_pool();
#endif
#if KCENON_WITH_CONTAINER_SYSTEM
// Container system is available
use_advanced_serialization();
#endif
#if KCENON_WITH_LOGGER_SYSTEM
// Logger system is available
use_structured_logging();
#else
// Fallback to basic logging
use_console_logging();
#endif
#if KCENON_WITH_MONITORING_SYSTEM
// Monitoring system is available
auto adapter = std::make_shared<monitoring_system_adapter>("my_service");
monitoring_integration_manager::instance().set_monitoring(adapter);
#else
// Fallback to basic monitoring (logs to console)
auto basic = std::make_shared<basic_monitoring>(true);
monitoring_integration_manager::instance().set_monitoring(basic);
#endifBUILD_WITH_THREAD_SYSTEM— enable thread pool integration viathread_integration_manager.BUILD_WITH_CONTAINER_SYSTEM— enable container adapters viacontainer_manager.BUILD_WITH_LOGGER_SYSTEM— uselogger_system_adapter; otherwise falls back tobasic_logger.
- Recommended vcpkg baseline alignment across modules (example):
- fmt: 10.2.1
- Provide a top-level
vcpkg-configuration.jsonto set a sharedbuiltin-baselineand fmt override.
- C++ standard: C++20 (string_view and coroutine-friendly APIs; falls back to non-coroutine path when disabled).
- ASIO standalone is required (see
vcpkg.json).
- Benefit: Up to 40% improvement in concurrent connection handling
- Trade-off: Slightly increased memory usage
- Benefit: Type-safe serialization with minimal overhead
- Trade-off: Additional dependency and build time
- Benefit: Structured logging with filtering reduces I/O overhead
- Trade-off: Minimal performance impact (~1-2%)
- Benefit: Full observability with metrics collection and health monitoring
- Trade-off: Slightly higher overhead than basic_monitoring (~3-5%)
- Note: basic_monitoring (default) has minimal overhead as it only logs when enabled
If CMake cannot find an integration system:
- Verify the system is installed in the expected location
- Check that include paths are correct
- Ensure the system is built with compatible compiler settings
- Ensure all systems are built with the same C++ standard
- Check ABI compatibility between systems
- Verify all required libraries are linked
- Check that all integrated systems are initialized properly
- Verify thread safety when using multiple integrations
- Review log output for initialization errors
Last Updated: 2025-12-05