Class Store
A store-and-forward buffer.
public sealed class Store : IDisposable
- Inheritance
-
Store
- Implements
- Inherited Members
Remarks
The queue a node writes into while it has nowhere to send. An in-memory buffer suits a test or a process that will not outlive it; a file-backed one survives a reboot, which is what a node somewhere without reliable power actually needs.
Handing a store to a ladder consumes it, because the ladder owns it from then on, so a spent store throws rather than aliasing a buffer it no longer holds.
Properties
IsAvailable
Whether this store is still holdable, or has been given away.
public bool IsAvailable { get; }
Property Value
Methods
AppendAsync(ReadOnlyMemory<byte>)
Adds a record to the end of the buffer.
public Task AppendAsync(ReadOnlyMemory<byte> record)
Parameters
recordReadOnlyMemory<byte>The bytes to hold.
Returns
Exceptions
- PamojaException
The store is full, or otherwise refused it.
CountAsync()
Reports how many records the buffer holds.
public Task<int> CountAsync()
Returns
Exceptions
- PamojaException
The native call failed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DrainToAsync(Transport, string)
Sends every held record over a transport, oldest first.
public Task<int> DrainToAsync(Transport transport, string topic)
Parameters
transportTransportThe transport to send over, borrowed not consumed.
topicstringThe topic to send to.
Returns
Remarks
A record is removed only once the transport has taken it, so a link that fails part-way leaves the rest of the queue intact for the next attempt.
Exceptions
- PamojaException
The link failed part-way through.
File(string)
Opens a buffer backed by a directory, so it survives a restart.
public static Store File(string dir)
Parameters
dirstringThe directory to hold records in; created if missing.
Returns
- Store
The buffer.
Exceptions
- PamojaException
The directory could not be opened.
Memory(int)
Creates a buffer held in memory.
public static Store Memory(int capacity = 0)
Parameters
capacityintThe most records to hold, or 0 for no bound.
Returns
- Store
The buffer.
Remarks
A full store refuses the next append rather than dropping anything, so a record is never lost without the caller being told.
PeekAsync()
Reads the oldest record without removing it.
public Task<byte[]?> PeekAsync()
Returns
Exceptions
- PamojaException
The native call failed.
PopAsync()
Removes and returns the oldest record.
public Task<byte[]?> PopAsync()
Returns
Exceptions
- PamojaException
The native call failed.
Take()
Hands the native handle on, leaving this one spent.
public nint Take()