当前位置: 首页>>代码示例>>Java>>正文


Java ExecutionContext类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:hosuaby,项目名称:signature-processing,代码行数:22,代码来源:ListIdsItemReader.java

示例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
}
 
开发者ID:create1st,项目名称:spring-batch,代码行数:18,代码来源:TicketReaderFactoryTest.java

示例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");
        }
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:22,代码来源:LHHuntingClubCSVCleaner.java

示例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");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:27,代码来源:DataflowTemplateTests.java

示例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();
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:14,代码来源:DescriptionParsingTest.java

示例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());
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:20,代码来源:JobStepExecutionControllerTests.java

示例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}"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:28,代码来源:StepExecutionJacksonMixInTests.java

示例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]);
    }
}
 
开发者ID:hosuaby,项目名称:signature-processing,代码行数:18,代码来源:ListIdsItemReader.java

示例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"));
}
 
开发者ID:create1st,项目名称:spring-batch,代码行数:24,代码来源:TicketReaderFactoryTest.java

示例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);
	}
}
 
开发者ID:SoatGroup,项目名称:json-file-itemwriter,代码行数:23,代码来源:JsonFlatFileItemWriter.java

示例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;
	}
}
 
开发者ID:SoatGroup,项目名称:json-file-itemwriter,代码行数:18,代码来源:JsonFlatFileItemWriter.java

示例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;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:25,代码来源:SetTemporaryFilenamesTasklet.java

示例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"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-task,代码行数:10,代码来源:JobExecutionEventTests.java

示例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());
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:22,代码来源:BOMIgnoringFlatFileItemReaderTest.java


注:本文中的org.springframework.batch.item.ExecutionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。