Example usage for org.springframework.batch.core JobExecution stop

List of usage examples for org.springframework.batch.core JobExecution stop

Introduction

In this page you can find the example usage for org.springframework.batch.core JobExecution stop.

Prototype

public void stop() 

Source Link

Document

Signal the JobExecution to stop.

Usage

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public int stopAll() {
    Collection<JobExecution> result = jobExecutionDao.getRunningJobExecutions();
    for (JobExecution jobExecution : result) {
        jobExecution.stop();
        jobRepository.update(jobExecution);
    }/*  w  ww. jav a 2 s. co  m*/
    return result.size();
}

From source file:admin.service.SimpleJobService.java

@Override
public int stopAll() {
    Collection<JobExecution> result = jobExecutionDao.getRunningJobExecutions();
    for (JobExecution jobExecution : result) {
        jobExecution.stop();
        jobRepository.update(jobExecution);
    }/*w ww.  j ava  2s . co  m*/
    return result.size();
}

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public JobExecution stop(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException {

    JobExecution jobExecution = getJobExecution(jobExecutionId);
    if (!jobExecution.isRunning()) {
        throw new JobExecutionNotRunningException(
                "JobExecution is not running and therefore cannot be stopped");
    }/*from   w w w. j av a 2 s. co  m*/

    logger.info("Stopping job execution: " + jobExecution);
    jobExecution.stop();
    jobRepository.update(jobExecution);
    return jobExecution;

}

From source file:admin.service.SimpleJobService.java

@Override
public JobExecution stop(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException {

    JobExecution jobExecution = getJobExecution(jobExecutionId);
    if (!jobExecution.isRunning()) {
        throw new JobExecutionNotRunningException(
                "JobExecution is not running and therefore cannot be stopped");
    }/*w ww  . ja  v  a 2s. c o m*/

    logger.info("Stopping job execution: " + jobExecution);
    jobExecution.stop();
    jobRepository.update(jobExecution);
    return jobExecution;

}

From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java

/**
 * Interface method implementation/*from   ww  w.  j  a  va 2  s. c o m*/
 * @see org.springframework.batch.admin.service.JobService#stop(java.lang.Long)
 */
public JobExecution stop(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException {
    JobExecution jobExecution = getJobExecution(jobExecutionId);
    if (!jobExecution.isRunning()) {
        throw new JobExecutionNotRunningException(
                "JobExecution is not running and therefore cannot be stopped");
    }
    LOGGER.info("Stopping job execution: " + jobExecution);
    jobExecution.stop();
    jobRepository.update(jobExecution);
    return jobExecution;
}

From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java

/**
 * Interface method implementation/*from   w w  w .ja  v a 2s. c o  m*/
 * @see org.springframework.batch.admin.service.JobService#stopAll()
 */
public int stopAll() {
    List<JobExecution> allExecutions = new LinkedList<JobExecution>();
    for (String jobName : this.jobRegistry.getJobNames()) {
        for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) {
            for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) {
                if (jobExecution.isRunning()) {
                    allExecutions.add(jobExecution);
                }
            }
        }
    }
    for (JobExecution jobExecution : allExecutions) {
        jobExecution.stop();
        this.jobRepository.update(jobExecution);
    }
    return allExecutions.size();
}

From source file:org.springframework.batch.sample.GracefulShutdownFunctionalTests.java

@Test
public void testLaunchJob() throws Exception {

    final JobParameters jobParameters = new JobParametersBuilder()
            .addLong("timestamp", System.currentTimeMillis()).toJobParameters();

    JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobParameters);

    Thread.sleep(1000);//from w ww  .ja v a 2s  . com

    assertEquals(BatchStatus.STARTED, jobExecution.getStatus());
    assertTrue(jobExecution.isRunning());

    jobExecution.stop();

    int count = 0;
    while (jobExecution.isRunning() && count <= 10) {
        logger.info("Checking for end time in JobExecution: count=" + count);
        Thread.sleep(100);
        count++;
    }

    assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
    assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());

}

From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobService.java

@Override
public int stopAll() {
    Collection<JobExecution> result = jobExecutionDao.getRunningJobExecutions();
    Collection<String> jsrJobNames = getJsrJobNames();

    for (JobExecution jobExecution : result) {
        if (jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) {
            jsrJobOperator.stop(jobExecution.getId());
        } else {/*  w w  w.  ja  v  a 2  s  .com*/
            jobExecution.stop();
            jobRepository.update(jobExecution);
        }
    }

    return result.size();
}

From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobService.java

@Override
public JobExecution stop(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException {

    JobExecution jobExecution = getJobExecution(jobExecutionId);
    if (!jobExecution.isRunning()) {
        throw new JobExecutionNotRunningException(
                "JobExecution is not running and therefore cannot be stopped");
    }/*from   w  w w .java 2  s. c om*/

    logger.info("Stopping job execution: " + jobExecution);

    Collection<String> jsrJobNames = getJsrJobNames();

    if (jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) {
        jsrJobOperator.stop(jobExecutionId);
        jobExecution = getJobExecution(jobExecutionId);
    } else {
        jobExecution.stop();
        jobRepository.update(jobExecution);
    }
    return jobExecution;

}