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

io.logspace.agent.shaded.quartz.impl.JobDetailImpl Maven / Gradle / Ivy

There is a newer version: 0.3.2
Show newest version

/* 
 * Copyright 2001-2009 Terracotta, Inc. 
 * 
 * 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 io.logspace.agent.shaded.quartz.impl;

import io.logspace.agent.shaded.quartz.DisallowConcurrentExecution;
import io.logspace.agent.shaded.quartz.Job;
import io.logspace.agent.shaded.quartz.JobBuilder;
import io.logspace.agent.shaded.quartz.JobDataMap;
import io.logspace.agent.shaded.quartz.JobDetail;
import io.logspace.agent.shaded.quartz.JobExecutionContext;
import io.logspace.agent.shaded.quartz.JobKey;
import io.logspace.agent.shaded.quartz.PersistJobDataAfterExecution;
import io.logspace.agent.shaded.quartz.Scheduler;
import io.logspace.agent.shaded.quartz.StatefulJob;
import io.logspace.agent.shaded.quartz.Trigger;
import io.logspace.agent.shaded.quartz.utils.ClassUtils;


/**
 * 

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

* * @see Job * @see StatefulJob * @see JobDataMap * @see Trigger * * @author James House * @author Sharada Jambula */ @SuppressWarnings("deprecation") public class JobDetailImpl implements Cloneable, java.io.Serializable, JobDetail { private static final long serialVersionUID = -6069784757781506897L; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Data members. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private String name; private String group = Scheduler.DEFAULT_GROUP; private String description; private Class jobClass; private JobDataMap jobDataMap; private boolean durability = false; private boolean shouldRecover = false; private transient JobKey key = null; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 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... } /** *

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

* * @exception IllegalArgumentException * if name is null or empty, or the group is an empty string. * * @deprecated use {@link JobBuilder} */ public JobDetailImpl(String name, Class jobClass) { this(name, null, jobClass); } /** *

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

* * @param group if null, Scheduler.DEFAULT_GROUP will be used. * * @exception IllegalArgumentException * if name is null or empty, or the group is an empty string. * * @deprecated use {@link JobBuilder} */ public JobDetailImpl(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 name is null or empty, or the group is an empty string. * * @deprecated use {@link JobBuilder} */ public JobDetailImpl(String name, String group, Class jobClass, boolean durability, boolean recover) { setName(name); setGroup(group); setJobClass(jobClass); 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; this.key = null; } /** *

* 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; this.key = null; } /** *

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

*/ public String getFullName() { return group + "." + name; } /* (non-Javadoc) * @see io.logspace.agent.shaded.quartz.JobDetailI#getKey() */ public JobKey getKey() { if(key == null) { if(getName() == null) return null; key = new JobKey(getName(), getGroup()); } return key; } public void setKey(JobKey key) { if(key == null) throw new IllegalArgumentException("Key cannot be null!"); setName(key.getName()); setGroup(key.getGroup()); this.key = key; } /* (non-Javadoc) * @see io.logspace.agent.shaded.quartz.JobDetailI#getDescription() */ 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; } /* (non-Javadoc) * @see io.logspace.agent.shaded.quartz.JobDetailI#getJobClass() */ 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; } /* (non-Javadoc) * @see io.logspace.agent.shaded.quartz.JobDetailI#getJobDataMap() */ 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; } /** *

* 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() */ public void setRequestsRecovery(boolean shouldRecover) { this.shouldRecover = shouldRecover; } /* (non-Javadoc) * @see io.logspace.agent.shaded.quartz.JobDetailI#isDurable() */ public boolean isDurable() { return durability; } /** * @return whether the associated Job class carries the {@link PersistJobDataAfterExecution} annotation. */ public boolean isPersistJobDataAfterExecution() { return ClassUtils.isAnnotationPresent(jobClass, PersistJobDataAfterExecution.class); } /** * @return whether the associated Job class carries the {@link DisallowConcurrentExecution} annotation. */ public boolean isConcurrentExectionDisallowed() { return ClassUtils.isAnnotationPresent(jobClass, DisallowConcurrentExecution.class); } /* (non-Javadoc) * @see io.logspace.agent.shaded.quartz.JobDetailI#requestsRecovery() */ public boolean requestsRecovery() { return shouldRecover; } /** *

* Return a simple string representation of this object. *

*/ @Override public String toString() { return "JobDetail '" + getFullName() + "': jobClass: '" + ((getJobClass() == null) ? null : getJobClass().getName()) + " concurrentExectionDisallowed: " + isConcurrentExectionDisallowed() + " persistJobDataAfterExecution: " + isPersistJobDataAfterExecution() + " isDurable: " + isDurable() + " requestsRecovers: " + requestsRecovery(); } @Override public boolean equals(Object obj) { if (!(obj instanceof JobDetail)) { return false; } JobDetail other = (JobDetail) obj; if(other.getKey() == null || getKey() == null) return false; if (!other.getKey().equals(getKey())) { return false; } return true; } @Override public int hashCode() { return getKey().hashCode(); } @Override public Object clone() { JobDetailImpl copy; try { copy = (JobDetailImpl) super.clone(); if (jobDataMap != null) { copy.jobDataMap = (JobDataMap) jobDataMap.clone(); } } catch (CloneNotSupportedException ex) { throw new IncompatibleClassChangeError("Not Cloneable."); } return copy; } public JobBuilder getJobBuilder() { JobBuilder b = JobBuilder.newJob() .ofType(getJobClass()) .requestRecovery(requestsRecovery()) .storeDurably(isDurable()) .usingJobData(getJobDataMap()) .withDescription(getDescription()) .withIdentity(getKey()); return b; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy