Package javax.batch.operations

Examples of javax.batch.operations.JobOperator


        String jobXml = args[0];
        if (jobXml == null || jobXml.isEmpty()) {
            usage(args);
        }

        JobOperator jobOperator = BatchRuntime.getJobOperator();
        long jobExecutionId;
        long timeout = Long.getLong(JobExecutionImpl.JOB_EXECUTION_TIMEOUT_SECONDS_KEY, JobExecutionImpl.JOB_EXECUTION_TIMEOUT_SECONDS_DEFAULT);
        try {
            jobExecutionId = jobOperator.start(jobXml, null);
            JobExecutionImpl jobExecution = (JobExecutionImpl) jobOperator.getJobExecution(jobExecutionId);
            jobExecution.awaitTerminatioin(timeout, TimeUnit.SECONDS);

            if (!jobExecution.getBatchStatus().equals(BatchStatus.COMPLETED)) {
                throw new BatchRuntimeException(String.format("The job did not complete: %s%n", jobXml));
            }
View Full Code Here


            final String key = args[i].substring(0, equalSignPos).trim();
            final String val = args[i].substring(equalSignPos + 1).trim();
            jobParameters.setProperty(key, val);
        }

        final JobOperator jobOperator = BatchRuntime.getJobOperator();
        final long jobExecutionId;
        try {
            jobExecutionId = jobOperator.start(jobXml, jobParameters);
            final JobExecutionImpl jobExecution = (JobExecutionImpl) jobOperator.getJobExecution(jobExecutionId);
            jobExecution.awaitTermination(0, TimeUnit.SECONDS)//no timeout

            if (!jobExecution.getBatchStatus().equals(BatchStatus.COMPLETED)) {
                throw new BatchRuntimeException(String.format("The job did not complete: %s%n", jobXml));
            }
View Full Code Here

        } else if (instanceId != null) {
            for (JobExecution je : getJobExecutionForInstance(Long.valueOf(instanceId))) {
                jobExecutions.add(handleJob(je, columnFormatter));
            }
        } else {
            JobOperator jobOperator = BatchRuntime.getJobOperator();
            Set<String> jobNames = jobOperator.getJobNames();
            if (jobNames != null) {
                for (String jn : jobOperator.getJobNames()) {
                    List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
                    if (exe != null) {
                        for (JobInstance ji : exe) {
                            for (JobExecution je : jobOperator.getJobExecutions(ji)) {
                                jobExecutions.add(handleJob(je, columnFormatter));
                            }
                        }
                    }
                }
View Full Code Here

    }

    private List<JobExecution> findJobExecutions(long exeId)
        throws JobSecurityException {
        List<JobExecution> jobExecutions = new ArrayList<>();
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        JobExecution jobExecution = jobOperator.getJobExecution(exeId);
        if (jobExecution != null)
            jobExecutions.add(jobExecution);

        return jobExecutions;
    }
View Full Code Here

        return jobExecutions;
    }

    private static List<JobExecution> getJobExecutionForInstance(long instId)
            throws JobSecurityException {
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        JobInstance jobInstance = null;
        for (String jn : jobOperator.getJobNames()) {
            List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
            if (exe != null) {
                for (JobInstance ji : exe) {
                    if (ji.getInstanceId() == instId) {
                        jobInstance = ji;
                        break;
                    }
                }
            }
        }

        List<JobExecution> jeList = new ArrayList<JobExecution>();
        List<JobExecution> lst = BatchRuntime.getJobOperator().getJobExecutions(jobInstance);
        if (lst != null) {
            for (JobExecution je : lst) {
                jeList.add(jobOperator.getJobExecution(je.getExecutionId()));
            }
        }

        return jeList;
    }
