本文整理汇总了Java中org.springframework.batch.item.ExecutionContext类的典型用法代码示例。如果您正苦于以下问题:Java ExecutionContext类的具体用法?Java ExecutionContext怎么用?Java ExecutionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExecutionContext类属于org.springframework.batch.item包,在下文中一共展示了ExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Override
public void open(ExecutionContext executionContext) throws
ItemStreamException {
if (executionContext == null) {
throw new IllegalArgumentException();
}
if (executionContext.containsKey(IDS_NUMBER)) {
number = executionContext.getInt(IDS_NUMBER);
count = executionContext.getInt(CURRENT_ID_COUNT);
ids = new String[number];
for (int i = 0; i < number; i++) {
ids[i] = executionContext.getString(LIST_ID + i);
}
} else {
ids = loadListIds();
number = ids.length;
count = 0;
}
}
示例2: execute
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
/**
* Executes the task as specified by the taskName with the associated
* properties and arguments.
* @param contribution mutable state to be passed back to update the current step execution
* @param chunkContext contains the task-execution-id used by the listener.
* @return Repeat status of FINISHED.
*/
@Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext chunkContext) throws Exception {
String tmpTaskName = this.taskName.substring(0,
this.taskName.lastIndexOf('_'));
List<String> args = this.arguments;
ExecutionContext stepExecutionContext = chunkContext.getStepContext().getStepExecution().
getExecutionContext();
if(stepExecutionContext.containsKey("task-arguments")) {
args = (List<String>) stepExecutionContext.get("task-arguments");
}
long executionId = this.taskOperations.launch(tmpTaskName,
this.properties, args);
stepExecutionContext.put("task-execution-id", executionId);
stepExecutionContext.put("task-arguments", args);
waitForTaskToComplete(executionId);
return RepeatStatus.FINISHED;
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:32,代码来源:TaskLauncherTasklet.java
示例3: testCreateReaderAndFailToRead
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Test(expected = FlatFileParseException.class)
public void testCreateReaderAndFailToRead() throws Exception {
// given
final ExecutionContext executionContext = mock(ExecutionContext.class);
// when
final ItemStreamReader<Ticket> reader = factory.createReader(new ClassPathResource("tickets-fail.csv"));
try {
reader.open(executionContext);
System.out.println(reader.read());
} finally {
reader.close();
}
// then
}
示例4: afterJob
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Override
public void afterJob(final JobExecution jobExecution) {
if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus())) {
final ExecutionContext executionContext = jobExecution.getExecutionContext();
final String inputFile = executionContext.getString(LHHuntingClubBatchConfig.KEY_INPUT_FILE, null);
if (inputFile != null) {
final Path path = Paths.get(inputFile);
try {
LOG.info("Deleting temporary file: {}", inputFile);
Files.deleteIfExists(path);
} catch (IOException e) {
e.printStackTrace();
}
} else {
LOG.warn("Input file not found in context");
}
}
}
示例5: assertCorrectMixins
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
private void assertCorrectMixins(RestTemplate restTemplate) {
boolean containsMappingJackson2HttpMessageConverter = false;
for (HttpMessageConverter<?> converter : restTemplate.getMessageConverters()) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
containsMappingJackson2HttpMessageConverter = true;
final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
final ObjectMapper objectMapper = jacksonConverter.getObjectMapper();
assertNotNull(objectMapper.findMixInClassFor(JobExecution.class));
assertNotNull(objectMapper.findMixInClassFor(JobParameters.class));
assertNotNull(objectMapper.findMixInClassFor(JobParameter.class));
assertNotNull(objectMapper.findMixInClassFor(JobInstance.class));
assertNotNull(objectMapper.findMixInClassFor(ExitStatus.class));
assertNotNull(objectMapper.findMixInClassFor(StepExecution.class));
assertNotNull(objectMapper.findMixInClassFor(ExecutionContext.class));
assertNotNull(objectMapper.findMixInClassFor(StepExecutionHistory.class));
}
}
if (!containsMappingJackson2HttpMessageConverter) {
fail("Expected that the restTemplate's list of Message Converters contained a "
+ "MappingJackson2HttpMessageConverter");
}
}
示例6: testRead
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
/**
* @throws Exception if there is a problem accessing the file
*/
@Test
public final void testRead() throws Exception {
expect(conversionService.convert(isA(String.class), isA(TypeDescriptor.class), isA(TypeDescriptor.class))).andReturn(new TreeSet<>(Arrays.asList(DescriptionType.general)));
expect(conversionService.convert(isA(String.class), eq(DateTime.class))).andReturn(new DateTime());
expect(taxonService.find(isA(String.class))).andReturn(new Taxon()).anyTimes();
expect(taxonService.find(isA(String.class), eq("taxon-with-content"))).andReturn(new Taxon()).anyTimes();
replay(taxonService,conversionService);
flatFileItemReader.open(new ExecutionContext());
flatFileItemReader.read();
}
示例7: setupMockMVC
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Before
public void setupMockMVC() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
.defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)).build();
if (!initialized) {
createStepExecution(JOB_NAME_ORIG, STEP_NAME_ORIG);
createStepExecution(JOB_NAME_FOO, STEP_NAME_ORIG, STEP_NAME_FOO);
createStepExecution(JOB_NAME_FOOBAR, STEP_NAME_ORIG, STEP_NAME_FOO, STEP_NAME_FOOBAR);
initialized = true;
}
for (HttpMessageConverter<?> converter : adapter.getMessageConverters()) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
jacksonConverter.getObjectMapper().addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class);
jacksonConverter.getObjectMapper().addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
jacksonConverter.getObjectMapper().setDateFormat(new ISO8601DateFormatWithMilliSeconds());
}
}
}
示例8: testSerializationOfSingleStepExecution
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
/**
* Assert that by using the {@link ExecutionContextJacksonMixIn} Jackson renders the
* Step Execution Context correctly.
*
* @throws JsonProcessingException if a Json generation error occurs.
*/
@Test
public void testSerializationOfSingleStepExecution() throws JsonProcessingException {
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class);
objectMapper.addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
final StepExecution stepExecution = getStepExecution();
final String result = objectMapper.writeValueAsString(stepExecution);
assertThat(result, not(containsString("\"executionContext\":{\"dirty\":true,\"empty\":false}")));
assertThat(result, containsString("\"executionContext\":{\"dirty\":true,\"empty\":false,\"values\":[{"));
assertThat(result, containsString("{\"counter\":1234}"));
assertThat(result, containsString("{\"myDouble\":1.123456}"));
assertThat(result, containsString("{\"Josh\":4444444444}"));
assertThat(result, containsString("{\"awesomeString\":\"Yep\"}"));
assertThat(result, containsString("{\"hello\":\"world\""));
assertThat(result, containsString("{\"counter2\":9999}"));
}
示例9: update
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Override
public void update(ExecutionContext executionContext) throws
ItemStreamException {
/* Clear context */
for (Entry<String, Object> entry : executionContext.entrySet()) {
String key = entry.getKey();
executionContext.remove(key);
}
executionContext.putInt(IDS_NUMBER, number);
executionContext.putInt(CURRENT_ID_COUNT, count);
for (int i = 0; i < number; i++) {
executionContext.putString(LIST_ID + i, ids[i]);
}
}
示例10: testCreateReaderAndReadCorrectData
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Test
public void testCreateReaderAndReadCorrectData() throws Exception {
// given
final ExecutionContext executionContext = mock(ExecutionContext.class);
final LocalDate date = LocalDate.of(2015, 12, 20);
// when
final ItemStreamReader<Ticket> reader = factory.createReader(new ClassPathResource("tickets.csv"));
final Ticket ticket;
try {
reader.open(executionContext);
ticket = reader.read();
} finally {
reader.close();
}
// then
assertThat(ticket, notNullValue());
assertThat(ticket.getTag(), equalTo("Ticket_0"));
assertThat(ticket.getDate(), equalTo(Date.valueOf(date)));
assertThat(ticket.getContent(), equalTo("Test ticket"));
}
示例11: update
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Override
public void update(ExecutionContext executionContext) {
if (state == null) {
throw new ItemStreamException(
"ItemStream not open or already closed.");
}
Assert.notNull(executionContext, "ExecutionContext must not be null");
if (saveState) {
try {
executionContext.putLong(
getExecutionContextKey(RESTART_DATA_NAME),
state.position());
} catch (IOException e) {
throw new ItemStreamException(
"ItemStream does not return current position properly",
e);
}
executionContext.putLong(
getExecutionContextKey(WRITTEN_STATISTICS_NAME),
state.jsonObjectsWritten);
}
}
示例12: restoreFrom
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
/**
* @param executionContext
*/
public void restoreFrom(ExecutionContext executionContext) {
lastMarkedByteOffsetPosition = executionContext
.getLong(getExecutionContextKey(RESTART_DATA_NAME));
jsonObjectsWritten = executionContext
.getLong(getExecutionContextKey(WRITTEN_STATISTICS_NAME));
if (shouldDeleteIfEmpty && jsonObjectsWritten == 0) {
// previous execution deleted the output file because no items
// were written
restarted = false;
lastMarkedByteOffsetPosition = 0;
} else {
restarted = true;
}
}
示例13: execute
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
/**
* @param contribution Set the step contribution
* @param chunkContext Set the chunk context
* @return the repeat status
* @throws Exception if there is a problem deleting the resources
*/
public final RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext)
throws Exception {
UUID uuid = UUID.randomUUID();
String unpackDirectoryName = harvesterSpoolDirectory + File.separator
+ uuid.toString();
String temporaryFileName = harvesterSpoolDirectory + File.separator
+ uuid.toString() + ".zip";
File unpackDirectory = new File(unpackDirectoryName);
unpackDirectory.mkdir();
File temporaryFile = new File(temporaryFileName);
ExecutionContext executionContext = chunkContext.getStepContext()
.getStepExecution().getJobExecution().getExecutionContext();
executionContext.put("temporary.file.name",temporaryFile.getAbsolutePath());
executionContext.put("unpack.directory.name",unpackDirectory.getAbsolutePath());
executionContext.putLong("job.execution.id", chunkContext.getStepContext().getStepExecution().getJobExecutionId());
return RepeatStatus.FINISHED;
}
示例14: testExecutionContext
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Test
public void testExecutionContext() {
ExecutionContext executionContext = new ExecutionContext();
executionContext.put("hello", "world");
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent();
assertNotNull(jobExecutionEvent.getExecutionContext());
jobExecutionEvent.setExecutionContext(executionContext);
assertEquals("world", jobExecutionEvent.getExecutionContext().getString("hello"));
}
示例15: setUp
import org.springframework.batch.item.ExecutionContext; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
lineTokenizer.setDelimiter('\t');
lineTokenizer.setNames(new String[] {"foo","bar"});
lineTokenizer.setStrict(false);
DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>();
lineMapper.setLineTokenizer(lineTokenizer);
lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
flatFileItemReader = new FlatFileItemReader<FieldSet>();
flatFileItemReader.setEncoding("UTF-8");
flatFileItemReader.setLinesToSkip(0);
flatFileItemReader.setLineMapper(lineMapper);
flatFileItemReader.setResource(new ClassPathResource("org/emonocot/bom.txt"));
flatFileItemReader.setBufferedReaderFactory(new BOMIgnoringBufferedReaderFactory());
flatFileItemReader.afterPropertiesSet();
flatFileItemReader.open(new ExecutionContext());
}