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

org.quartz.jobs.JobDetailImpl Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
/**
 * Copyright 2015 Knowm Inc. (http://knowm.org) and contributors.
 * Copyright 2013-2015 Xeiam LLC (http://xeiam.com) and contributors.
 * Copyright 2001-2011 Terracotta Inc. (http://terracotta.org).
 *
 * 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 org.quartz.jobs;

import java.util.Arrays;

import org.quartz.builders.JobBuilder;
import org.quartz.core.Scheduler;

/**
 * 

* Conveys the detail properties of a given Job instance. *

*

* Quartz does not store an actual instance of a Job class, but instead allows you to define an instance of one, through the use of a * JobDetail. *

*

* Jobs have a name and group associated with them, which should uniquely identify them within a single {@link Scheduler}. *

*

* Triggers are the 'mechanism' by which Jobs are scheduled. Many Triggers can point to the same * Job, but a single Trigger can only point to one Job. *

* * @author James House * @author Sharada Jambula * @author timmolter */ public class JobDetailImpl implements Cloneable, java.io.Serializable, JobDetail { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Data members. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private String name; private Class jobClass; private String description = ""; private JobDataMap jobDataMap; private boolean isConcurrencyAllowed = false; @Override public String toString() { return "name: '" + getName() + "', Job Class: " + ((getJobClass() == null) ? null : getJobClass().getName()) + ", description: " + getDescription() + " isConcurrencyAllowed: " + isConcurrencyAllowed() + ", jobDataMap: " + ((jobDataMap == null) ? "empty" : Arrays.toString(jobDataMap.entrySet().toArray())); } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Constructors. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** *

* Create a JobDetail with no specified name or group, and the default settings of all the other properties. *

*

* Note that the {@link #setName(String)},{@link #setGroup(String)}and {@link #setJobClass(Class)}methods must be called before the job can be * placed into a {@link Scheduler} *

*/ public JobDetailImpl() { // do nothing... } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Interface. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** *

* Get the name of this Job. *

*/ @Override public String getName() { return name; } /** *

* Set the name of this Job. *

* * @exception IllegalArgumentException if name is null or empty. */ public void setName(String name) { if (name == null || name.trim().length() == 0) { throw new IllegalArgumentException("Job name cannot be empty."); } this.name = name; } @Override public String getDescription() { return description; } /** *

* Set a description for the Job instance - may be useful for remembering/displaying the purpose of the job, though the description has * no meaning to Quartz. *

*/ public void setDescription(String description) { this.description = description; } @Override public Class getJobClass() { return jobClass; } /** *

* Set the instance of Job that will be executed. *

* * @exception IllegalArgumentException if jobClass is null or the class is not a Job. */ public void setJobClass(Class jobClass) { if (jobClass == null) { throw new IllegalArgumentException("Job class cannot be null."); } if (!Job.class.isAssignableFrom(jobClass)) { throw new IllegalArgumentException("Job class must implement the Job interface."); } this.jobClass = jobClass; } @Override public JobDataMap getJobDataMap() { if (jobDataMap == null) { jobDataMap = new JobDataMap(); } return jobDataMap; } /** *

* Set the JobDataMap to be associated with the Job. *

*/ public void setJobDataMap(JobDataMap jobDataMap) { this.jobDataMap = jobDataMap; } public void setIsConcurrencyAllowed(boolean isConcurrencyAllowed) { this.isConcurrencyAllowed = isConcurrencyAllowed; } @Override public boolean isConcurrencyAllowed() { return isConcurrencyAllowed; } @Override public boolean equals(Object obj) { if (!(obj instanceof JobDetail)) { return false; } JobDetail other = (JobDetail) obj; if (other.getName() == null || getName() == null) { return false; } if (!other.getName().equals(getName())) { return false; } return true; } @Override public int hashCode() { return getName().hashCode(); } @Override public Object clone() { JobDetailImpl copy; try { copy = (JobDetailImpl) super.clone(); if (jobDataMap != null) { copy.jobDataMap = jobDataMap.shallowCopy(); } } catch (CloneNotSupportedException ex) { throw new IncompatibleClassChangeError("Not Cloneable."); } return copy; } @Override public JobBuilder getJobBuilder() { JobBuilder b = JobBuilder.newJobBuilder().ofType(getJobClass()).isConcurrencyAllowed(isConcurrencyAllowed()).usingJobData(getJobDataMap()) .withDescription(getDescription()).withIdentity(getName()); return b; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy