Class Checkpoint
try (var w = Checkpoint.writer(path)) { // end of day
w.section("volume.AAPL", volumeCurve::writeState)
.section("alpha.AAPL", learner::writeState)
.section("venues", scorecard::writeState);
} // commits atomically
var r = Checkpoint.reader(path); // next morning
r.section("volume.AAPL", volumeCurve::readState); // false if absent
Contract. Each model persists its learned (cross-day)
state only; intraday state resets on read — you restore at session
start, not mid-stream. The reading instance must be constructed with the
same configuration (bucket count, venue count, …): a mismatch throws
IOException rather than silently misaligning arrays. Each
section payload carries its own version byte so models can evolve their
format independently of the file format.
Durability. The writer buffers sections in memory and commits
in Checkpoint.Writer.close(): temp file in the target directory, then an
atomic rename over the old checkpoint — a crash mid-save leaves
yesterday's file intact, never a torn one. (On the rare filesystem
without atomic rename — some network mounts — the commit degrades to a
plain replace, and a crash in that narrow window can lose the old file;
keep checkpoints on a local disk if that guarantee matters.) If any
section writer threw, nothing is committed. The reader loads the whole file up front (these
files are kilobytes), skips unknown sections (forward compatibility),
and rejects a section the model did not fully consume — the loudest
possible signal of a writer/reader format drift.
Everything here is cold-path (end of day / session start); the hot
lanes never see it. Naming convention: model.symbol
("volume.EURUSD", "venues"). For DayTypeProfiles, write one
section per day type ("volume.AAPL.day0" …).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRandom access to a loaded checkpoint's sections by name.static interfaceA model's state deserializer — typically areadStatereference.static interfaceA model's state serializer — typically awriteStatereference.static final classCollects named sections and commits them atomically on close. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidreadDoublesInto(DataInput in, double[] a) Reads a length-prefixed double array INTOa— a length mismatch means the checkpoint was written by a differently-configured instance (other bucket/venue count) and throws before touching it.static Checkpoint.ReaderLoads a checkpoint fully into memory and validates the header.static voidreadLongsInto(DataInput in, long[] a) Long-array counterpart ofreadDoublesInto(java.io.DataInput, double[]).static voidrequireVersion(DataInput in, int expected, String model) Reads and checks a model's leading state-version byte — the shared first line of everyreadState.static voidwriteDoubles(DataOutput out, double[] a) Length-prefixed double array.static voidwriteLongs(DataOutput out, long[] a) Length-prefixed long array.static Checkpoint.WriterOpens a writer; nothing touchespathuntilCheckpoint.Writer.close().
-
Method Details
-
writer
Opens a writer; nothing touchespathuntilCheckpoint.Writer.close(). -
reader
Loads a checkpoint fully into memory and validates the header.- Throws:
IOException
-
requireVersion
Reads and checks a model's leading state-version byte — the shared first line of everyreadState. Throws when the checkpoint was written by a build with a newer per-model format.- Throws:
IOException
-
writeDoubles
Length-prefixed double array.- Throws:
IOException
-
readDoublesInto
Reads a length-prefixed double array INTOa— a length mismatch means the checkpoint was written by a differently-configured instance (other bucket/venue count) and throws before touching it.- Throws:
IOException
-
writeLongs
Length-prefixed long array.- Throws:
IOException
-
readLongsInto
Long-array counterpart ofreadDoublesInto(java.io.DataInput, double[]).- Throws:
IOException
-