All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.scattersphere.util.thread.JobExecutionContext Maven / Gradle / Ivy

The newest version!
/*
 * Scattersphere
 * Copyright 2014-2015, Scattersphere Project.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.scattersphere.util.thread;


import net.scattersphere.job.Job;
import net.scattersphere.job.JobContext;

import java.util.Arrays;
import java.util.UUID;

/**
 * This is an immutable internal storage class used to keep track of running {@link Job}s, the results they provide,
 * the parameters that were sent to the {@link Job} (if any were specified).  In addition, a Job ID is automatically
 * assigned to the context, generated using a {@link UUID}.
 * 
 * @author [email protected]
 */
public class JobExecutionContext {

    private final Job job;
    private final String[] arguments;

    private final JobContext jobContext;

    /**
     * Constructor storing the {@link Job} and its arguments.
     *
     * @param job The {@link Job} to store.
     * @param jobName {@code String} containing the name of the job.
     * @param arguments The {@code String[]} of arguments that were sent to the job.
     */
    public JobExecutionContext(Job job, String jobName, String[] arguments) {
        this.job = job;
        this.arguments = arguments;
        this.jobContext = new JobContext(jobName, UUID.randomUUID().toString(), null);
    }

    /**
     * Retrieves the {@link Job} object.
     *
     * @return {@link Job} object.
     */
    public Job getJob() {
        return job;
    }

    /**
     * Retrieves the argument list that was sent.
     *
     * @return {@code String[]} of arguments, if provided.
     */
    public String[] getArguments() {
        return arguments;
    }

    /**
     * Returns the current job context.
     *
     * @return {@link JobContext} object.
     */
    public JobContext getJobContext() {
        return jobContext;
    }

    @Override
    public String toString() {
        return "JobExecutionContext{" +
                "job=" + job +
                ", arguments=" + Arrays.toString(arguments) +
                ", jobContext=" + jobContext +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy