Search in sources :

Example 1 with NoSuchJobException

use of javax.batch.operations.NoSuchJobException in project quickstart by wildfly.

the class BatchController method getJobsExecution.

public Set<JobData> getJobsExecution() {
    Set<JobData> jobsData = new TreeSet<JobData>(new Comparator<JobData>() {

        @Override
        public int compare(JobData o1, JobData o2) {
            return o2.getJobInstanceId().compareTo(o1.getJobInstanceId());
        }
    });
    Map<Long, JobExecution> jobIntances = new HashMap<>();
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    try {
        List<JobInstance> instances = jobOperator.getJobInstances("import-file", 0, jobOperator.getJobInstanceCount("import-file"));
        for (JobInstance ji : instances) {
            List<JobExecution> executions = jobOperator.getJobExecutions(ji);
            for (JobExecution jobExecution : executions) {
                // initialize the map if null
                if (jobIntances.get(ji.getInstanceId()) == null) {
                    jobIntances.put(ji.getInstanceId(), jobExecution);
                }
                // Update the jobExecution if is newer
                JobExecution existing = jobIntances.get(ji.getInstanceId());
                if (jobExecution.getExecutionId() > existing.getExecutionId()) {
                    jobIntances.put(ji.getInstanceId(), jobExecution);
                }
            }
        }
        for (Long instaceId : jobIntances.keySet()) {
            JobExecution jobExecution = jobIntances.get(instaceId);
            JobInstance ji = jobOperator.getJobInstance(jobExecution.getExecutionId());
            Properties parameters = jobOperator.getParameters(jobExecution.getExecutionId());
            jobsData.add(new JobData(ji.getInstanceId(), jobExecution.getExecutionId(), ji.getJobName(), jobExecution.getCreateTime(), jobExecution.getEndTime(), jobExecution.getBatchStatus(), parameters, jobExecution.getExitStatus()));
        }
    } catch (NoSuchJobException e) {
    // It's ok if when doesn't have any jobs yet to show
    }
    return jobsData;
}
Also used : HashMap(java.util.HashMap) JobInstance(javax.batch.runtime.JobInstance) JobOperator(javax.batch.operations.JobOperator) Properties(java.util.Properties) JobExecution(javax.batch.runtime.JobExecution) NoSuchJobException(javax.batch.operations.NoSuchJobException) TreeSet(java.util.TreeSet)

Aggregations

HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 TreeSet (java.util.TreeSet)1 JobOperator (javax.batch.operations.JobOperator)1 NoSuchJobException (javax.batch.operations.NoSuchJobException)1 JobExecution (javax.batch.runtime.JobExecution)1 JobInstance (javax.batch.runtime.JobInstance)1