Tabnine Logo
TaskExecutorPartitionHandler
Code IndexAdd Tabnine to your IDE (free)

How to use
TaskExecutorPartitionHandler
in
org.springframework.batch.core.partition.support

Best Java code snippets using org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler (Showing top 20 results out of 315)

origin: spring-projects/spring-batch

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(this.step);
if (taskExecutor == null) {
  taskExecutor = new SyncTaskExecutor();
partitionHandler.setGridSize(gridSize);
partitionHandler.setTaskExecutor(taskExecutor);
step.setPartitionHandler(partitionHandler);
origin: spring-projects/spring-batch

@Override
protected Set<StepExecution> doHandle(StepExecution masterStepExecution,
                   Set<StepExecution> partitionStepExecutions) throws Exception {
  Assert.notNull(step, "A Step must be provided.");
  final Set<Future<StepExecution>> tasks = new HashSet<>(getGridSize());
  final Set<StepExecution> result = new HashSet<>();
  for (final StepExecution stepExecution : partitionStepExecutions) {
    final FutureTask<StepExecution> task = createTask(step, stepExecution);
    try {
      taskExecutor.execute(task);
      tasks.add(task);
    } catch (TaskRejectedException e) {
      // couldn't execute one of the tasks
      ExitStatus exitStatus = ExitStatus.FAILED
          .addExitDescription("TaskExecutor rejected the task for this step.");
      /*
       * Set the status in case the caller is tracking it through the
       * JobExecution.
       */
      stepExecution.setStatus(BatchStatus.FAILED);
      stepExecution.setExitStatus(exitStatus);
      result.add(stepExecution);
    }
  }
  for (Future<StepExecution> task : tasks) {
    result.add(task.get());
  }
  return result;
}
origin: spring-projects/spring-batch

@Before
public void setUp() throws Exception {
  handler.setStep(new StepSupport() {
    @Override
    public void execute(StepExecution stepExecution) throws JobInterruptedException {
      count++;
      stepExecutions.add(stepExecution.getStepName());
    }
  });
  handler.afterPropertiesSet();
}
origin: spring-projects/spring-batch

@Test
public void testSetGridSize() throws Exception {
  handler.setGridSize(2);
  handler.handle(stepExecutionSplitter, stepExecution);
  assertEquals(2, count);
  assertEquals("[foo0, foo1]", stepExecutions.toString());
}
origin: spring-projects/spring-batch

@Test
public void testTaskExecutorFailure() throws Exception {
  handler.setGridSize(2);
  handler.setTaskExecutor(new TaskExecutor() {
    @Override
    public void execute(Runnable task) {
      if (count > 0) {
        throw new TaskRejectedException("foo");
      }
      task.run();
    }
  });
  Collection<StepExecution> executions = handler.handle(stepExecutionSplitter, stepExecution);
  new DefaultStepExecutionAggregator().aggregate(stepExecution, executions);
  assertEquals(1, count);
  assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
}
origin: spring-projects/spring-batch

@Test
public void testPartitionStepWithProxyHandler() throws Exception {
  StepParserStepFactoryBean<Object, Object> fb = new StepParserStepFactoryBean<>();
  fb.setBeanName("step1");
  fb.setAllowStartIfComplete(true);
  fb.setJobRepository(new JobRepositorySupport());
  fb.setStartLimit(5);
  fb.setListeners(new StepListener[] { new StepExecutionListenerSupport() });
  fb.setTaskExecutor(new SyncTaskExecutor());
  SimplePartitioner partitioner = new SimplePartitioner();
  fb.setPartitioner(partitioner);
  TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
  partitionHandler.setStep(new StepSupport("foo"));
  ProxyFactory factory = new ProxyFactory(partitionHandler);
  fb.setPartitionHandler((PartitionHandler) factory.getProxy());
  Object step = fb.getObject();
  assertTrue(step instanceof PartitionStep);
  Object handler = ReflectionTestUtils.getField(step, "partitionHandler");
  assertTrue(handler instanceof Advised);
}
origin: spring-projects/spring-batch

@Test
public void testNullStep() throws Exception {
  handler = new TaskExecutorPartitionHandler();
  try {
    handler.handle(stepExecutionSplitter, stepExecution);
    fail("Expected IllegalArgumentException");
  }
  catch (IllegalArgumentException e) {
    // expected
    String message = e.getMessage();
    assertTrue("Wrong message: " + message, message.contains("Step"));
  }
}
origin: spring-projects/spring-batch

@Test
public void testConfiguration() throws Exception {
  handler = new TaskExecutorPartitionHandler();
  try {
    handler.afterPropertiesSet();
    fail("Expected IllegalStateException when no step is set");
  }
  catch (IllegalStateException e) {
    // expected
    String message = e.getMessage();
    assertEquals("Wrong message: " + message, "A Step must be provided.", message);
  }
}
origin: spring-projects/spring-batch

@Test
public void testSetTaskExecutor() throws Exception {
  handler.setTaskExecutor(new SimpleAsyncTaskExecutor());
  handler.handle(stepExecutionSplitter, stepExecution);
  assertEquals(1, count);
}
origin: spring-projects/spring-batch

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(getStep());
if (getTaskExecutor() == null) {
  taskExecutor(new SyncTaskExecutor());
partitionHandler.setGridSize(getGridSize());
partitionHandler.setTaskExecutor(getTaskExecutor());
step.setPartitionHandler(partitionHandler);
origin: apache/servicemix-bundles

@Override
protected Set<StepExecution> doHandle(StepExecution masterStepExecution,
                   Set<StepExecution> partitionStepExecutions) throws Exception {
  Assert.notNull(step, "A Step must be provided.");
  final Set<Future<StepExecution>> tasks = new HashSet<Future<StepExecution>>(getGridSize());
  final Set<StepExecution> result = new HashSet<StepExecution>();
  for (final StepExecution stepExecution : partitionStepExecutions) {
    final FutureTask<StepExecution> task = createTask(step, stepExecution);
    try {
      taskExecutor.execute(task);
      tasks.add(task);
    } catch (TaskRejectedException e) {
      // couldn't execute one of the tasks
      ExitStatus exitStatus = ExitStatus.FAILED
          .addExitDescription("TaskExecutor rejected the task for this step.");
      /*
       * Set the status in case the caller is tracking it through the
       * JobExecution.
       */
      stepExecution.setStatus(BatchStatus.FAILED);
      stepExecution.setExitStatus(exitStatus);
      result.add(stepExecution);
    }
  }
  for (Future<StepExecution> task : tasks) {
    result.add(task.get());
  }
  return result;
}
origin: org.springframework.batch/org.springframework.batch.core

private void configurePartitionStep(PartitionStep ts) {
  Assert.state(partitioner != null, "A Partitioner must be provided for a partition step");
  Assert.state(step != null, "A Step must be provided for a partition step");
  configureAbstractStep(ts);
  if (partitionHandler != null) {
    ts.setPartitionHandler(partitionHandler);
  }
  else {
    TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
    partitionHandler.setStep(step);
    if (taskExecutor == null) {
      taskExecutor = new SyncTaskExecutor();
    }
    partitionHandler.setGridSize(gridSize);
    partitionHandler.setTaskExecutor(taskExecutor);
    ts.setPartitionHandler(partitionHandler);
  }
  SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, step, partitioner);
  ts.setStepExecutionSplitter(splitter);
}
origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

@Override
protected Set<StepExecution> doHandle(StepExecution masterStepExecution,
                   Set<StepExecution> partitionStepExecutions) throws Exception {
  Assert.notNull(step, "A Step must be provided.");
  final Set<Future<StepExecution>> tasks = new HashSet<Future<StepExecution>>(getGridSize());
  final Set<StepExecution> result = new HashSet<StepExecution>();
  for (final StepExecution stepExecution : partitionStepExecutions) {
    final FutureTask<StepExecution> task = createTask(step, stepExecution);
    try {
      taskExecutor.execute(task);
      tasks.add(task);
    } catch (TaskRejectedException e) {
      // couldn't execute one of the tasks
      ExitStatus exitStatus = ExitStatus.FAILED
          .addExitDescription("TaskExecutor rejected the task for this step.");
      /*
       * Set the status in case the caller is tracking it through the
       * JobExecution.
       */
      stepExecution.setStatus(BatchStatus.FAILED);
      stepExecution.setExitStatus(exitStatus);
      result.add(stepExecution);
    }
  }
  for (Future<StepExecution> task : tasks) {
    result.add(task.get());
  }
  return result;
}
origin: org.springframework.batch/spring-batch-core

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(this.step);
if (taskExecutor == null) {
  taskExecutor = new SyncTaskExecutor();
partitionHandler.setGridSize(gridSize);
partitionHandler.setTaskExecutor(taskExecutor);
step.setPartitionHandler(partitionHandler);
origin: org.springframework.batch/spring-batch-core

@Override
protected Set<StepExecution> doHandle(StepExecution masterStepExecution,
                   Set<StepExecution> partitionStepExecutions) throws Exception {
  Assert.notNull(step, "A Step must be provided.");
  final Set<Future<StepExecution>> tasks = new HashSet<Future<StepExecution>>(getGridSize());
  final Set<StepExecution> result = new HashSet<StepExecution>();
  for (final StepExecution stepExecution : partitionStepExecutions) {
    final FutureTask<StepExecution> task = createTask(step, stepExecution);
    try {
      taskExecutor.execute(task);
      tasks.add(task);
    } catch (TaskRejectedException e) {
      // couldn't execute one of the tasks
      ExitStatus exitStatus = ExitStatus.FAILED
          .addExitDescription("TaskExecutor rejected the task for this step.");
      /*
       * Set the status in case the caller is tracking it through the
       * JobExecution.
       */
      stepExecution.setStatus(BatchStatus.FAILED);
      stepExecution.setExitStatus(exitStatus);
      result.add(stepExecution);
    }
  }
  for (Future<StepExecution> task : tasks) {
    result.add(task.get());
  }
  return result;
}
origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(this.step);
if (taskExecutor == null) {
  taskExecutor = new SyncTaskExecutor();
partitionHandler.setGridSize(gridSize);
partitionHandler.setTaskExecutor(taskExecutor);
step.setPartitionHandler(partitionHandler);
origin: apache/servicemix-bundles

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(this.step);
if (taskExecutor == null) {
  taskExecutor = new SyncTaskExecutor();
partitionHandler.setGridSize(gridSize);
partitionHandler.setTaskExecutor(taskExecutor);
step.setPartitionHandler(partitionHandler);
origin: org.springframework.batch/spring-batch-core

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(getStep());
if (getTaskExecutor() == null) {
  taskExecutor(new SyncTaskExecutor());
partitionHandler.setGridSize(getGridSize());
partitionHandler.setTaskExecutor(getTaskExecutor());
step.setPartitionHandler(partitionHandler);
origin: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(getStep());
if (getTaskExecutor() == null) {
  taskExecutor(new SyncTaskExecutor());
partitionHandler.setGridSize(getGridSize());
partitionHandler.setTaskExecutor(getTaskExecutor());
step.setPartitionHandler(partitionHandler);
origin: apache/servicemix-bundles

TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setStep(getStep());
if (getTaskExecutor() == null) {
  taskExecutor(new SyncTaskExecutor());
partitionHandler.setGridSize(getGridSize());
partitionHandler.setTaskExecutor(getTaskExecutor());
step.setPartitionHandler(partitionHandler);
org.springframework.batch.core.partition.supportTaskExecutorPartitionHandler

Javadoc

A PartitionHandler that uses a TaskExecutor to execute the partitioned Step locally in multiple threads. This can be an effective approach for scaling batch steps that are IO intensive, like directory and filesystem scanning and copying.
By default, the thread pool is synchronous.

Most used methods

  • <init>
  • setGridSize
    Passed to the StepExecutionSplitter in the #handle(StepExecutionSplitter,StepExecution) method, inst
  • setStep
    Setter for the Step that will be used to execute the partitioned StepExecution. This is a regular Sp
  • setTaskExecutor
    Setter for the TaskExecutor that is used to farm out step executions to multiple threads.
  • createTask
    Creates the task executing the given step in the context of the given execution.
  • getGridSize
  • afterPropertiesSet
  • handle

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSharedPreferences (Context)
  • runOnUiThread (Activity)
  • onRequestPermissionsResult (Fragment)
  • InetAddress (java.net)
    An Internet Protocol (IP) address. This can be either an IPv4 address or an IPv6 address, and in pra
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now