Class DatabaseAccumulator

java.lang.Object
com.scivicslab.turingworkflow.plugins.logdb.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.

Since:
1.0
Author:
devteam@scivicslab.com
  • 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)
      Adds an output entry to the database log store.

      If the log store actor is not available or the session ID is invalid, the entry is silently skipped but still counted. Null or empty data is also skipped. Writing is fire-and-forget to avoid blocking workflow execution.

      Specified by:
      add in interface com.scivicslab.pojoactor.core.accumulator.Accumulator
      Parameters:
      source - the source identifier (typically the node ID)
      type - the output type (used as the label in the log entry)
      data - the output data to log, may be null or empty
    • getSummary

      public String getSummary()
      Returns a summary string describing the accumulator state.
      Specified by:
      getSummary in interface com.scivicslab.pojoactor.core.accumulator.Accumulator
      Returns:
      a human-readable summary including the entry count and session ID
    • getCount

      public int getCount()
      Returns the number of entries processed by this accumulator.
      Specified by:
      getCount in interface com.scivicslab.pojoactor.core.accumulator.Accumulator
      Returns:
      the total entry count (including skipped entries)
    • clear

      public void clear()
      Resets the entry count to zero.
      Specified by:
      clear in interface com.scivicslab.pojoactor.core.accumulator.Accumulator