View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   //CabaWeb
3   //Copyright (C) 2004  Thomas Vogt <Thomas.Vogt@TVC-Software.com>
4   //
5   //This library is free software; you can redistribute it and/or
6   //modify it under the terms of the GNU Lesser General Public
7   //License as published by the Free Software Foundation; either
8   //version 2.1 of the License, or (at your option) any later version.
9   //
10  //This library is distributed in the hope that it will be useful,
11  //but WITHOUT ANY WARRANTY; without even the implied warranty of
12  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  //Lesser General Public License for more details.
14  //
15  //You should have received a copy of the GNU Lesser General Public
16  //License along with this library; if not, write to the Free Software
17  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package org.fhw.cabaweb.webfrontend.servlets;
21  
22  import java.io.IOException;
23  
24  import javax.servlet.*;
25  
26  import org.fhw.cabaweb.calculation.timer.BerechnungsJob;
27  import org.quartz.CronTrigger;
28  import org.quartz.JobDetail;
29  import org.quartz.Scheduler;
30  import org.quartz.SchedulerFactory;
31  
32  /***
33   * Die Klasse dient als Listener für den Servlet Container um den Timer im Hintergrund laufen zu lassen.
34   *
35   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
36   * @version Version 1.0 27.08.2004
37   */
38  public class TimerServlet implements Servlet
39  {
40  
41      /***
42       * @see javax.servlet.Servlet#init(ServletConfig)
43       */
44      public void init(ServletConfig arg0) throws ServletException
45      {
46          SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
47          JobDetail jobDetail = new JobDetail("Calculation Timer", "Calculation Timer", BerechnungsJob.class);
48          CronTrigger trigger = new CronTrigger("Calculation Timer", "Calculation Timer");
49  
50          try
51          {
52              trigger.setCronExpression("0 0/5 * * * ?");
53              Scheduler sched = schedFact.getScheduler();
54              sched.start();
55              sched.scheduleJob(jobDetail, trigger);
56          }
57          catch (Exception e)
58          {
59              e.printStackTrace();
60          }
61      }
62  
63      /***
64       * @see javax.servlet.Servlet#getServletConfig()
65       */
66      public ServletConfig getServletConfig()
67      {
68          return null;
69      }
70  
71      /***
72       * @see javax.servlet.Servlet#service(ServletRequest, ServletResponse)
73       */
74      public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException
75      {
76      }
77  
78      /***
79       * @see javax.servlet.Servlet#getServletInfo()
80       */
81      public String getServletInfo()
82      {
83          return null;
84      }
85  
86      /***
87       * @see javax.servlet.Servlet#destroy()
88       */
89      public void destroy()
90      {
91      }
92  
93  }