1 package org.apache.turbine.services.schedule;
2
3
4 /*
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 */
22
23
24 import java.util.List;
25
26 import org.apache.turbine.services.TurbineServices;
27 import org.apache.turbine.util.TurbineException;
28
29 /**
30 * This is a facade class to provide easy access to the Scheduler
31 * service. All access methods are static and act upon the current
32 * instance of the scheduler service.
33 *
34 * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
35 * @version $Id: TurbineScheduler.java 1692656 2015-07-25 21:26:13Z tv $
36 * @see org.apache.turbine.services.schedule.ScheduleService
37 */
38 public abstract class TurbineScheduler
39 {
40 /**
41 * Factory method for a new Job
42 *
43 * Schedule a job to run on a certain point of time.<br>
44 *
45 * Example 1: Run the DefaultScheduledJob at 8:00am every 15th of
46 * the month - <br>
47 *
48 * JobEntry je = newJob(0,0,8,-1,15,"DefaultScheduledJob");<br>
49 *
50 * Example 2: Run the DefaultScheduledJob at 8:00am every day -
51 * <br>
52 *
53 * JobEntry je = newJob(0,0,8,-1,-1,"DefaultScheduledJob");<br>
54 *
55 * Example 3: Run the DefaultScheduledJob every 2 hours. - <br>
56 *
57 * JobEntry je = newJob(0,120,-1,-1,-1,"DefaultScheduledJob");<br>
58 *
59 * Example 4: Run the DefaultScheduledJob every 30 seconds. - <br>
60 *
61 * JobEntry je = newJob(30,-1,-1,-1,-1,"DefaultScheduledJob");<br>
62 *
63 * @param sec Value for entry "seconds".
64 * @param min Value for entry "minutes".
65 * @param hour Value for entry "hours".
66 * @param wd Value for entry "week days".
67 * @param day_mo Value for entry "month days".
68 * @param task Task to execute.
69 *
70 * @return A JobEntry.
71 * @exception TurbineException could not create job
72 */
73 public static JobEntry newJob(int sec,
74 int min,
75 int hour,
76 int wd,
77 int day_mo,
78 String task) throws TurbineException
79 {
80 return getService().newJob(sec, min, hour, wd, day_mo, task);
81 }
82
83 /**
84 * Get a specific Job from Storage.
85 *
86 * @param oid The int id for the job.
87 * @return A JobEntry.
88 * @exception TurbineException job could not be retrieved
89 */
90 public static JobEntry getJob(int oid)
91 throws TurbineException
92 {
93 return getService().getJob(oid);
94 }
95
96 /**
97 * Add a new job to the queue.
98 *
99 * @param je A JobEntry with the job to add.
100 * @exception TurbineException job could not be added
101 */
102 public static void addJob(JobEntry je)
103 throws TurbineException
104 {
105 getService().addJob(je);
106 }
107
108 /**
109 * Add or update a job
110 *
111 * @param je A JobEntry with the job to modify
112 * @exception TurbineException job could not be updated
113 */
114 public static void updateJob(JobEntry je)
115 throws TurbineException
116 {
117 getService().updateJob(je);
118 }
119
120 /**
121 * Remove a job from the queue.
122 *
123 * @param je A JobEntry with the job to remove.
124 * @exception TurbineException job could not be removed
125 */
126 public static void removeJob(JobEntry je)
127 throws TurbineException
128 {
129 getService().removeJob(je);
130 }
131
132 /**
133 * List jobs in the queue. This is used by the scheduler UI.
134 *
135 * @return A Vector of jobs.
136 */
137 public static List<? extends JobEntry> listJobs()
138 {
139 return getService().listJobs();
140 }
141
142 /**
143 * Determines if the scheduler service is currently active.
144 *
145 * @return Status of the scheduler service.
146 */
147 public static boolean isEnabled()
148 {
149 return getService().isEnabled();
150 }
151
152 /**
153 * Starts the scheduler if not already running.
154 */
155 public static void startScheduler()
156 {
157 getService().startScheduler();
158 }
159
160 /**
161 * Stops the scheduler if ti is currently running.
162 */
163 public static void stopScheduler()
164 {
165 getService().stopScheduler();
166 }
167
168 /**
169 * Utility method for accessing the service
170 * implementation
171 *
172 * @return a ScheduleService implementation instance
173 */
174 private static ScheduleService getService()
175 {
176 return (ScheduleService) TurbineServices
177 .getInstance().getService(ScheduleService.SERVICE_NAME);
178 }
179
180 }