30{
31 std::cout << "=== Config Watcher Example ===\n\n";
32
33
34 const std::string config_path = "example_config.yaml";
35 {
36 std::ofstream f(config_path);
37 f << "thread:\n"
38 << " pool_size: 4\n"
39 << " queue_type: adaptive\n"
40 << "logger:\n"
41 << " level: info\n"
42 << "monitoring:\n"
43 << " enabled: true\n"
44 << " metrics_interval: 30\n";
45 }
46
47
48 std::cout << "1. Creating config watcher for '" << config_path << "'...\n";
50
51
52 watcher.on_change(
54 {
55 std::cout << "\n [Change detected]\n";
58 });
59
60
61 watcher.on_error([](const std::string& error)
62 { std::cerr <<
" [Config error] " <<
error <<
"\n"; });
63
64
65 std::cout << "\n2. Starting file watcher...\n";
66 auto start_result = watcher.start();
67 if (start_result.is_ok())
68 {
69 std::cout << " Watcher running = " << (watcher.is_running() ? "true" : "false") << "\n";
70 }
71 else
72 {
73 std::cout << " Watcher start skipped (platform may not support file watching in this "
74 "environment)\n";
75 }
76
77
78 std::cout << "\n3. Modifying config file...\n";
79 {
80 std::ofstream f(config_path);
81 f << "thread:\n"
82 << " pool_size: 8\n"
83 << " queue_type: lock_free\n"
84 << "logger:\n"
85 << " level: debug\n"
86 << "monitoring:\n"
87 << " enabled: true\n"
88 << " metrics_interval: 10\n";
89 }
90
91
92 std::this_thread::sleep_for(std::chrono::milliseconds(500));
93
94
95 std::cout << "\n4. Manual reload...\n";
96 auto reload_result = watcher.reload();
97 std::cout << " Reload: " << (reload_result.is_ok() ? "success" : "skipped") << "\n";
98
99
100 std::cout << "\n5. Stopping watcher...\n";
101 watcher.stop();
102 std::cout << " Watcher running = " << (watcher.is_running() ? "true" : "false") << "\n";
103
104
105 std::remove(config_path.c_str());
106
107 std::cout << "\nDone.\n";
108 return 0;
109}
Monitors configuration files for changes and supports hot-reload.
size_t pool_size
Number of worker threads (default: hardware concurrency)
Root configuration structure for the unified system.
thread_config thread
Thread system configuration.