Quantum Resource Manager and Compiler Infrastructure (QRM&CI) 0.1.0
mqss::qrmci::BackendRegistry Class Reference

Owns the backends a process knows about, keyed by backend name. More...

Public Types

using Clock = std::chrono::steady_clock
 Monotonic clock used for entry freshness.

Public Member Functions

 BackendRegistry ()=default
 Construct a registry with the default time-to-live.
 BackendRegistry (Clock::duration timeToLive)
 Construct a registry with an explicit time-to-live.
bool insertOrRefresh (BackendWrapper backend, Clock::time_point now=Clock::now())
 Insert a backend, or refresh the entry already registered under the same name, and stamp it as last heard from at now.
std::size_t expire (Clock::time_point now=Clock::now())
 Drop every entry last refreshed longer ago than the registry's time-to-live.
const BackendWrapper * find (std::string_view backendName) const
 Look up a backend by name.
bool contains (std::string_view backendName) const
 Check whether a backend is registered under a given name.
std::size_t size () const noexcept
 Get the number of registered backends.
bool empty () const noexcept
 Check whether the registry holds no backends.
Clock::duration getTimeToLive () const noexcept
 Get the registry's entry time-to-live.
template<typename Fn>
void forEachBackend (Fn &&fn) const
 Apply a function to every registered backend, in ascending backend-name order.

Static Public Attributes

static constexpr Clock::duration DefaultTimeToLive = std::chrono::seconds(30)
 How long an entry stays usable after it was last refreshed.

Detailed Description

Owns the backends a process knows about, keyed by backend name.

Entries are inserted or refreshed with insertOrRefresh(), each stamped with the time it was last heard from, and dropped by expire() once they are older than the registry's time-to-live – so a worker that dies stops receiving task assignments instead of lingering forever. Lookup goes through find(), which returns nullptr for an unknown name rather than default-constructing an entry the way a raw map's operator[] does.

Iteration order is by ascending backend name, which is what makes chooseBackend() reproducible.

Definition at line 52 of file BackendRegistry.h.

Member Typedef Documentation

◆ Clock

using mqss::qrmci::BackendRegistry::Clock = std::chrono::steady_clock

Monotonic clock used for entry freshness.

Definition at line 55 of file BackendRegistry.h.

Constructor & Destructor Documentation

◆ BackendRegistry()

mqss::qrmci::BackendRegistry::BackendRegistry ( Clock::duration timeToLive)
explicit

Construct a registry with an explicit time-to-live.

Parameters
timeToLiveHow long an entry stays usable after its last refresh. For a self-refreshing process, must be longer than the PublicationThrottle interval it refreshes on, or it can expire its own entry between refreshes.

Member Function Documentation

◆ contains()

bool mqss::qrmci::BackendRegistry::contains ( std::string_view backendName) const
nodiscard

Check whether a backend is registered under a given name.

Parameters
backendNameThe backend name to look up.
Returns
True if the name is registered.

◆ empty()

bool mqss::qrmci::BackendRegistry::empty ( ) const
inlinenodiscardnoexcept

Check whether the registry holds no backends.

Returns
True if there are no entries.

Definition at line 112 of file BackendRegistry.h.

◆ expire()

std::size_t mqss::qrmci::BackendRegistry::expire ( Clock::time_point now = Clock::now())

Drop every entry last refreshed longer ago than the registry's time-to-live.

Parameters
nowThe current time.
Returns
The number of entries dropped.

◆ find()

const BackendWrapper * mqss::qrmci::BackendRegistry::find ( std::string_view backendName) const
nodiscard

Look up a backend by name.

This is the one lookup rule every caller shares: a miss is a null return, never a silently default-constructed entry.

Parameters
backendNameThe backend name to look up.
Returns
A pointer to the registered backend, or nullptr if no backend is registered under that name. The pointer is invalidated by the next insertOrRefresh()/expire() touching that entry.

◆ forEachBackend()

template<typename Fn>
void mqss::qrmci::BackendRegistry::forEachBackend ( Fn && fn) const
inline

Apply a function to every registered backend, in ascending backend-name order.

Template Parameters
FnCallable as fn(const std::string &name, const BackendWrapper &backend).
Parameters
fnThe function to apply.

Definition at line 125 of file BackendRegistry.h.

◆ getTimeToLive()

Clock::duration mqss::qrmci::BackendRegistry::getTimeToLive ( ) const
inlinenodiscardnoexcept

Get the registry's entry time-to-live.

Returns
The configured time-to-live.

Definition at line 116 of file BackendRegistry.h.

◆ insertOrRefresh()

bool mqss::qrmci::BackendRegistry::insertOrRefresh ( BackendWrapper backend,
Clock::time_point now = Clock::now() )

Insert a backend, or refresh the entry already registered under the same name, and stamp it as last heard from at now.

Rejected rather than applied if an entry is already registered under the same name with a different, non-empty dispatch queue – the same ID publishing under two different queues is a routing conflict a task could silently be sent to the wrong worker over, not something a later status update should be allowed to overwrite. The existing entry, and its time-to-live, are left untouched either way.

Parameters
backendThe backend to register.
nowThe time to stamp the entry with.
Returns
True if backend was inserted or refreshed the existing entry; false if it was rejected as a dispatch-queue conflict.

◆ size()

std::size_t mqss::qrmci::BackendRegistry::size ( ) const
inlinenodiscardnoexcept

Get the number of registered backends.

Returns
The number of entries.

Definition at line 108 of file BackendRegistry.h.

Member Data Documentation

◆ DefaultTimeToLive

Clock::duration mqss::qrmci::BackendRegistry::DefaultTimeToLive = std::chrono::seconds(30)
staticconstexpr

How long an entry stays usable after it was last refreshed.

Definition at line 58 of file BackendRegistry.h.


The documentation for this class was generated from the following file: