本文整理汇总了Java中org.springframework.batch.core.step.tasklet.Tasklet类的典型用法代码示例。如果您正苦于以下问题:Java Tasklet类的具体用法?Java Tasklet怎么用?Java Tasklet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tasklet类属于org.springframework.batch.core.step.tasklet包,在下文中一共展示了Tasklet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: step1
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
// get path of file in src/main/resources
Path xmlDocPath = Paths.get(getFilePath());
// process the file to json
String json = processXML2JSON(xmlDocPath);
// insert json into mongodb
insertToMongo(json);
return RepeatStatus.FINISHED;
}
}).build();
}
示例2: getTasklet
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
public Tasklet getTasklet(BatchRunConfDto conf, String typeId, String scritpFile) {
String cmd = Paths.get(conf.getBasePath(), scritpFile).toString();
switch (typeId) {
case CMD_TYPE:
cmd = "cmd /c " + cmd;
return new ExecTasklet(cmd, execService, conf);
case SHELL_TYPE:
cmd = "sh -x " + cmd;
return new ExecTasklet(cmd, execService, conf);
case JAR_TYPE:
cmd = "java -jar " + cmd;
return new ExecTasklet(cmd, execService, conf);
case BINARY_TYPE:
return new ExecTasklet(cmd, execService, conf);
case PROC_TYPE:
return new ProcTasklet(scritpFile, jdbcTemplate);
}
return null;
}
示例3: init
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Before
public void init() throws Exception {
this.context.register(BatchConfiguration.class);
this.context.refresh();
JobRepository jobRepository = this.context.getBean(JobRepository.class);
this.jobLauncher = this.context.getBean(JobLauncher.class);
this.jobs = new JobBuilderFactory(jobRepository);
PlatformTransactionManager transactionManager = this.context
.getBean(PlatformTransactionManager.class);
this.steps = new StepBuilderFactory(jobRepository, transactionManager);
this.step = this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
return null;
}
}).build();
this.job = this.jobs.get("job").start(this.step).build();
this.jobExplorer = this.context.getBean(JobExplorer.class);
this.runner = new JobLauncherCommandLineRunner(this.jobLauncher,
this.jobExplorer);
this.context.getBean(BatchConfiguration.class).clear();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:JobLauncherCommandLineRunnerTests.java
示例4: retryFailedExecutionOnNonRestartableJob
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
this.job = this.jobs.get("job").preventRestart()
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
this.runner.execute(this.job, new JobParameters());
this.runner.execute(this.job, new JobParameters());
// A failed job that is not restartable does not re-use the job params of
// the last execution, but creates a new job instance when running it again.
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:JobLauncherCommandLineRunnerTests.java
示例5: retryFailedExecutionWithNonIdentifyingParameters
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
this.job = this.jobs.get("job")
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
.addLong("foo", 2L, false).toJobParameters();
this.runner.execute(this.job, jobParameters);
this.runner.execute(this.job, jobParameters);
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:JobLauncherCommandLineRunnerTests.java
示例6: retryFailedExecutionOnNonRestartableJob
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
this.job = this.jobs.get("job").preventRestart()
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
this.runner.execute(this.job, new JobParameters());
this.runner.execute(this.job, new JobParameters());
// A failed job that is not restartable does not re-use the job params of
// the last execution, but creates a new job instance when running it again.
assertEquals(2, this.jobExplorer.getJobInstances("job", 0, 100).size());
}
示例7: retryFailedExecutionWithNonIdentifyingParameters
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
this.job = this.jobs.get("job")
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
.addLong("foo", 2L, false).toJobParameters();
this.runner.execute(this.job, jobParameters);
this.runner.execute(this.job, jobParameters);
assertEquals(1, this.jobExplorer.getJobInstances("job", 0, 100).size());
}
示例8: importProductsJob
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Bean
public Job importProductsJob(Tasklet decompressTasklet, ItemReader<Product> reader) {
Step decompress = stepBuilders.get("decompress")
.tasklet(decompressTasklet)
.repository(jobRepository)
.transactionManager(transactionManager)
.build();
Step readWriteProducts = stepBuilders.get("readWriteProducts")
.<Product, Product>chunk(3)
.reader(reader)
.writer(writer())
.faultTolerant()
.skipLimit(5)
.skip(FlatFileParseException.class)
.build();
return jobBuilders.get("importProductsJob")
.repository(jobRepository)
.listener(loggerListener)
.start(decompress)
.next(readWriteProducts)
.build();
}
示例9: createTaskletStepWithListener
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
private Step createTaskletStepWithListener(final String taskName,
StepExecutionListener stepExecutionListener) {
return this.steps.get(taskName)
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
})
.transactionAttribute(getTransactionAttribute())
.listener(stepExecutionListener)
.build();
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:14,代码来源:ComposedRunnerVisitorConfiguration.java
示例10: createTaskletStep
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
private Step createTaskletStep(final String taskName) {
return this.steps.get(taskName)
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
})
.transactionAttribute(getTransactionAttribute())
.build();
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:12,代码来源:ComposedRunnerVisitorConfiguration.java
示例11: step2
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
public Step step2(){
return stepBuilderFactory.get("step2")
.tasklet(new Tasklet(){
@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception{
// checks if our collection exists
Boolean doesexist = mongoTemplate.collectionExists("foo");
System.out.println("Status of collection returns :::::::::::::::::::::" + doesexist);
// show all DBObjects in foo collection
DBCursor alldocs = mongoTemplate.getCollection("foo").find();
List<DBObject> dbarray = alldocs.toArray();
System.out.println("list of db objects returns:::::::::::::::::::::" + dbarray);
// execute the three methods we defined for querying the foo collection
String result = doCollect();
String resultTwo = doCollectTwo();
String resultThree = doCollectThree();
System.out.println(" RESULT:::::::::::::::::::::" + result);
System.out.println(" RESULT:::::::::::::::::::::" + resultTwo);
System.out.println(" RESULT:::::::::::::::::::::" + resultThree);
return RepeatStatus.FINISHED;
}
}).build();
}
示例12: optionalStep
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Bean
public Step optionalStep() {
return stepBuilderFactory.get("optionalStep")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
logger.info("IN OPTIONAL STEP ------------------------ */");
return RepeatStatus.FINISHED;
}
})
.build();
}
示例13: githubStep1
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Bean
public Step githubStep1() throws Exception {
return stepBuilderFactory.get("githubStep1")
.tasklet(new Tasklet() {
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) {
// GitHubDTO gitHubDTO = githubJobUI.getDummyStats();
GitHubDTO gitHubDTO = githubJobUI.getGitHubStats();
long currentStatId = githubJobUI.getCurrentGithubId();
gitHubDTO.setStatId(currentStatId);
gitHubDTO.setStatDate(new Date());
githubJobUI.saveGithubStats(gitHubDTO);
chunkContext
.getStepContext()
.getStepExecution()
.getJobExecution()
.getExecutionContext()
.put("statId", currentStatId);
logger.info("Working with GitHubDTO: " + gitHubDTO.toString());
return RepeatStatus.FINISHED;
}
})
.listener(githubPromotionListener())
.build();
}
示例14: tasklet
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Bean
public Tasklet tasklet() {
return (contribution, chunkContext) -> {
log.info("Executing tasklet step");
return RepeatStatus.FINISHED;
};
}
示例15: retryFailedExecution
import org.springframework.batch.core.step.tasklet.Tasklet; //导入依赖的package包/类
@Test
public void retryFailedExecution() throws Exception {
this.job = this.jobs.get("job")
.start(this.steps.get("step").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
throw new RuntimeException("Planned");
}
}).build()).incrementer(new RunIdIncrementer()).build();
this.runner.execute(this.job, new JobParameters());
this.runner.execute(this.job, new JobParameters());
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:JobLauncherCommandLineRunnerTests.java