001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.broker.scheduler;
018
019import java.util.List;
020import org.apache.kahadb.util.ByteSequence;
021
022public interface JobScheduler {
023
024    /**
025     * @return the name of the scheduler
026     * @throws Exception 
027     */
028    public abstract String getName() throws Exception;
029/**
030 * Add a Job listener
031 * @param l
032 * @throws Exception 
033 */
034    public abstract void addListener(JobListener l) throws Exception;
035/**
036 * remove a JobListener
037 * @param l
038 * @throws Exception 
039 */
040    public abstract void removeListener(JobListener l) throws Exception;
041
042    /**
043     * Add a job to be scheduled
044     * @param jobId a unique identifier for the job
045     * @param payload the message to be sent when the job is scheduled
046     * @param delay the time in milliseconds before the job will be run
047     * @throws Exception
048     */
049    public abstract void schedule(String jobId, ByteSequence payload,long delay) throws Exception;
050
051    /**
052     * Add a job to be scheduled
053     * @param jobId a unique identifier for the job
054     * @param payload the message to be sent when the job is scheduled
055     * @param cronEntry - cron entry
056     * @throws Exception
057     */
058    public abstract void schedule(String jobId, ByteSequence payload,String cronEntry) throws Exception;
059
060    
061    /**
062     * Add a job to be scheduled
063     * @param jobId a unique identifier for the job
064     * @param payload the message to be sent when the job is scheduled
065     * @param cronEntry - cron entry
066     * @param delay time in ms to wait before scheduling
067     * @param period the time in milliseconds between successive executions of the Job
068     * @param repeat the number of times to execute the job - less than 0 will be repeated forever
069     * @throws Exception
070     */
071    public abstract void schedule(String jobId, ByteSequence payload,String cronEntry,long delay, long period, int repeat) throws Exception;
072
073    /**
074     * remove all jobs scheduled to run at this time
075     * @param time
076     * @throws Exception 
077     */
078    public abstract void remove(long time) throws  Exception;
079
080    /**
081     * remove a job with the matching jobId
082     * @param jobId
083     * @throws Exception 
084     */
085    public abstract void remove(String jobId) throws  Exception;
086    
087    /**
088     * remove all the Jobs from the scheduler
089     * @throws Exception
090     */
091    public abstract void removeAllJobs() throws Exception;
092    
093    /**
094     * remove all the Jobs from the scheduler that are due between the start and finish times
095     * @param start time in milliseconds
096     * @param finish time in milliseconds
097     * @throws Exception
098     */
099    public abstract void removeAllJobs(long start,long finish) throws Exception;
100    
101
102    
103    /**
104     * Get the next time jobs will be fired
105     * @return the time in milliseconds
106     * @throws Exception 
107     */
108    public abstract long getNextScheduleTime() throws Exception;
109    
110    /**
111     * Get all the jobs scheduled to run next
112     * @return a list of jobs that will be scheduled next
113     * @throws Exception
114     */
115    public abstract List<Job> getNextScheduleJobs() throws Exception;
116    
117    /**
118     * Get all the outstanding Jobs
119     * @return a  list of all jobs
120     * @throws Exception 
121     */
122    public abstract List<Job> getAllJobs() throws Exception;
123    
124    /**
125     * Get all outstanding jobs due to run between start and finish
126     * @param start
127     * @param finish
128     * @return a list of jobs
129     * @throws Exception
130     */
131    public abstract List<Job> getAllJobs(long start,long finish)throws Exception;
132
133}