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
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionAuditEventRecorder(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 TypeMethodDescriptionprotected BatchAppend a json converted value of anAuditEventto batch storage.protected voidPush aBatchto completion storage.booleanbooleanbooleanvoidprotected Batchprepare(boolean force) Prepare aBatchstorage representation for flushing to completion storage.protected voidprocess(AuditEvent auditEvent) Convert an event to json, append to a batch file (seeBatch), and flush to a completion file, if ready.voidstart()voidstop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isPauseable, stop
-
Field Details
-
RECORD_END_MARKER
- See Also:
-
started
protected boolean started
-
-
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:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
onApplicationEvent
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<AuditApplicationEvent>
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
process
Convert an event to json, append to a batch file (seeBatch), and flush to a completion file, if ready.- Parameters:
auditEvent- The event to push to storage
-
append
Append a json converted value of anAuditEventto batch storage.- Parameters:
json- The convertedAuditEvent- Returns:
- A
Batchready to flush to completion, or null if noBatchis ready to flush.
-
prepare
Prepare aBatchstorage representation for flushing to completion storage. If theBatch.count()satisfiesAuditProcessingProperties.getEventRecorderBatchFileMaxRecordCount(), orforceis true, then the currentBatchis made ready for completion. -
flush
Push aBatchto completion storage. Do nothing if null.- Parameters:
batch- TheBatchto complete.
-
isStarted
public boolean isStarted()
-