Class FileBlockStore
java.lang.Object
ai.badmonkey.agentspaces.peering.blocks.FileBlockStore
- All Implemented Interfaces:
BlockStore
A file-backed block store (LB-B-05): one file per CID under a directory, written
through a temporary name and an atomic move, read back on start so a restart serves
what it held and a live entry's block survives the process. The last-served time is
the file's modification time, which a read refreshes, so eviction order survives too.
-
Constructor Summary
ConstructorsConstructorDescriptionFileBlockStore(Path dir) Opens or creates a store, reading back every block it holds. -
Method Summary
Modifier and TypeMethodDescriptionlongThe bytes held.cids()The CIDs held.dir()The directory.Optional<byte[]> Reads a block and marks it served.kind()The store kind:memoryorfile.longlastAccessMillis(String cid) When a block was last served or stored, or -1 when not held.booleanStores a block unless it is already held, in which case it is marked served.longDrops a block.intsize()How many blocks are held.
-
Constructor Details
-
FileBlockStore
Opens or creates a store, reading back every block it holds.- Parameters:
dir- the directory- Throws:
IOException- when the directory cannot be created or listed
-
-
Method Details
-
dir
The directory. -
get
Description copied from interface:BlockStoreReads a block and marks it served.- Specified by:
getin interfaceBlockStore- Parameters:
cid- the CIDnowMillis- the clock- Returns:
- the bytes, when held
-
put
Description copied from interface:BlockStoreStores a block unless it is already held, in which case it is marked served.- Specified by:
putin interfaceBlockStore- Parameters:
cid- the CIDbytes- the bytes; the store keeps its own copynowMillis- the clock- Returns:
- whether the block was new to the store
-
remove
Description copied from interface:BlockStoreDrops a block.- Specified by:
removein interfaceBlockStore- Parameters:
cid- the CID- Returns:
- the bytes freed, or -1 when the block was not held
-
cids
Description copied from interface:BlockStoreThe CIDs held.- Specified by:
cidsin interfaceBlockStore
-
lastAccessMillis
Description copied from interface:BlockStoreWhen a block was last served or stored, or -1 when not held.- Specified by:
lastAccessMillisin interfaceBlockStore
-
size
public int size()Description copied from interface:BlockStoreHow many blocks are held.- Specified by:
sizein interfaceBlockStore
-
bytesUsed
public long bytesUsed()Description copied from interface:BlockStoreThe bytes held.- Specified by:
bytesUsedin interfaceBlockStore
-
kind
Description copied from interface:BlockStoreThe store kind:memoryorfile.- Specified by:
kindin interfaceBlockStore
-