001/* 002 * Copyright 2002-2017 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.config; 018 019import org.springframework.scheduling.Trigger; 020import org.springframework.util.Assert; 021 022/** 023 * {@link Task} implementation defining a {@code Runnable} to be executed 024 * according to a given {@link Trigger}. 025 * 026 * @author Chris Beams 027 * @since 3.2 028 * @see ScheduledTaskRegistrar#addTriggerTask(TriggerTask) 029 * @see org.springframework.scheduling.TaskScheduler#schedule(Runnable, Trigger) 030 */ 031public class TriggerTask extends Task { 032 033 private final Trigger trigger; 034 035 036 /** 037 * Create a new {@link TriggerTask}. 038 * @param runnable the underlying task to execute 039 * @param trigger specifies when the task should be executed 040 */ 041 public TriggerTask(Runnable runnable, Trigger trigger) { 042 super(runnable); 043 Assert.notNull(trigger, "Trigger must not be null"); 044 this.trigger = trigger; 045 } 046 047 048 /** 049 * Return the associated trigger. 050 */ 051 public Trigger getTrigger() { 052 return this.trigger; 053 } 054 055}