View Full Code Here

        Map<String, Object> jobInfo = new HashMap<>();

        int jobParamIndex = -1;
        StringTokenizer st = new StringTokenizer("", "");
        String[] cfData = new String[getOutputHeaders().length];
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        for (int index = 0; index < getOutputHeaders().length; index++) {
            Object data = null;
            switch (getOutputHeaders()[index]) {
                case JOB_NAME:
                    data = " " + je.getJobName();
                    break;
                case EXECUTION_ID:
                    data = "" + je.getExecutionId();
                    break;
                case BATCH_STATUS:
                    data = je.getBatchStatus();
                    break;
                case EXIT_STATUS:
                    data = je.getExitStatus();
                    break;
                case START_TIME:
                    data = je.getStartTime().getTime();
                    cfData[index] = je.getStartTime().toString();
                    break;
                case END_TIME:
                    data = je.getEndTime().getTime();
                    cfData[index] = je.getEndTime().toString();
                    break;
                case JOB_PARAMETERS:
                    data = je.getJobParameters() == null ? new Properties() : je.getJobParameters();
                    jobParamIndex = index;
                    ColumnFormatter cf = new ColumnFormatter(new String[]{"KEY", "VALUE"});
                    for (Map.Entry e : ((Properties) data).entrySet())
                        cf.addRow(new String[]{e.getKey().toString(), e.getValue().toString()});
                    st = new StringTokenizer(cf.toString(), "\n");
                    break;
                case STEP_COUNT:
                    long exeId = executionId == null ? je.getExecutionId() : Long.valueOf(executionId);
                    data = jobOperator.getStepExecutions(exeId) == null
                        ? 0 : jobOperator.getStepExecutions(exeId).size();
                    break;
                default:
                    throw new IllegalArgumentException("Unknown header: " + getOutputHeaders()[index]);
            }
            jobInfo.put(getOutputHeaders()[index], data);
View Full Code Here

    }

    private List<StepExecution> findStepExecutions()
        throws JobSecurityException {
        List<StepExecution> stepExecutions = new ArrayList<>();
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        List<StepExecution<?>> jobExecution = jobOperator.getStepExecutions(Long.valueOf(executionId));
        if (jobExecution != null)
            stepExecutions.addAll(jobExecution);

        return stepExecutions;
    }
View Full Code Here

    }

    private List<JobExecution> findJobExecutions()
        throws JobSecurityException {
        List<JobExecution> jobExecutions = new ArrayList<>();
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        if (jobName != null) {
            List<JobInstance> exe = jobOperator.getJobInstances(jobName, 0, Integer.MAX_VALUE - 1);
            if (exe != null) {
                for (JobInstance ji : exe) {
                    jobExecutions.addAll(jobOperator.getJobExecutions(ji));
                }
            }
        } else {
            Set<String> jobNames = jobOperator.getJobNames();
            if (jobNames != null) {
                for (String jn : jobOperator.getJobNames()) {
                    List<JobInstance> exe = jobOperator.getJobInstances(jn, 0, Integer.MAX_VALUE - 1);
                    if (exe != null) {
                        for (JobInstance ji : exe) {
                            jobExecutions.addAll(jobOperator.getJobExecutions(ji));
                        }
                    }
                }
            }
        }
View Full Code Here

    private Map<String, Object> handleJob(JobExecution je, ColumnFormatter columnFormatter)
        throws  JobSecurityException {
        Map<String, Object> jobInfo = new HashMap<>();

        String[] cfData = new String[getOutputHeaders().length];
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        for (int index = 0; index < getOutputHeaders().length; index++) {
            Object data = null;
            switch (getOutputHeaders()[index]) {
                case JOB_NAME:
                    data = "" + je.getJobName();
                    break;
                case APP_NAME:
                    try {
                        data = "" + ((TaggedJobExecution) je).getTagName();
                    } catch (Exception ex) {
                        logger.log(Level.FINE, "Error while calling ((TaggedJobExecution) je).getTagName() ", ex);
                        data = "null";//ex.toString();
                    }
                    break;
                case INSTANCE_COUNT:
                    data = "";//jobOperator.getJobInstanceCount(je.getJobName());
                    break;
                case INSTANCE_ID:
                    data = jobOperator.getJobInstance(je.getExecutionId()).getInstanceId();
                    break;
                case EXECUTION_ID:
                    data = je.getExecutionId();
                    break;
                case BATCH_STATUS:
View Full Code Here

        return new String[] {NAME, STEP_ID, START_TIME, END_TIME, BATCH_STATUS, EXIT_STATUS};
    }

    private List<StepExecution> findStepExecutions()
        throws JobSecurityException, NoSuchJobExecutionException {
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        JobExecution je = jobOperator.getJobExecution(Long.valueOf(executionId));
        if (!glassFishBatchSecurityHelper.isVisibleToThisInstance(((TaggedJobExecution) je).getTagName()))
            throw new NoSuchJobExecutionException("No job execution exists for job execution id: " + executionId);

        List<StepExecution> stepExecutions = jobOperator.getStepExecutions(Long.valueOf(executionId));
        if (stepExecutions == null || stepExecutions.size() == 0)
            throw new NoSuchJobExecutionException("No job execution exists for job execution id: " + executionId);

        return stepExecutions;
    }
View Full Code Here

TOP

Related Classes of javax.batch.operations.JobOperator

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.