Package ai.pipestream.common.util
Interface ProcessingBuffer<T extends com.google.protobuf.Message>
- Type Parameters:
T- the type of protobuf message to store
- All Known Implementing Classes:
NoOpProcessingBuffer,ProcessingBufferImpl
public interface ProcessingBuffer<T extends com.google.protobuf.Message>
Interface for a buffer that stores protobuf messages and can save them to disk.
This is used for testing purposes to capture and save protobuf messages during test runs.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a message to the buffer.voidclear()Clears all messages from the buffer.voidSaves all messages in the buffer to disk using default parameters.voidsaveToDisk(String fileNamePrefix, int numberPrecision) Saves all messages in the buffer to disk to "voidsaveToDisk(Path location, String fileNamePrefix, int numberPrecision) Saves all messages in the buffer to disk.intsize()Returns the number of messages in the buffer.snapshot()Returns a snapshot of all items currently in the buffer.
-
Method Details
-
add
Adds a message to the buffer. If the buffer is full, the oldest message will be removed.- Parameters:
message- the message to add
-
saveToDisk
void saveToDisk()Saves all messages in the buffer to disk using default parameters. Default location is the current directory, default prefix is "protobuf", and default precision is 3 digits. -
saveToDisk
Saves all messages in the buffer to disk to "./
" directory.- Parameters:
fileNamePrefix- the prefix to use for the file namesnumberPrecision- the number of digits to use for the file name suffix
-
saveToDisk
Saves all messages in the buffer to disk.- Parameters:
location- the directory to save the files tofileNamePrefix- the prefix to use for the file namesnumberPrecision- the number of digits to use for the file name suffix
-
size
int size()Returns the number of messages in the buffer.- Returns:
- the number of messages
-
clear
void clear()Clears all messages from the buffer. -
snapshot
Returns a snapshot of all items currently in the buffer. This method creates a new list to prevent external modification of the buffer. The returned list represents the buffer contents at the moment of the call. This is useful for analysis and reporting.- Returns:
- a new list containing a snapshot of all messages in the buffer
-