Class DatabaseAccumulator

java.lang.Object
com.scivicslab.actoriac.accumulator.DatabaseAccumulator
All Implemented Interfaces:
com.scivicslab.pojoactor.core.accumulator.Accumulator

public class DatabaseAccumulator extends Object implements com.scivicslab.pojoactor.core.accumulator.Accumulator
Accumulator that writes output to an H2 database via DistributedLogStore.

This accumulator writes all output to the H2 database asynchronously. It uses a dedicated executor to avoid blocking workflow execution.

Usage

DatabaseAccumulator dbAcc = new DatabaseAccumulator(logStoreActor, dbExecutor, sessionId);
dbAcc.add("node-1", "stdout", "command output");
dbAcc.add("workflow", "cowsay", renderedCowsayArt);
Since:
2.12.0
Author:
devteam@scivicslab.com
  • Field Details

  • Constructor Details

    • DatabaseAccumulator

      public DatabaseAccumulator(com.scivicslab.pojoactor.core.ActorRef<DistributedLogStore> logStoreActor, ExecutorService dbExecutor, long sessionId)
      Constructs a DatabaseAccumulator.
      Parameters:
      logStoreActor - the actor reference for the distributed log store
      dbExecutor - the executor service for async DB writes
      sessionId - the session ID for this workflow execution
  • Method Details

    • add

      public void add(String source, String type, String data)
      Specified by:
      add in interface com.scivicslab.pojoactor.core.accumulator.Accumulator
    • formatOutput

      private String formatOutput(String source, String data)
      Formats the output with a fixed-width source prefix on each line.
      Parameters:
      source - the source identifier (e.g., "node-web-01", "cli")
      data - the output data (may contain multiple lines)
      Returns:
      the formatted output string with prefix on each line
    • formatPrefix

      private String formatPrefix(String source)
      Creates a prefix from the source name.
      Parameters:
      source - the source identifier
      Returns:
      formatted prefix like "[node-web-01] "
    • getSummary

      public String getSummary()
      Specified by:
      getSummary in interface com.scivicslab.pojoactor.core.accumulator.Accumulator
    • getCount

      public int getCount()
      Specified by:
      getCount in interface com.scivicslab.pojoactor.core.accumulator.Accumulator
    • clear

      public void clear()
      Specified by:
      clear in interface com.scivicslab.pojoactor.core.accumulator.Accumulator