Package org.springframework.batch.core.jsr.step

Examples of org.springframework.batch.core.jsr.step.PartitionStep


    return this;
  }

  @Override
  public Step build() {
    PartitionStep step = new PartitionStep();
    step.setName(getName());
    super.enhance(step);

    if (getPartitionHandler() != null) {
      step.setPartitionHandler(getPartitionHandler());
    }
    else {
      TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
      partitionHandler.setStep(getStep());
      if (getTaskExecutor() == null) {
        taskExecutor(new SyncTaskExecutor());
      }
      partitionHandler.setGridSize(getGridSize());
      partitionHandler.setTaskExecutor(getTaskExecutor());
      step.setPartitionHandler(partitionHandler);
    }

    if (getSplitter() != null) {
      step.setStepExecutionSplitter(getSplitter());
    }
    else {

      boolean allowStartIfComplete = isAllowStartIfComplete();
      String name = getStepName();
      if (getStep() != null) {
        try {
          allowStartIfComplete = getStep().isAllowStartIfComplete();
          name = getStep().getName();
        }
        catch (Exception e) {
          logger.info("Ignored exception from step asking for name and allowStartIfComplete flag. "
              + "Using default from enclosing PartitionStep (" + name + "," + allowStartIfComplete + ").");
        }
      }
      SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter();
      splitter.setPartitioner(getPartitioner());
      splitter.setJobRepository(getJobRepository());
      splitter.setAllowStartIfComplete(allowStartIfComplete);
      splitter.setStepName(name);
      splitter(splitter);
      step.setStepExecutionSplitter(splitter);

    }

    if (getAggregator() != null) {
      step.setStepExecutionAggregator(getAggregator());
    }

    if(reducer != null) {
      step.setPartitionReducer(reducer);
    }

    try {
      step.afterPropertiesSet();
    }
    catch (Exception e) {
      throw new StepBuilderException(e);
    }
View Full Code Here


  @Test
  public void testGetPartitionedStep() throws Exception {
    SimpleFlow flow = new SimpleFlow("job");
    List<StateTransition> transitions = new ArrayList<StateTransition>();
    PartitionStep step = new PartitionStep();
    step.setName("step1");
    JsrPartitionHandler partitionHandler = new JsrPartitionHandler();
    partitionHandler.setPropertyContext(new BatchPropertyContext());
    partitionHandler.setPartitions(3);
    partitionHandler.setJobRepository(jobRepository);
    partitionHandler.setStep(new StubStep("subStep"));
    partitionHandler.afterPropertiesSet();
    step.setPartitionHandler(partitionHandler);
    step.setStepExecutionSplitter(new JsrStepExecutionSplitter(jobRepository, false, "step1", true));
    step.setJobRepository(jobRepository);
    step.afterPropertiesSet();
    transitions.add(StateTransition.createStateTransition(new StepState("job.step", step), "end0"));
    transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
    flow.setStateTransitions(transitions);
    flow.afterPropertiesSet();
    job.setFlow(flow);
    job.afterPropertiesSet();

    job.execute(jobRepository.createJobExecution("partitionJob", new JobParameters()));

    assertEquals(3, step.getStepNames().size());
    Step subStep = job.getStep("step1:partition0");
    assertNotNull(subStep);
    assertEquals("subStep", subStep.getName());
    assertNull(job.getStep("step that does not exist"));
  }
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.jsr.step.PartitionStep

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.