Class JsonAccumulator

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

public class JsonAccumulator extends Object implements Accumulator
An accumulator that outputs results in JSON format.

This accumulator organizes results as a JSON object where keys are source identifiers and values are objects containing type-data pairs. This is useful for API responses, log storage, and external system integration.

Example Output

 {
   "node-localhost": {
     "cpu": "AMD Ryzen 7 7700 8-Core Processor",
     "gpu": "NVIDIA GeForce RTX 4080",
     "memory": "62Gi"
   }
 }
 
Since:
2.8.0
Author:
devteam@scivics-lab.com
  • Constructor Details

    • JsonAccumulator

      public JsonAccumulator()
  • Method Details

    • add

      public void add(String source, String type, String data)
      Description copied from interface: Accumulator
      Adds a result to this accumulator.
      Specified by:
      add in interface Accumulator
      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

      public String getSummary()
      Description copied from interface: Accumulator
      Returns a formatted summary of all accumulated results.

      The format of the summary depends on the implementation. For example, StreamingAccumulator returns a simple count, while BufferedAccumulator returns all results grouped by source.

      Specified by:
      getSummary in interface Accumulator
      Returns:
      the formatted summary string
    • getCount

      public int getCount()
      Description copied from interface: Accumulator
      Returns the number of results that have been added.
      Specified by:
      getCount in interface Accumulator
      Returns:
      the count of added results
    • clear

      public void clear()
      Description copied from interface: Accumulator
      Clears all accumulated results.

      After calling this method, the accumulator should be in its initial state, as if no results had been added.

      Specified by:
      clear in interface Accumulator
    • getResultsAsJson

      public org.json.JSONObject getResultsAsJson()
      Returns the results as a JSONObject.

      Note: This returns a copy to prevent external modification.

      Returns:
      a copy of the results JSONObject