01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: SchedulerServlet.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.servlet;
09:
10: import com.uwyn.rife.database.Datasource;
11: import com.uwyn.rife.database.Datasources;
12: import com.uwyn.rife.scheduler.Scheduler;
13: import com.uwyn.rife.scheduler.exceptions.FatalTaskExecutionException;
14: import com.uwyn.rife.scheduler.exceptions.NoExecutorForTasktypeException;
15: import com.uwyn.rife.scheduler.exceptions.UnableToRetrieveTasksToProcessException;
16: import com.uwyn.rife.scheduler.taskmanagers.DatabaseTasksFactory;
17: import com.uwyn.rife.scheduler.taskoptionmanagers.DatabaseTaskoptionsFactory;
18: import java.util.logging.Logger;
19: import javax.servlet.ServletException;
20: import javax.servlet.http.HttpServlet;
21:
22: public class SchedulerServlet extends HttpServlet {
23: private static final long serialVersionUID = 6728613469081145182L;
24:
25: public void init() throws ServletException {
26: String sleep_time = getInitParameter("sleeptime");
27: String datasource_name = getInitParameter("datasource");
28: Datasource datasource = Datasources.getRepInstance()
29: .getDatasource(datasource_name);
30: Scheduler scheduler = new Scheduler(DatabaseTasksFactory
31: .getInstance(datasource), DatabaseTaskoptionsFactory
32: .getInstance(datasource));
33:
34: if (null != sleep_time) {
35: try {
36: scheduler.setSleepTime(Integer.parseInt(sleep_time));
37: } catch (NumberFormatException e) {
38: // just use the default value for the sleep time
39: }
40: }
41:
42: try {
43: scheduler.start();
44: } catch (NoExecutorForTasktypeException e) {
45: Logger.getLogger("com.uwyn.rife.servlet").severe(
46: e.getMessage());
47: } catch (UnableToRetrieveTasksToProcessException e) {
48: Logger.getLogger("com.uwyn.rife.servlet").severe(
49: e.getMessage());
50: } catch (FatalTaskExecutionException e) {
51: Logger.getLogger("com.uwyn.rife.servlet").severe(
52: e.getMessage());
53: }
54: }
55: }
|