-
Notifications
You must be signed in to change notification settings - Fork 198
listeners
Listeners allow you to plugin custom behavior in the workflow in a AOP style. You can register listeners to do pre/post processing before/after the entire job or a specific step.
To listen to job related events, you need to register an implementation of the JobListener
interface:
public interface JobListener {
void beforeJobStart(JobParameters parameters);
void afterJobEnd(JobReport report);
}
The next figure shows when each method of the JobListener
is called in the processing workflow:
You can register a custom job listener using the JobBuilder
API:
Job job = new JobBuilder()
.jobListener(new MyJobListener())
.build();
Several use cases can be implemented using this listener:
- Setup/cleanup resources before/after the job
- Lock/Unlock working directory at job start/stop
- Archive log files at the end of Job
- Send job report by email at the end of execution
- etc
The RecordReaderListener
and RecordWriterListener
allow you to get notified before/after reading/writing each record:
public interface RecordReaderListener {
void beforeRecordReading();
void afterRecordReading(Record record);
void onRecordReadingException(final Throwable throwable);
}
public interface RecordWriterListener {
void beforeRecordWriting(Batch batch);
void afterRecordWriting(Batch batch);
void onRecordWritingException(Batch batch, final Throwable throwable);
}
Here is when each method is called in the processing workflow:
You can register a custom record reader/writer listener using the JobBuilder
API:
Job job = new JobBuilder()
.readerListener(new MyReaderListener())
.writerListener(new MyWriterListener())
.build();
The PipelineListener
allows you to get notified before/after processing each record:
public interface PipelineListener {
Record beforeRecordProcessing(final Record record);
void afterRecordProcessing(final Record inputRecord, final Record outputRecord);
void onRecordProcessingException(final Record record, final Throwable throwable);
}
Here is when each method is called in the processing workflow:
You can register a custom pipeline listener using the JobBuilder
API:
Job job = new JobBuilder()
.pipelineListener(new MyPipelineListener())
.build();
Here are some use cases:
- Calculate the processing time for each record
- Custom Pre/Post processing for each record
- etc
The BatchListener
allows you to get notified before/after processing each batch:
public interface BatchListener {
void beforeBatchReading();
void afterBatchProcessing(final Batch batch);
void afterBatchWriting(final Batch batch);
void onBatchWritingException(final Batch batch, Throwable throwable);
}
Here is when each method is called in the processing workflow:
You can register a custom batch listener using the JobBuilder
API:
Job job = new JobBuilder()
.batchListener(new MyBatchListener())
.build();
Here are some use cases:
- Define transaction boundaries
- Custom Pre/Post processing for each batch
- etc
Easy Batch is created by Mahmoud Ben Hassine with the help of some awesome contributors
-
Introduction
-
User guide
-
Job reference
-
Component reference
-
Get involved