001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.scheduling.quartz; 018 019import org.quartz.Job; 020import org.quartz.JobExecutionContext; 021import org.quartz.JobExecutionException; 022 023import org.springframework.util.Assert; 024 025/** 026 * Simple Quartz {@link org.quartz.Job} adapter that delegates to a 027 * given {@link java.lang.Runnable} instance. 028 * 029 * <p>Typically used in combination with property injection on the 030 * Runnable instance, receiving parameters from the Quartz JobDataMap 031 * that way instead of via the JobExecutionContext. 032 * 033 * @author Juergen Hoeller 034 * @since 2.0 035 * @see SpringBeanJobFactory 036 * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) 037 */ 038public class DelegatingJob implements Job { 039 040 private final Runnable delegate; 041 042 043 /** 044 * Create a new DelegatingJob. 045 * @param delegate the Runnable implementation to delegate to 046 */ 047 public DelegatingJob(Runnable delegate) { 048 Assert.notNull(delegate, "Delegate must not be null"); 049 this.delegate = delegate; 050 } 051 052 /** 053 * Return the wrapped Runnable implementation. 054 */ 055 public final Runnable getDelegate() { 056 return this.delegate; 057 } 058 059 060 /** 061 * Delegates execution to the underlying Runnable. 062 */ 063 @Override 064 public void execute(JobExecutionContext context) throws JobExecutionException { 065 this.delegate.run(); 066 } 067 068}