Add async/resilience/reflection primitives + FSM v2 rewrite

A round of new universal capabilities (all generic — templated/reflection
based, no app coupling), verified by the test suite (1103 passing):

Data reflection:
- Reflect.hpp now (de)serializes chrono::duration, chrono::time_point,
  std::variant (tagged), std::array, and non-string-keyed std::map;
  Meta.hpp gains is_time_point_v et al.

Async:
- EventBus gains Mode::Async (worker-thread dispatch + flush()).
- ThreadPool gains a bounded queue, try_submit(), and rejection stats.

New modules / containers:
- Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker,
  ResourceMonitor.
- Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V>
  (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats).
- System: process/CPU/memory metrics (Metrics.hpp) and a streaming
  Process API.

Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions,
history states, deferred events), Configuration/Logging reflection
helpers, and the accompanying test suites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-22 15:45:16 +03:00
1 parent 43b5a81504
commit 80293ee56f
93 files changed
+8500 -3312

No files matched your search

+38 -8
View File
@@ -1,5 +1,6 @@
#pragma once
#include <Void/Core/Meta.hpp>
#include <Void/Service/Service.hpp>
#include <memory>
@@ -14,6 +15,16 @@
namespace Void::Service
{
#ifdef VOID_HAS_META_REFLECTION
/// The reflected (unqualified) name of an interface type — a sensible
/// default service name when an IService impl doesn't override
/// service_name(). E.g. interface_name<IClock>() == "IClock".
template <typename I> [[nodiscard]] std::string interface_name()
{
return Void::Meta::type_name<I>();
}
#endif
/// Type-keyed service container: providers register an implementation
/// against an interface type, consumers resolve by that interface and
/// never name the concrete type — the core of the dependency-inversion
@@ -32,6 +43,16 @@ namespace Void::Service
ServiceRegistry(const ServiceRegistry&) = delete;
ServiceRegistry& operator=(const ServiceRegistry&) = delete;
/// Create a scoped child registry that overlays `parent`: lookups
/// fall through to the parent when a key is not provided locally,
/// and a local provide<I>() shadows the parent's entry. Lifecycle
/// (start_all/stop_all) covers only locally-provided services. The
/// parent must outlive this registry.
explicit ServiceRegistry(const ServiceRegistry* parent)
: m_parent{parent}
{
}
/// Register (or replace) the implementation for interface I.
/// If I derives IService, the instance joins the lifecycle.
template <typename I> void provide(std::shared_ptr<I> impl)
@@ -54,15 +75,18 @@ namespace Void::Service
m_services.insert_or_assign(key, std::move(entry));
}
/// Resolve I, or nullptr if not provided.
/// Resolve I, or nullptr if not provided. Falls through to the
/// parent registry (if any) on a local miss.
template <typename I> [[nodiscard]] std::shared_ptr<I> get() const
{
std::shared_lock lock{m_mutex};
const auto it = m_services.find(std::type_index{typeid(I)});
if (it == m_services.end()) {
return nullptr;
{
std::shared_lock lock{m_mutex};
const auto it = m_services.find(std::type_index{typeid(I)});
if (it != m_services.end()) {
return std::static_pointer_cast<I>(it->second.impl);
}
}
return std::static_pointer_cast<I>(it->second.impl);
return m_parent ? m_parent->get<I>() : nullptr;
}
/// Resolve I; throws std::runtime_error if not provided.
@@ -79,8 +103,13 @@ namespace Void::Service
template <typename I> [[nodiscard]] bool has() const
{
std::shared_lock lock{m_mutex};
return m_services.contains(std::type_index{typeid(I)});
{
std::shared_lock lock{m_mutex};
if (m_services.contains(std::type_index{typeid(I)})) {
return true;
}
}
return m_parent ? m_parent->has<I>() : false;
}
/// Call on_start() on every lifecycle service, registration
@@ -119,6 +148,7 @@ namespace Void::Service
IService* service = nullptr; // non-null iff I : IService
};
const ServiceRegistry* m_parent = nullptr;
mutable std::shared_mutex m_mutex;
std::unordered_map<std::type_index, Entry> m_services;
std::vector<std::type_index> m_order;