class

Arcana::TopicLog

Inherits Reference < Object

The posts of one #topic: a log on the bus that everyone shares. A post is stored once and numbered from 1; anyone reads from any point with read(after:), without subscribing and without consuming it. The log keeps the newest retention posts and drops older ones.

Constants

DEFAULT_RETENTION = 10000
MAX_RETENTION = 100000

The most posts a topic may keep: every kept post is in memory.

Constructors

new(address : String, retention : Int32 = DEFAULT_RETENTION)
Source

Class methods

check_retention!(retention : Int) : Nil
Source

Instance methods

address
Source
append(envelope : Envelope) : Int64

Add a post; returns its number.

Source
dump

The log's state for a snapshot.

Source
first

The oldest kept post's number; head + 1 when none are kept.

Source
head

The newest post's number; 0 before the first post.

Source
load_snapshot(head : Int64, posts : Array(Post)) : Nil

Restore a snapshot, replacing what the log holds. Posts must be in order with consecutive numbers, as dump gives them.

Source
published_at

When the newest post was published; nil before the first.

Source
read(after : Int64 = 0_i64, limit : Int32 | Nil = nil) : Array(Post)

The posts numbered after after, oldest first, at most limit of them. Posts already dropped are skipped: compare first with after + 1 to tell whether any were missed.

Source
retention
Source
retention=(retention : Int32)

Keep at most retention posts from now on, dropping the oldest.

Source
size

How many posts are kept.

Source

Nested types