KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > servlets > SchedulerController


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.servlets;
20
21 import java.io.*;
22 import java.rmi.*;
23 import java.util.*;
24 import javax.rmi.*;
25 import javax.naming.*;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29 import cowsultants.itracker.ejb.client.models.*;
30 import cowsultants.itracker.ejb.client.interfaces.*;
31 import cowsultants.itracker.ejb.client.util.*;
32 import cowsultants.itracker.web.scheduler.*;
33
34 public class SchedulerController extends GenericController {
35     Scheduler scheduler = null;
36
37     public SchedulerController() {
38     }
39
40     public void init(ServletConfig config) {
41         try {
42             scheduler = new Scheduler();
43                     scheduler.setPriority(4);
44             scheduler.start();
45
46             InitialContext ic = new InitialContext();
47             Object JavaDoc shRef = ic.lookup("java:comp/env/" + SchedulerHandler.JNDI_NAME);
48             SchedulerHandlerHome shHome = (SchedulerHandlerHome) PortableRemoteObject.narrow(shRef, SchedulerHandlerHome.class);
49             SchedulerHandler sh = shHome.create();
50
51             ScheduledTaskModel[] tasks = sh.getAllTasks();
52             if(tasks != null) {
53                 for(int i = 0; i < tasks.length; i++) {
54                     scheduler.addTask(tasks[i]);
55                 }
56             }
57         } catch(Exception JavaDoc e) {
58             Logger.logError("Unable to start scheduler. " + e.getMessage());
59         }
60     }
61
62     public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
63     }
64
65     public void destroy() {
66         scheduler.setStop(true);
67         scheduler = null;
68     }
69 }
70   
Popular Tags