Class FileAccumulator
java.lang.Object
com.scivicslab.pojoactor.workflow.accumulator.FileAccumulator
- All Implemented Interfaces:
Accumulator,Closeable,AutoCloseable
Accumulator that writes output to a text file.
This accumulator writes all output to a text file as it arrives. The output format is identical to what appears on the console, ensuring consistency across all output destinations.
Usage
try (FileAccumulator fileAcc = new FileAccumulator(Path.of("run.log"))) {
fileAcc.add("node-1", "stdout", "command output");
fileAcc.add("workflow", "cowsay", renderedCowsayArt);
}
- Since:
- 2.12.0
- Author:
- devteam@scivicslab.com
-
Constructor Summary
ConstructorsConstructorDescriptionFileAccumulator(String filePath) Constructs a FileAccumulator that writes to the specified file.FileAccumulator(Path filePath) Constructs a FileAccumulator that writes to the specified file. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a result to this accumulator.voidclear()Clears all accumulated results.voidclose()Closes the file writer.intgetCount()Returns the number of results that have been added.Returns the path to the output file.Returns a formatted summary of all accumulated results.
-
Constructor Details
-
FileAccumulator
Constructs a FileAccumulator that writes to the specified file.- Parameters:
filePath- the path to the output file- Throws:
IOException- if the file cannot be opened for writing
-
FileAccumulator
Constructs a FileAccumulator that writes to the specified file.- Parameters:
filePath- the path to the output file as a string- Throws:
IOException- if the file cannot be opened for writing
-
-
Method Details
-
getFilePath
Returns the path to the output file.- Returns:
- the file path
-
add
Description copied from interface:AccumulatorAdds a result to this accumulator.- Specified by:
addin interfaceAccumulator- Parameters:
source- the source identifier (e.g., actor name like "node-localhost")type- the type of result (e.g., "cpu", "memory", "error")data- the result data as a string
-
getSummary
Description copied from interface:AccumulatorReturns a formatted summary of all accumulated results.The format of the summary depends on the implementation. For example,
StreamingAccumulatorreturns a simple count, whileBufferedAccumulatorreturns all results grouped by source.- Specified by:
getSummaryin interfaceAccumulator- Returns:
- the formatted summary string
-
getCount
public int getCount()Description copied from interface:AccumulatorReturns the number of results that have been added.- Specified by:
getCountin interfaceAccumulator- Returns:
- the count of added results
-
clear
public void clear()Description copied from interface:AccumulatorClears all accumulated results.After calling this method, the accumulator should be in its initial state, as if no results had been added.
- Specified by:
clearin interfaceAccumulator
-
close
public void close()Closes the file writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-