Table of Contents

Class SubscriptionsRegistry

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

The declaration surface for engine-owned replication: the projections clients may see, the profiles that decide what each session watches, the commands clients may send, the events they hear and the metrics they are told about.

public sealed class SubscriptionsRegistry
Inheritance
SubscriptionsRegistry
Inherited Members

Remarks

Reached through Subscriptions, and configured before Start(). Replication rides the tick, so it belongs to the runtime rather than to DatabaseEngine; and everything here is compiled once at Start, which is why the registry freezes there and refuses a late declaration instead of quietly not applying it.

Declaring costs nothing at run time. The registry holds names, codecs and policy; it has no per-tick presence at all. What the tick sees is the compiled plan the projection compiler builds from it, in which every name has already become an offset.

Malformed declarations are refused where they are written. A duplicate wire name, a ninth change group, a 256th archetype, a 64-bit source with no explicit narrowing and a metric under the reserved typhon. prefix all throw from the call that declared them. What cannot be judged from one declaration — an observer shape or a source that a later phase builds — is refused at Start, with the phase named.

Constructors

SubscriptionsRegistry(SubscriptionsOptions)

Creates a registry over the given options.

public SubscriptionsRegistry(SubscriptionsOptions options = null)

Parameters

options SubscriptionsOptions

The operator's replication options. null takes the defaults.

Remarks

The runtime builds its own from Subscriptions and exposes it as Subscriptions; that is the one the engine reads. Constructing one directly is for a test, or for an application that assembles its declarations somewhere other than beside its host.

Properties

Archetypes

The archetype projections, in declaration order.

public IReadOnlyList<ArchetypeProjection> Archetypes { get; }

Property Value

IReadOnlyList<ArchetypeProjection>

Commands

The command types, in declaration order.

public IReadOnlyList<CommandDeclaration> Commands { get; }

Property Value

IReadOnlyList<CommandDeclaration>

Events

The replicated events, in declaration order.

public IReadOnlyList<EventDeclaration> Events { get; }

Property Value

IReadOnlyList<EventDeclaration>

IsFrozen

Whether Start has compiled these declarations. A frozen registry refuses every further declaration.

public bool IsFrozen { get; }

Property Value

bool

Metrics

The application's metrics, in declaration order. The built-ins are not listed here: the engine owns them.

public IReadOnlyList<MetricDeclaration> Metrics { get; }

Property Value

IReadOnlyList<MetricDeclaration>

Options

The operator's replication options.

public SubscriptionsOptions Options { get; }

Property Value

SubscriptionsOptions

Profiles

The interest profiles, in declaration order.

public IReadOnlyList<ProfileDeclaration> Profiles { get; }

Property Value

IReadOnlyList<ProfileDeclaration>

Sessions

Session kinds, admission and the tick-visible session lifecycle.

public SubscriptionsSessions Sessions { get; }

Property Value

SubscriptionsSessions

Sources

The shared sources, in declaration order.

public IReadOnlyList<SourceDeclaration> Sources { get; }

Property Value

IReadOnlyList<SourceDeclaration>

Methods

Archetype<TArchetype>(Action<ArchetypeProjectionBuilder>)

Declares what clients may see of an archetype.

public SubscriptionsRegistry Archetype<TArchetype>(Action<ArchetypeProjectionBuilder> configure) where TArchetype : Archetype<TArchetype>

Parameters

configure Action<ArchetypeProjectionBuilder>

Declares its position, fields and owner section.

Returns

SubscriptionsRegistry

This registry.

Type Parameters

TArchetype

The archetype.

Command<T>(Action<CommandBuilder<T>>)

Declares a command type clients may send.

public SubscriptionsRegistry Command<T>(Action<CommandBuilder<T>> configure) where T : unmanaged

Parameters

configure Action<CommandBuilder<T>>

Declares delivery, rate, roles and pre-check.

Returns

SubscriptionsRegistry

This registry.

Type Parameters

T

The command type: an unmanaged struct.

Event<T>(EventQueue<T>, Action<EventBuilder<T>>)

Declares that an event queue's events reach clients, and how.

public SubscriptionsRegistry Event<T>(EventQueue<T> queue, Action<EventBuilder<T>> configure) where T : unmanaged

Parameters

queue EventQueue<T>

The queue systems produce into. Replication becomes its single consumer.

configure Action<EventBuilder<T>>

Declares routing and fields.

Returns

SubscriptionsRegistry

This registry.

Type Parameters

T

The event type.

Metric(string, string, Codec, Func<double>, MetricKind, string[])

Declares an application metric, carried to sessions that asked for statistics.

public SubscriptionsRegistry Metric(string name, string unit, Codec codec, Func<double> source, MetricKind kind = MetricKind.Gauge, string[] labels = null)

Parameters

name string

The metric's name. The typhon. prefix is reserved for the engine's own.

unit string

Its unit, as a client displays it — ms, count, B/s.

codec Codec

How the value travels. Encoders saturate: no NaN and no infinity reach the wire.

source Func<double>

Reads the current value, once per emission — not once per session.

kind MetricKind

Gauge or counter.

labels string[]

The label set, for a metric that contributes one value per label rather than one value.

Returns

SubscriptionsRegistry

This registry.

Profile(string, Action<ProfileBuilder>)

Declares a named set of observers a session can be bound to.

public SubscriptionsRegistry Profile(string name, Action<ProfileBuilder> configure)

Parameters

name string

The profile's name.

configure Action<ProfileBuilder>

Declares its observers.

Returns

SubscriptionsRegistry

This registry.

Source(string, ViewBase, Action<ArchetypeProjectionBuilder>)

Declares a shared non-spatial source: a View whose members are replicated to the sessions subscribed to it — a bazaar, a leaderboard, a roster.

public SubscriptionsRegistry Source(string name, ViewBase view, Action<ArchetypeProjectionBuilder> projection)

Parameters

name string

The source's name, as a session subscribes to it.

view ViewBase

The View whose membership drives enters and leaves.

projection Action<ArchetypeProjectionBuilder>

Declares what of each member travels.

Returns

SubscriptionsRegistry

This registry.

Remarks

Declared now, built in Phase 4 — a runtime that starts with one refuses to start and says so. Data with no position cannot be reached through an observer, so an application that needs it should be able to say so against the shape it will eventually get, rather than inventing a spatial home for a leaderboard in the meantime.

Static<TArchetype>(Action<ArchetypeProjectionBuilder>)

Declares an archetype whose replicated state never changes: its record is sent once, on enter, and never updated.

public SubscriptionsRegistry Static<TArchetype>(Action<ArchetypeProjectionBuilder> configure) where TArchetype : Archetype<TArchetype>

Parameters

configure Action<ArchetypeProjectionBuilder>

Declares its position and fields.

Returns

SubscriptionsRegistry

This registry.

Type Parameters

TArchetype

The archetype.

Remarks

This is not an optimization hint the engine may ignore. A static archetype has no change groups and no per-entity comparison at all, so a world of scenery costs the projection pass nothing per tick — which is the difference between replicating a landscape and replicating a simulation.