001package org.apache.turbine.services.schedule;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Date;
023
024import org.apache.turbine.util.TurbineException;
025
026/**
027 * This is a interface for a scheduled job. It does not specify how to configure
028 * when to run, that is left to subclasses. See the JobEntryTorque for an
029 * example of a JobEntry backed by Torque objects.
030 *
031 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
032 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
033 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
034 * @version $Id$
035 */
036public interface JobEntry extends Comparable<JobEntry>
037{
038    /**
039     * Sets whether the job is running.
040     *
041     * @param isActive
042     *            Whether the job is running.
043     */
044    void setActive(boolean isActive);
045
046    /**
047     * Check to see if job is currently active/running
048     *
049     * @return true if job is currently being run by the worker thread, otherwise
050     *         false
051     */
052    boolean isActive();
053
054    /**
055     * Check to see if job is new
056     *
057     * @return true if job is not yet saved, otherwise
058     *         false
059     */
060    boolean isNew();
061
062    /**
063     * Get the value of jobId.
064     *
065     * @return int
066     */
067    int getJobId();
068
069    /**
070     * Set the value of jobId.
071     *
072     * @param v new value
073     */
074    void setJobId(int v);
075
076    /**
077     * Get the Task
078     *
079     * @return String
080     */
081    String getTask();
082
083    /**
084     * Set the value of Task
085     *
086     * @param v new value
087     */
088    void setTask(String v);
089
090    /**
091     * Get the next runtime for this job as a long.
092     *
093     * @return The next run time as a long.
094     */
095    long getNextRuntime();
096
097    /**
098     * Gets the next runtime as a date
099     *
100     * @return Next run date
101     */
102    Date getNextRunDate();
103
104    /**
105     * Get the next runtime for this job as a String.
106     *
107     * @return The next run time as a String.
108     */
109    String getNextRunAsString();
110
111    /**
112     * Calculate how long before the next runtime. <br>
113     *
114     * The runtime determines it's position in the job queue. Here's the logic: <br>
115     * 1. Create a date the represents when this job is to run. <br>
116     * 2. If this date has expired, them "roll" appropriate date fields forward
117     * to the next date. <br>
118     * 3. Calculate the diff in time between the current time and the next run
119     * time. <br>
120     *
121     * @throws TurbineException
122     *                a generic exception.
123     */
124    void calcRunTime() throws TurbineException;
125
126}