Class AuditEventRecorder

java.lang.Object
com.broadleafcommerce.common.audit.AuditEventRecorder
All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationListener<AuditApplicationEvent>, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class AuditEventRecorder extends Object implements org.springframework.context.SmartLifecycle, org.springframework.context.ApplicationListener<AuditApplicationEvent>
Async recorder of AuditEvent instances fired from ChangeAuditHandler. Leverages StorageProvider as events are serialized to json, stored in batch files, and eventually flushed to a completion file for eventual ingestion via AuditServices.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    protected boolean
     

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    AuditEventRecorder(org.springframework.scheduling.TaskScheduler scheduler, AuditProcessingProperties properties, org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor executor, com.fasterxml.jackson.databind.ObjectMapper objectMapper, StorageProvider storageProvider, org.springframework.context.ApplicationEventPublisher eventPublisher)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Batch
    append(String json)
    Append a json converted value of an AuditEvent to batch storage.
    protected void
    flush(Batch batch)
    Push a Batch to completion storage.
    boolean
     
    boolean
     
    boolean
     
    void
     
    protected Batch
    prepare(boolean force)
    Prepare a Batch storage representation for flushing to completion storage.
    protected void
    process(AuditEvent auditEvent)
    Convert an event to json, append to a batch file (see Batch), and flush to a completion file, if ready.
    void
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.context.ApplicationListener

    supportsAsyncExecution

    Methods inherited from interface org.springframework.context.SmartLifecycle

    getPhase, stop
  • Field Details

  • Constructor Details

    • AuditEventRecorder

      public AuditEventRecorder(org.springframework.scheduling.TaskScheduler scheduler, AuditProcessingProperties properties, org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor executor, com.fasterxml.jackson.databind.ObjectMapper objectMapper, StorageProvider storageProvider, org.springframework.context.ApplicationEventPublisher eventPublisher)
  • Method Details

    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • onApplicationEvent

      public void onApplicationEvent(AuditApplicationEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<AuditApplicationEvent>
    • isAutoStartup

      public boolean isAutoStartup()
      Specified by:
      isAutoStartup in interface org.springframework.context.SmartLifecycle
    • process

      protected void process(AuditEvent auditEvent)
      Convert an event to json, append to a batch file (see Batch), and flush to a completion file, if ready.
      Parameters:
      auditEvent - The event to push to storage
    • append

      @Nullable protected Batch append(String json)
      Append a json converted value of an AuditEvent to batch storage.
      Parameters:
      json - The converted AuditEvent
      Returns:
      A Batch ready to flush to completion, or null if no Batch is ready to flush.
    • prepare

      @Nullable protected Batch prepare(boolean force)
      Prepare a Batch storage representation for flushing to completion storage. If the Batch.count() satisfies AuditProcessingProperties.getEventRecorderBatchFileMaxRecordCount(), or force is true, then the current Batch is made ready for completion.
      Parameters:
      force - Whether a non-empty Batch should be flushed to completion, regardless of whether it has met the configured size requirements
      Returns:
      A Batch ready to flush to completion, or null if no Batch is ready to flush.
    • flush

      protected void flush(@Nullable Batch batch)
      Push a Batch to completion storage. Do nothing if null.
      Parameters:
      batch - The Batch to complete.
    • isStarted

      public boolean isStarted()