LogStoreBase class abstract base

Base class for a store (LogStore): carries what every store would otherwise repeat, leaving the implementation the primitives onWriteEntries, onQueryEntries, onQueryTags, onClear, onRemoveBefore, onRetainNewest and onClose.

The base emits every LogStoreChange to changes itself (the store reports only removals of its own through reportChange, delivered after the current write's LogEntriesAdded); hands onWriteEntries the entries already in stored form (LogEntry.withoutLiveObjects); makes every operation throw StateError after close and closes changes after onClose. A base class: a store is final class MyStore extends LogStoreBase, and one the base does not fit implements LogStore directly.

final class MyStore extends LogStoreBase {
  @override
  Future<List<StoredLogEntry>> onWriteEntries(List<LogEntry> entries) => db.transaction((tx) async {
    final stored = [for (final entry in entries) StoredLogEntry(insert(tx, entry), entry)];
    reportChange(LogEntriesRemovedById(evictOldest(tx)));
    return stored;
  });
  // …
}
Implemented types
Implementers

Constructors

LogStoreBase()

Properties

changes → Stream<LogStoreChange>
Broadcast stream of changes: LogEntriesAdded for each saved batch of entries, LogEntriesRemoved describing removed entries, LogStoreInvalidated when a change cannot be described more precisely. There may be several subscribers (for example, two open viewers).
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
isClosed → bool
Whether close has been called: from then on operations throw StateError.
no setter
name → String
Store name in messages (StateError after close). Defaults to the class name, unreadable in an --obfuscate build; a store should return a constant string, as sinks do (LogSink.name).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → Future<void>
Removes all entries (onClear) and sends AllLogEntriesRemoved. Throws StateError after close.
override
close() → Future<void>
Releases resources (onClose) and closes changes. A repeated call closes nothing again and returns the result of the first.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onClear() → Future<void>
Removes all entries. The base sends AllLogEntriesRemoved.
onClose() → Future<void>
Releases the store's resources. Called once, from close; the base closes changes afterwards. Does nothing by default.
onQueryEntries(LogQuery query) → Future<LogPage>
A page of entries for query; see LogStore.queryEntries.
onQueryTags() → Future<Set<String>>
All tags of stored entries; see LogStore.queryTags.
onRemoveBefore(DateTime time) → Future<void>
Removes entries strictly before time. The base sends LogEntriesRemovedBefore.
onRetainNewest(int count) → Future<Set<int>?>
Keeps the count newest entries in store order and returns the removed ids (an empty set if there was nothing to remove) or null if they cannot be determined cheaply: the base then sends LogStoreInvalidated. In SQL, DELETE … RETURNING id provides the ids.
onWriteEntries(List<LogEntry> entries) → Future<List<StoredLogEntry>>
Saves entries in this order and returns them with ids (StoredLogEntry.id): increasing in save order and never reused (in SQLite, INTEGER PRIMARY KEY AUTOINCREMENT). Entries are already in stored form (LogEntry.withoutLiveObjects). A batch is best saved in one transaction; the sink passes the next one only after this one completes. The base sends LogEntriesAdded.
queryEntries([LogQuery query = const LogQuery()]) → Future<LogPage>
A page of entries for query (onQueryEntries). Throws StateError after close.
override
queryTags() → Future<Set<String>>
Tags of stored entries (onQueryTags). Throws StateError after close.
override
removeBefore(DateTime time) → Future<void>
Removes entries strictly before time (onRemoveBefore) and sends LogEntriesRemovedBefore. Throws StateError after close.
override
reportChange(LogStoreChange change) → void
Reports a change the store made on its own: removed entries because of file size (LogEntriesRemovedById or, if it does not know which, LogStoreInvalidated). During onWriteEntries the change is sent after the LogEntriesAdded of that write: otherwise a subscriber would get a removal of entries it does not yet know about.
retainNewest(int count) → Future<void>
Keeps the count newest entries (onRetainNewest) and sends LogEntriesRemovedById with the removed ids, nothing if there was nothing to remove, or LogStoreInvalidated if the store does not know what it removed. Throws StateError after close.
override
toString() → String
A string representation of this object.
inherited
writeEntries(List<LogEntry> entries) → Future<List<StoredLogEntry>>
Converts entries to stored form, saves them (onWriteEntries) and sends LogEntriesAdded to changes; changes the store reported while saving (reportChange) follow it. Throws StateError after close.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited