-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from zahidMed/master
release 1.0.0
- Loading branch information
Showing
25 changed files
with
291 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,38 +16,36 @@ | |
import org.aspectj.lang.annotation.Aspect; | ||
|
||
/** | ||
* Aspect that intercepts the call of job run method in order to allow the {@link JobExecutionContextListener} to insert | ||
* the parameters they need for restoring their contexts. | ||
* Aspect that intercepts the call of job run method in order to allow the | ||
* {@link JobExecutionContextListener} to insert the parameters they need for | ||
* restoring their contexts. | ||
* | ||
* @author Mohammed ZAHID <[email protected]> | ||
* | ||
*/ | ||
@Aspect | ||
@Service | ||
public class JobExecutionAspect { | ||
|
||
|
||
|
||
protected List<JobExecutionContextListener> jobExecutionContextListeners; | ||
public JobExecutionAspect(List<JobExecutionContextListener> jobExecutionContextListeners){ | ||
this.jobExecutionContextListeners= jobExecutionContextListeners; | ||
|
||
public JobExecutionAspect(List<JobExecutionContextListener> jobExecutionContextListeners) { | ||
this.jobExecutionContextListeners = jobExecutionContextListeners; | ||
} | ||
|
||
|
||
|
||
@Around("execution(* org.springframework.batch.core.launch.JobLauncher+.run(..))") | ||
public JobExecution beforeRun(ProceedingJoinPoint joinPoint) throws Throwable | ||
{ | ||
JobParameters jobParameters=(JobParameters) joinPoint.getArgs()[1]; | ||
JobParametersBuilder jobParametersBuilder= new JobParametersBuilder(jobParameters); | ||
if(!CollectionUtils.isEmpty(jobExecutionContextListeners)){ | ||
Iterator<JobExecutionContextListener> iter= jobExecutionContextListeners.iterator(); | ||
while(iter.hasNext()){ | ||
public JobExecution beforeRun(ProceedingJoinPoint joinPoint) throws Throwable { | ||
JobParameters jobParameters = (JobParameters) joinPoint.getArgs()[1]; | ||
JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(jobParameters); | ||
if (!CollectionUtils.isEmpty(jobExecutionContextListeners)) { | ||
Iterator<JobExecutionContextListener> iter = jobExecutionContextListeners.iterator(); | ||
while (iter.hasNext()) { | ||
iter.next().insertContextInfo(jobParametersBuilder); | ||
} | ||
} | ||
return (JobExecution)joinPoint.proceed(new Object[] {joinPoint.getArgs()[0],jobParametersBuilder.toJobParameters()}); | ||
|
||
} | ||
return (JobExecution) joinPoint | ||
.proceed(new Object[] { joinPoint.getArgs()[0], jobParametersBuilder.toJobParameters() }); | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,45 +7,53 @@ | |
import com.digibooster.spring.batch.aop.JobExecutionAspect; | ||
|
||
/** | ||
* Allow the restoring the context of the thread that runs the job inside the job it self. | ||
* Allow the restoring the context of the thread that runs the job inside the | ||
* job it self. | ||
* | ||
* @author Mohammed ZAHID <[email protected]> | ||
* | ||
*/ | ||
public interface JobExecutionContextListener { | ||
|
||
/** | ||
* Serializes the current context information and puts it in the the job parameter. | ||
* This method called by the Aspect {@link JobExecutionAspect} | ||
* Serializes the current context information and puts it in the the job | ||
* parameter. This method called by the Aspect {@link JobExecutionAspect} | ||
* | ||
* @param jobParametersBuilder | ||
*/ | ||
void insertContextInfo(JobParametersBuilder jobParametersBuilder); | ||
|
||
/** | ||
* Deserializes the context information from the job parameters and inserts it in the Job execution context. | ||
* This method is called by the Job listener {@link JobExecutionListenerContextSupport} | ||
* Deserializes the context information from the job parameters and inserts it | ||
* in the Job execution context. This method is called by the Job listener | ||
* {@link JobExecutionListenerContextSupport} | ||
* | ||
* @param jobExecution | ||
*/ | ||
void fillJobExecutionContext(JobExecution jobExecution); | ||
|
||
/** | ||
* Removes the context information from job execution context when the job ends | ||
* This method is called by the Job listener {@link JobExecutionListenerContextSupport} | ||
* This method is called by the Job listener | ||
* {@link JobExecutionListenerContextSupport} | ||
* | ||
* @param jobExecution | ||
*/ | ||
void removeFromJobExecutionContext(JobExecution jobExecution); | ||
|
||
|
||
/** | ||
* Restore the context information from the job execution context before each step | ||
* This method is called by the Step listener {@link StepExecutionListenerContextSupport} | ||
* Restore the context information from the job execution context before each | ||
* step This method is called by the Step listener | ||
* {@link StepExecutionListenerContextSupport} | ||
* | ||
* @param stepExecution | ||
*/ | ||
void restoreContext(StepExecution stepExecution); | ||
|
||
|
||
/** | ||
* Remove the context information when the step ends | ||
* This method is called by the Step listener {@link StepExecutionListenerContextSupport} | ||
* Remove the context information when the step ends This method is called by | ||
* the Step listener {@link StepExecutionListenerContextSupport} | ||
* | ||
* @param stepExecution | ||
*/ | ||
void clearContext(StepExecution stepExecution); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,38 +8,40 @@ | |
import org.springframework.util.CollectionUtils; | ||
|
||
/** | ||
* Listener that call the registered {@link JobExecutionContextListener} before and after running the batch jobs. | ||
* Listener that call the registered {@link JobExecutionContextListener} before | ||
* and after running the batch jobs. | ||
* | ||
* @author Mohammed ZAHID <[email protected]> | ||
* | ||
*/ | ||
public class JobExecutionListenerContextSupport implements JobExecutionListener { | ||
|
||
protected List<JobExecutionContextListener> jobExecutionContextListeners; | ||
public JobExecutionListenerContextSupport(List<JobExecutionContextListener> jobExecutionContextListeners){ | ||
this.jobExecutionContextListeners= jobExecutionContextListeners; | ||
|
||
public JobExecutionListenerContextSupport(List<JobExecutionContextListener> jobExecutionContextListeners) { | ||
this.jobExecutionContextListeners = jobExecutionContextListeners; | ||
} | ||
|
||
@Override | ||
public void beforeJob(JobExecution jobExecution) { | ||
if(!CollectionUtils.isEmpty(jobExecutionContextListeners)){ | ||
Iterator<JobExecutionContextListener> iter= jobExecutionContextListeners.iterator(); | ||
while(iter.hasNext()){ | ||
if (!CollectionUtils.isEmpty(jobExecutionContextListeners)) { | ||
Iterator<JobExecutionContextListener> iter = jobExecutionContextListeners.iterator(); | ||
while (iter.hasNext()) { | ||
iter.next().fillJobExecutionContext(jobExecution); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void afterJob(JobExecution jobExecution) { | ||
if(!CollectionUtils.isEmpty(jobExecutionContextListeners)){ | ||
Iterator<JobExecutionContextListener> iter= jobExecutionContextListeners.iterator(); | ||
while(iter.hasNext()){ | ||
if (!CollectionUtils.isEmpty(jobExecutionContextListeners)) { | ||
Iterator<JobExecutionContextListener> iter = jobExecutionContextListeners.iterator(); | ||
while (iter.hasNext()) { | ||
iter.next().removeFromJobExecutionContext(jobExecution); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,36 +9,36 @@ | |
import org.springframework.util.CollectionUtils; | ||
|
||
/** | ||
* Listener that call the registered {@link JobExecutionContextListener} before and after running the batch steps. | ||
* Listener that call the registered {@link JobExecutionContextListener} before | ||
* and after running the batch steps. | ||
* | ||
* @author Mohammed ZAHID <[email protected]> | ||
* | ||
*/ | ||
public class StepExecutionListenerContextSupport implements StepExecutionListener{ | ||
public class StepExecutionListenerContextSupport implements StepExecutionListener { | ||
|
||
|
||
protected List<JobExecutionContextListener> jobExecutionContextListeners; | ||
|
||
public StepExecutionListenerContextSupport(List<JobExecutionContextListener> jobExecutionContextListeners){ | ||
this.jobExecutionContextListeners= jobExecutionContextListeners; | ||
protected List<JobExecutionContextListener> jobExecutionContextListeners; | ||
|
||
public StepExecutionListenerContextSupport(List<JobExecutionContextListener> jobExecutionContextListeners) { | ||
this.jobExecutionContextListeners = jobExecutionContextListeners; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public void beforeStep(StepExecution stepExecution) { | ||
if(!CollectionUtils.isEmpty(jobExecutionContextListeners)){ | ||
Iterator<JobExecutionContextListener> iter= jobExecutionContextListeners.iterator(); | ||
while(iter.hasNext()){ | ||
if (!CollectionUtils.isEmpty(jobExecutionContextListeners)) { | ||
Iterator<JobExecutionContextListener> iter = jobExecutionContextListeners.iterator(); | ||
while (iter.hasNext()) { | ||
iter.next().restoreContext(stepExecution); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public ExitStatus afterStep(StepExecution stepExecution) { | ||
if(!CollectionUtils.isEmpty(jobExecutionContextListeners)){ | ||
Iterator<JobExecutionContextListener> iter= jobExecutionContextListeners.iterator(); | ||
while(iter.hasNext()){ | ||
if (!CollectionUtils.isEmpty(jobExecutionContextListeners)) { | ||
Iterator<JobExecutionContextListener> iter = jobExecutionContextListeners.iterator(); | ||
while (iter.hasNext()) { | ||
iter.next().clearContext(stepExecution); | ||
} | ||
} | ||
|
31 changes: 0 additions & 31 deletions
31
...h-context-commons/src/main/java/com/digibooster/spring/batch/util/CustomJobParameter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.