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 Batch
Append a json converted value of anAuditEvent
to batch storage.protected void
Push aBatch
to completion storage.boolean
boolean
boolean
void
protected Batch
prepare
(boolean force) Prepare aBatch
storage representation for flushing to completion storage.protected void
process
(AuditEvent auditEvent) Convert an event to json, append to a batch file (seeBatch
), and flush to a completion file, if ready.void
start()
void
stop()
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
-
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:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
onApplicationEvent
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<AuditApplicationEvent>
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartup
in 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 anAuditEvent
to batch storage.- Parameters:
json
- The convertedAuditEvent
- Returns:
- A
Batch
ready to flush to completion, or null if noBatch
is ready to flush.
-
prepare
Prepare aBatch
storage representation for flushing to completion storage. If theBatch.count()
satisfiesAuditProcessingProperties.getEventRecorderBatchFileMaxRecordCount()
, orforce
is true, then the currentBatch
is made ready for completion. -
flush
Push aBatch
to completion storage. Do nothing if null.- Parameters:
batch
- TheBatch
to complete.
-
isStarted
public boolean isStarted()
-