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

org.quartz.JobDetail Maven / Gradle / Ivy

Go to download

SDK for dev_appserver (local development) with some of the dependencies shaded (repackaged)

There is a newer version: 2.0.31
Show newest version

/* 
 * Copyright 2004-2005 OpenSymphony 
 * 
 * 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.
 * 
 */

/*
 * Previously Copyright (c) 2001-2004 James House
 */
package org.quartz;

import java.util.ArrayList;

/**
 * 

* 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. *

* *

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

* *

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

* * @see Job * @see StatefulJob * @see JobDataMap * @see Trigger * * @author James House * @author Sharada Jambula */ public class JobDetail implements Cloneable, java.io.Serializable { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Data members. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private String name; private String group = Scheduler.DEFAULT_GROUP; private String description; private Class jobClass; private JobDataMap jobDataMap; private boolean volatility = false; private boolean durability = false; private boolean shouldRecover = false; private ArrayList jobListeners = new ArrayList(2); /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 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 JobDetail() { // do nothing... } /** *

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

* * @param group if null, Scheduler.DEFAULT_GROUP will be used. * * @exception IllegalArgumentException * if nameis null or empty, or the group is an empty string. */ public JobDetail(String name, String group, Class jobClass) { setName(name); setGroup(group); setJobClass(jobClass); } /** *

* Create a JobDetail with the given name, and group, and * the given settings of all the other properties. *

* * @param group if null, Scheduler.DEFAULT_GROUP will be used. * * @exception IllegalArgumentException * if nameis null or empty, or the group is an empty string. */ public JobDetail(String name, String group, Class jobClass, boolean volatility, boolean durability, boolean recover) { setName(name); setGroup(group); setJobClass(jobClass); setVolatility(volatility); setDurability(durability); setRequestsRecovery(recover); } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** *

* Get the name of this Job. *

*/ 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; } /** *

* Get the group of this Job. *

*/ public String getGroup() { return group; } /** *

* Set the group of this Job. *

* * @param group if null, Scheduler.DEFAULT_GROUP will be used. * * @exception IllegalArgumentException * if the group is an empty string. */ public void setGroup(String group) { if (group != null && group.trim().length() == 0) throw new IllegalArgumentException( "Group name cannot be empty."); if(group == null) group = Scheduler.DEFAULT_GROUP; this.group = group; } /** *

* Returns the 'full name' of the Trigger in the format * "group.name". *

*/ public String getFullName() { return group + "." + name; } /** *

* Return the description given to the Job instance by its * creator (if any). *

* * @return null if no description was set. */ 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; } /** *

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

*/ 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; } /** *

* Get the JobDataMap that is associated with the Job. *

*/ 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; } /** *

* Validates whether the properties of the JobDetail are * valid for submission into a Scheduler. * * @throws IllegalStateException * if a required property (such as Name, Group, Class) is not * set. */ public void validate() throws SchedulerException { if (name == null) throw new SchedulerException("Job's name cannot be null", SchedulerException.ERR_CLIENT_ERROR); if (group == null) throw new SchedulerException("Job's group cannot be null", SchedulerException.ERR_CLIENT_ERROR); if (jobClass == null) throw new SchedulerException("Job's class cannot be null", SchedulerException.ERR_CLIENT_ERROR); } /** *

* Set whether or not the Job should be persisted in the * {@link org.quartz.spi.JobStore} for re-use after program * restarts. *

* *

* If not explicitly set, the default value is false. *

*/ public void setVolatility(boolean volatility) { this.volatility = volatility; } /** *

* Set whether or not the Job should remain stored after it * is orphaned (no {@link Trigger}s point to it). *

* *

* If not explicitly set, the default value is false. *

*/ public void setDurability(boolean durability) { this.durability = durability; } /** *

* Set whether or not the the Scheduler should re-execute * the Job if a 'recovery' or 'fail-over' situation is * encountered. *

* *

* If not explicitly set, the default value is false. *

* * @see JobExecutionContext#isRecovering() * @see JobExecutionContext#isFailedOver() */ public void setRequestsRecovery(boolean shouldRecover) { this.shouldRecover = shouldRecover; } /** *

* Whether or not the Job should not be persisted in the * {@link org.quartz.spi.JobStore} for re-use after program * restarts. *

* *

* If not explicitly set, the default value is false. *

* * @return true if the Job should be garbage * collected along with the {@link Scheduler}. */ public boolean isVolatile() { return volatility; } /** *

* Whether or not the Job should remain stored after it is * orphaned (no {@link Trigger}s point to it). *

* *

* If not explicitly set, the default value is false. *

* * @return true if the Job should remain persisted after * being orphaned. */ public boolean isDurable() { return durability; } /** *

* Whether or not the Job implements the interface {@link StatefulJob}. *

*/ public boolean isStateful() { if (jobClass == null) return false; return (StatefulJob.class.isAssignableFrom(jobClass)); } /** *

* Instructs the Scheduler whether or not the Job * should be re-executed if a 'recovery' or 'fail-over' situation is * encountered. *

* *

* If not explicitly set, the default value is false. *

* * @see JobExecutionContext#isRecovering() * @see JobExecutionContext#isFailedOver() */ public boolean requestsRecovery() { return shouldRecover; } /** *

* Add the specified name of a {@link JobListener} to the * end of the Job's list of listeners. *

*/ public void addJobListener(String name) { jobListeners.add(name); } /** *

* Remove the specified name of a {@link JobListener} from * the Job's list of listeners. *

* * @return true if the given name was found in the list, and removed */ public boolean removeJobListener(String name) { return jobListeners.remove(name); } /** *

* Returns an array of String s containing the names of all * {@link JobListener} s assigned to the Job, * in the order in which they should be notified. *

*/ public String[] getJobListenerNames() { return (String[]) jobListeners.toArray(new String[jobListeners.size()]); } /** *

* Return a simple string representation of this object. *

*/ public String toString() { return "JobDetail '" + getFullName() + "': jobClass: '" + ((getJobClass() == null) ? null : getJobClass().getName()) + " isStateful: " + isStateful() + " isVolatile: " + isVolatile() + " isDurable: " + isDurable() + " requestsRecovers: " + requestsRecovery(); } public Object clone() { JobDetail copy; try { copy = (JobDetail) super.clone(); copy.jobListeners = (ArrayList) jobListeners.clone(); if (jobDataMap != null) copy.jobDataMap = (JobDataMap) jobDataMap.clone(); } catch (CloneNotSupportedException ex) { throw new IncompatibleClassChangeError("Not Cloneable."); } return copy; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy