Package org.springframework.batch.core.scope.context

Examples of org.springframework.batch.core.scope.context.StepContext


public class JobTasklet extends JobExecutor implements Tasklet {


  public RepeatStatus execute(final StepContribution contribution, ChunkContext chunkContext) throws Exception {

    StepContext context = StepSynchronizationManager.getContext();
    final StepExecution stepExecution = (context != null) ? context.getStepExecution() : null;

    final AtomicBoolean done = new AtomicBoolean(false);

    final JobListener jobListener = new JobListener() {
View Full Code Here


    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
      SimpleAsyncTaskExecutor asyncTX = new SimpleAsyncTaskExecutor();

      StepContext context = StepSynchronizationManager.getContext();
      final StepExecution stepExecution = (context != null) ? context.getStepExecution() : null;

      final AtomicBoolean done = new AtomicBoolean(false);

      final Thread[] th = new Thread[1];
View Full Code Here

                return RepeatStatus.FINISHED;
            }
        };
        StepContribution contribution = Mockito.mock(StepContribution.class);
        StepExecution stepExecution = createStepExecution("testExecuteJob", "testExecuteStep");
        StepContext stepContext = Mockito.mock(StepContext.class);
        Mockito.when(stepContext.getStepExecution()).thenReturn(stepExecution);

        ChunkContext chunkContext = Mockito.mock(ChunkContext.class);
        Mockito.when(chunkContext.getStepContext()).thenReturn(stepContext);
        tasklet.execute(contribution, chunkContext);
View Full Code Here

   */
  public static final String STEP_EXECUTION = "stepExecution";

  @Override
  public Message<?> preSend(Message<?> message, MessageChannel channel) {
    StepContext context = StepSynchronizationManager.getContext();
    if (context == null) {
      return message;
    }
    return MessageBuilder.fromMessage(message).setHeader(STEP_EXECUTION, context.getStepExecution()).build();
  }
View Full Code Here

  /**
   * @return the current step execution if there is one
   */
  private StepExecution getStepExecution() {
    StepContext context = StepSynchronizationManager.getContext();
    if (context==null) {
      return null;
    }
    StepExecution stepExecution = context.getStepExecution();
    return stepExecution;
  }
View Full Code Here

  @Test
  public void testExecutionInStepScope() throws Exception {
    delegate = new ItemProcessor<String, String>() {
      public String process(String item) throws Exception {
        StepContext context = StepSynchronizationManager.getContext();
        assertTrue(context != null && context.getStepExecution() != null);
        return item + item;
      };
    };
    processor.setDelegate(delegate);
    Future<String> result = StepScopeTestUtils.doInStepScope(MetaDataInstanceFactory.createStepExecution(), new Callable<Future<String>>() {
View Full Code Here

  }

  @Test
  public void testGetWithSomethingAlreadyInParentContext() {
    context.setAttribute("foo", "bar");
    StepContext context = StepSynchronizationManager.register(new StepExecution("bar", new JobExecution(0L)));
    Object value = scope.get("foo", new ObjectFactory<Object>() {
      @Override
      public Object getObject() throws BeansException {
        return "spam";
      }
    });
    assertEquals("spam", value);
    assertTrue(context.hasAttribute("foo"));
    StepSynchronizationManager.close();
    assertEquals("bar", scope.get("foo", null));
  }
View Full Code Here

  }

  @Test
  public void testParentContextWithSameStepExecution() {
    context.setAttribute("foo", "bar");
    StepContext other = StepSynchronizationManager.register(stepExecution);
    assertSame(other, context);
  }
View Full Code Here

        @Override
        public String call() throws Exception {
          StepExecution stepExecution = new StepExecution(value, new JobExecution(0L), id);
          ExecutionContext executionContext = stepExecution.getExecutionContext();
          executionContext.put("foo", value);
          StepContext context = StepSynchronizationManager.register(stepExecution);
          logger.debug("Registered: " + context.getStepExecutionContext());
          try {
            return simple.getName();
          }
          finally {
            StepSynchronizationManager.close();
View Full Code Here

      FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
        @Override
        public String call() throws Exception {
          ExecutionContext executionContext = stepExecution.getExecutionContext();
          executionContext.put("foo", value);
          StepContext context = StepSynchronizationManager.register(stepExecution);
          logger.debug("Registered: " + context.getStepExecutionContext());
          try {
            return simple.getName();
          }
          finally {
            StepSynchronizationManager.close();
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.scope.context.StepContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.