forked from hibernate/hibernate-search
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#24 add decider and purger batchlet before the doc production chunk
Decider and purger batchlet provide a before-production enhancement. User can now have possibility to purge all index before started. However, this commit provides only the working model, method inside the batchlet is not implemented yet.
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
us-address/src/main/java/io/github/mincongh/batch/BeforeIndexDecider.java
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.github.mincongh.batch; | ||
|
||
import javax.batch.api.BatchProperty; | ||
import javax.batch.api.Decider; | ||
import javax.batch.runtime.StepExecution; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
/** | ||
* Decider decides the next step-execution before the start of index chunk. If | ||
* user requires a index purge, then the next step should be a purge, else, | ||
* the next step will be directly the index chunk. Index purge use | ||
* IndexPurgerBatchlet. | ||
* | ||
* @author Mincong HUANG | ||
*/ | ||
@Named | ||
public class BeforeIndexDecider implements Decider { | ||
|
||
@Inject @BatchProperty | ||
private Boolean purgeAtStart; | ||
private final String PURGE_IDX = "purgeIndex"; | ||
private final String PRODUCE_DOC = "produceLuceneDoc"; | ||
|
||
/** | ||
* Decide the next step | ||
* | ||
* @param executions not used for the moment. | ||
*/ | ||
@Override | ||
public String decide(StepExecution[] executions) throws Exception { | ||
|
||
String nextStep = purgeAtStart ? PURGE_IDX : PRODUCE_DOC; | ||
|
||
for (StepExecution se : executions) { | ||
System.out.println(se.getStepName() + " " | ||
+ se.getBatchStatus().toString() + " " | ||
+ se.getExitStatus() | ||
); | ||
} | ||
|
||
return nextStep; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
us-address/src/main/java/io/github/mincongh/batch/IndexPurgerBatchlet.java
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.mincongh.batch; | ||
|
||
import javax.batch.api.Batchlet; | ||
import javax.batch.runtime.BatchStatus; | ||
import javax.inject.Named; | ||
|
||
@Named | ||
public class IndexPurgerBatchlet implements Batchlet { | ||
|
||
@Override | ||
public String process() throws Exception { | ||
|
||
System.out.println("purging entities ..."); | ||
|
||
return BatchStatus.COMPLETED.toString(); | ||
} | ||
|
||
@Override | ||
public void stop() throws Exception { | ||
// TODO Auto-generated method stub | ||
} | ||
} |
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