001/*
002 * Copyright 2002-2013 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.support;
018
019import java.util.Date;
020
021import org.springframework.scheduling.TriggerContext;
022
023/**
024 * Simple data holder implementation of the {@link TriggerContext} interface.
025 *
026 * @author Juergen Hoeller
027 * @since 3.0
028 */
029public class SimpleTriggerContext implements TriggerContext {
030
031        private volatile Date lastScheduledExecutionTime;
032
033        private volatile Date lastActualExecutionTime;
034
035        private volatile Date lastCompletionTime;
036
037
038        /**
039         * Create a SimpleTriggerContext with all time values set to {@code null}.
040         */
041         public SimpleTriggerContext() {
042        }
043
044        /**
045         * Create a SimpleTriggerContext with the given time values.
046         * @param lastScheduledExecutionTime last <i>scheduled</i> execution time
047         * @param lastActualExecutionTime last <i>actual</i> execution time
048         * @param lastCompletionTime last completion time
049         */
050        public SimpleTriggerContext(Date lastScheduledExecutionTime, Date lastActualExecutionTime, Date lastCompletionTime) {
051                this.lastScheduledExecutionTime = lastScheduledExecutionTime;
052                this.lastActualExecutionTime = lastActualExecutionTime;
053                this.lastCompletionTime = lastCompletionTime;
054        }
055
056
057        /**
058         * Update this holder's state with the latest time values.
059         * @param lastScheduledExecutionTime last <i>scheduled</i> execution time
060         * @param lastActualExecutionTime last <i>actual</i> execution time
061         * @param lastCompletionTime last completion time
062         */
063        public void update(Date lastScheduledExecutionTime, Date lastActualExecutionTime, Date lastCompletionTime) {
064                this.lastScheduledExecutionTime = lastScheduledExecutionTime;
065                this.lastActualExecutionTime = lastActualExecutionTime;
066                this.lastCompletionTime = lastCompletionTime;
067        }
068
069
070        @Override
071        public Date lastScheduledExecutionTime() {
072                return this.lastScheduledExecutionTime;
073        }
074
075        @Override
076        public Date lastActualExecutionTime() {
077                return this.lastActualExecutionTime;
078        }
079
080        @Override
081        public Date lastCompletionTime() {
082                return this.lastCompletionTime;
083        }
084
085}