Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/RuntimeCollective/webapps/servlet/BeanFlusherInitialiserServlet.java


1   /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/servlet/BeanFlusherInitialiserServlet.java,v 1.3 2003/09/30 15:13:14 joe Exp $
2    * $Revision: 1.3 $
3    * $Date: 2003/09/30 15:13:14 $
4    *
5    * ====================================================================
6    *
7    * Josephine : http://www.runtime-collective.com/josephine/index.html
8    *
9    * Copyright (C) 2003 Runtime Collective
10   * 
11   * This product includes software developed by the
12   * Apache Software Foundation (http://www.apache.org/).
13   *
14   * This library is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU Lesser General Public
16   * License as published by the Free Software Foundation; either
17   * version 2.1 of the License, or (at your option) any later version.
18   *
19   * This library is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this library; if not, write to the Free Software
26   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27   *
28   */
29  
30  package com.RuntimeCollective.webapps.servlet;
31  
32  import com.RuntimeCollective.webapps.BeanFlusher;
33  import com.RuntimeCollective.webapps.RuntimeParameters;
34  
35  import java.sql.SQLException;
36  import java.util.Calendar;
37  import java.util.Timer;
38  import javax.servlet.ServletConfig;
39  import javax.servlet.ServletException;
40  import javax.servlet.http.HttpServlet;
41  
42  /**
43   * Initialises the deleting of unused Beans,
44   * according to the web.xml parameter 'beanFlusherConfiguration'
45   *
46   * @version $Id: BeanFlusherInitialiserServlet.java,v 1.3 2003/09/30 15:13:14 joe Exp $
47   */
48  public class BeanFlusherInitialiserServlet extends HttpServlet {
49  
50      /**
51       * Initialize the environment.
52       * @exception ServletException if we cannot configure ourselves correctly
53       */
54      public void init() throws ServletException {
55          ServletConfig sc = getServletConfig();
56          initBeanFlusher(sc);
57      }
58  
59      /**
60       * Set up a nightly timer that will flush unused bean.
61       */
62      private void initBeanFlusher(ServletConfig sc) {
63  
64          // Create the timer as a daemon thread
65          Timer timer = new Timer(true);
66          BeanFlusher task = new BeanFlusher();
67          
68          // Get a representation of 2 o'clock in the morning
69          Calendar runTime = Calendar.getInstance();
70          runTime.set(Calendar.HOUR_OF_DAY, 4);
71          runTime.set(Calendar.MINUTE, 0);
72          runTime.set(Calendar.SECOND, 0);
73          
74          // Number of milliseconds in a day
75          long oneDay = 24 * 60 * 60 * 1000; 
76          
77          // Schedule the task to happen once per day, at 2am.
78          // (Schedule at fixed rate is used; delays in execution
79          // will not propogate to the next execution.)
80          timer.scheduleAtFixedRate(task, runTime.getTime(), oneDay);
81          
82          RuntimeParameters.logDebug(this, "Scheduled BeanFlusher : next one will happen at "+runTime.getTime());
83      }
84  }