NetworkedApplications: networked-kv composition skeleton
This commit is contained in:
1 parent
a4c0bee501
commit
808b6d73df
4 files changed
+409
No files matched your search
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
#include <Void/Runtime/Host.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace NetworkedKv
|
||||
{
|
||||
/// Validated listener and request bounds for the reference service.
|
||||
/// Construction alone opens no socket or worker.
|
||||
struct NetworkedConfig {
|
||||
std::string listen_address{"127.0.0.1:0"};
|
||||
std::string admin_address{};
|
||||
std::uint32_t max_connections{64};
|
||||
std::size_t max_request_bytes{1024ULL * 1024ULL};
|
||||
std::size_t max_scan_page{1000};
|
||||
std::chrono::milliseconds request_deadline{
|
||||
std::chrono::seconds{30}};
|
||||
std::chrono::milliseconds shutdown_grace{
|
||||
std::chrono::seconds{5}};
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void> validate() const;
|
||||
};
|
||||
|
||||
enum class ResourceOwnership : std::uint8_t { Embedded, Managed };
|
||||
|
||||
/// Module-owned resources supplied by the application.
|
||||
///
|
||||
/// Embedded mode borrows an already-running host and never shuts it down.
|
||||
/// Managed mode lets the application create and own the host.
|
||||
struct ApplicationResources {
|
||||
ResourceOwnership ownership{ResourceOwnership::Embedded};
|
||||
Void::Runtime::Host* borrowed_host{nullptr};
|
||||
Void::Runtime::Options runtime_options{};
|
||||
};
|
||||
|
||||
enum class ApplicationState : std::uint8_t {
|
||||
Created,
|
||||
Running,
|
||||
Stopping,
|
||||
Stopped,
|
||||
Failed
|
||||
};
|
||||
|
||||
struct HealthSnapshot {
|
||||
ApplicationState state{ApplicationState::Created};
|
||||
bool ready{false};
|
||||
bool managed{false};
|
||||
std::size_t started_workers{0};
|
||||
};
|
||||
|
||||
/// Composition surface for the networked key-value reference service.
|
||||
///
|
||||
/// This slice owns lifecycle and resource-mode policy only: it wires no
|
||||
/// HTTP endpoints yet and defines no competing executor, clock, logger or
|
||||
/// error type.
|
||||
class NetworkedApplication
|
||||
{
|
||||
public:
|
||||
|
||||
NetworkedApplication(const NetworkedApplication&) = delete;
|
||||
NetworkedApplication& operator=(const NetworkedApplication&) = delete;
|
||||
NetworkedApplication(NetworkedApplication&&) noexcept;
|
||||
NetworkedApplication& operator=(NetworkedApplication&&) noexcept;
|
||||
~NetworkedApplication();
|
||||
|
||||
[[nodiscard]] static Void::Result::Result<NetworkedApplication>
|
||||
create(ApplicationResources resources, NetworkedConfig config);
|
||||
|
||||
/// Start serving. Managed mode creates and starts the owned host;
|
||||
/// embedded mode requires the borrowed host to already be running.
|
||||
[[nodiscard]] Void::Result::Result<void> start();
|
||||
|
||||
/// Stop serving. Idempotent and bounded. Managed mode shuts the
|
||||
/// owned host down; embedded mode leaves the borrowed host alone.
|
||||
[[nodiscard]] Void::Result::Result<Void::Runtime::ShutdownReport>
|
||||
stop();
|
||||
|
||||
[[nodiscard]] HealthSnapshot health() const;
|
||||
[[nodiscard]] const NetworkedConfig& config() const noexcept
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
NetworkedApplication() = default;
|
||||
void stop_owned_host() noexcept;
|
||||
|
||||
NetworkedConfig m_config{};
|
||||
ApplicationResources m_resources{};
|
||||
std::unique_ptr<Void::Runtime::Host> m_owned_host{};
|
||||
Void::Runtime::Host* m_host{nullptr};
|
||||
ApplicationState m_state{ApplicationState::Created};
|
||||
};
|
||||
} // namespace NetworkedKv
|
||||
Reference in new issue
Block a user