001    package org.apache.turbine.services.schedule;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import java.util.List;
025    
026    import org.apache.turbine.services.TurbineServices;
027    import org.apache.turbine.util.TurbineException;
028    
029    /**
030     * This is a fascade class to provide easy access to the Scheduler
031     * service.  All access methods are static and act upon the current
032     * instance of the scheduler service.
033     *
034     * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
035     * @version $Id: TurbineScheduler.java 1066938 2011-02-03 20:14:53Z ludwig $
036     * @see org.apache.turbine.services.schedule.ScheduleService
037     */
038    public abstract class TurbineScheduler
039    {
040        /**
041         * Get a specific Job from Storage.
042         *
043         * @param oid The int id for the job.
044         * @return A JobEntry.
045         * @exception TurbineException job could not be retrieved
046         */
047        public static JobEntry getJob(int oid)
048                throws TurbineException
049        {
050            return getService().getJob(oid);
051        }
052    
053        /**
054         * Add a new job to the queue.
055         *
056         * @param je A JobEntry with the job to add.
057         * @exception TurbineException job could not be added
058         */
059        public static void addJob(JobEntry je)
060                throws TurbineException
061        {
062            getService().addJob(je);
063        }
064    
065        /**
066         * Add or update a job
067         *
068         * @param je A JobEntry with the job to modify
069         * @exception TurbineException job could not be updated
070         */
071        public static void updateJob(JobEntry je)
072                throws TurbineException
073        {
074            getService().updateJob(je);
075        }
076    
077        /**
078         * Remove a job from the queue.
079         *
080         * @param je A JobEntry with the job to remove.
081         * @exception TurbineException job could not be removed
082         */
083        public static void removeJob(JobEntry je)
084                throws TurbineException
085        {
086            getService().removeJob(je);
087        }
088    
089        /**
090         * List jobs in the queue.  This is used by the scheduler UI.
091         *
092         * @return A Vector of jobs.
093         */
094        public static List<JobEntry> listJobs()
095        {
096            return getService().listJobs();
097        }
098    
099        /**
100         * Determines if the scheduler service is currently active.
101         *
102         * @return Status of the scheduler service.
103         */
104        public static boolean isEnabled()
105        {
106            return getService().isEnabled();
107        }
108    
109        /**
110         * Starts the scheduler if not already running.
111         */
112        public static void startScheduler()
113        {
114            getService().startScheduler();
115        }
116    
117        /**
118         * Stops the scheduler if ti is currently running.
119         */
120        public static void stopScheduler()
121        {
122            getService().stopScheduler();
123        }
124    
125        /**
126         * Utility method for accessing the service
127         * implementation
128         *
129         * @return a ScheduleService implementation instance
130         */
131        private static ScheduleService getService()
132        {
133            return (ScheduleService) TurbineServices
134                    .getInstance().getService(ScheduleService.SERVICE_NAME);
135        }
136    
137    }