1 /* 2 * Copyright 2004-2005 OpenSymphony 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy 6 * of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 * 16 */ 17 package org.quartz.spi; 18 19 import org.quartz.Job; 20 import org.quartz.SchedulerException; 21 22 /** 23 * <p> 24 * A JobFactory is responsible for producing instances of <code>Job</code> 25 * classes. 26 * </p> 27 * 28 * <p> 29 * This interface may be of use to those wishing to have their application 30 * produce <code>Job</code> instances via some special mechanism, such as to 31 * give the opertunity for dependency injection. 32 * </p> 33 * 34 * @see org.quartz.Scheduler#setJobFactory(JobFactory) 35 * @see org.quartz.simpl.SimpleJobFactory 36 * @see org.quartz.simpl.PropertySettingJobFactory 37 * 38 * @author James House 39 */ 40 public interface JobFactory { 41 42 /** 43 * Called by the scheduler at the time of the trigger firing, in order to 44 * produce a <code>Job</code> instance on which to call execute. 45 * 46 * <p> 47 * It should be extremely rare for this method to throw an exception - 48 * basically only the the case where there is no way at all to instantiate 49 * and prepare the Job for execution. When the exception is thrown, the 50 * Scheduler will move all triggers associated with the Job into the 51 * <code>Trigger.STATE_ERROR</code> state, which will require human 52 * intervention (e.g. an application restart after fixing whatever 53 * configuration problem led to the issue wih instantiating the Job. 54 * </p> 55 * 56 * @param bundle 57 * The TriggerFiredBundle from which the <code>JobDetail</code> 58 * and other info relating to the trigger firing can be obtained. 59 * @throws SchedulerException if there is a problem instantiating the Job. 60 * @return the newly instantiated Job 61 */ 62 Job newJob(TriggerFiredBundle bundle) throws SchedulerException; 63 64 } 65