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

Quick Search    Search Deep

Source code: nectar/scheduler/SchedulerConfiguration.java


1   /*
2       Copyright (C) 2003  Kai Schutte
3    
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8    
9       This program is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU General Public License for more details.
13   
14      You should have received a copy of the GNU General Public License
15      along with this program; if not, write to the Free Software
16      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * SchedulerConfiguration.java -- the configuration class for the SchedulerService.
19   *
20   * Created on March 21, 2003, 6:41 PM
21   */
22  
23  package nectar.scheduler;
24  
25  import nectar.configuration.Configuration;
26  import nectar.configuration.ConfigurationException;
27  import java.util.LinkedList;
28  import java.util.Iterator;
29  import java.util.List;
30  
31  import nectar.configuration.ServiceConfigElement;
32  import nectar.configuration.ConfigProperty;
33  import nectar.ServicesUtil;
34  
35  import org.apache.commons.logging.Log;
36  import org.apache.commons.logging.LogFactory;
37  
38  /** This is the Configuration Class for the SchedulerService, it parse the nectar_config.xml file for scheduled tasks, and sets them up in the SchedulerService.
39   *
40   * @author  Kai Schutte skander@skander.com
41   */
42  public class SchedulerConfiguration extends Configuration {
43      public static final String SERVICE_NAME = "Scheduler";
44      protected int initialPause = 5;
45      protected LinkedList jobList = new LinkedList();
46      private static Log log = LogFactory.getLog(SchedulerConfiguration.class);
47      
48      /** Creates a new instance of SchedulerConfiguration */
49      public SchedulerConfiguration() {
50          setServiceName(SERVICE_NAME);
51      }
52      
53      public List getJobList() {
54          return jobList;
55      }
56      
57      public int getInitialPause() {
58          return initialPause;
59      }
60      
61      /** Parses the Scheduler configuration element of the nectar_config.xml file.
62       * @throws ConfigurationException thrown if the configuration file holds invalid values.
63       */
64      public void parse() throws ConfigurationException {
65          if (this.configElement == null) {
66              throw new ConfigurationException("Invalid usage: element was not set", new NullPointerException());
67          }
68          if (log.isTraceEnabled()) log.trace(" NECTAR: SchedulerConfiguration -- parsing configuration...");
69          parseInitialPause();
70          parseScheduledActionSets();
71      }
72      
73      protected void parseInitialPause() throws ConfigurationException {
74          ConfigProperty p = configElement.getProperty("initialPause");
75          if (p != null) {
76              int value;
77              try {
78                  value = Integer.parseInt(p.getValue());
79              } catch (NumberFormatException e) {
80                  throw new ConfigurationException("Invalid \"initialPause\" property in "+this.getService()+" configuration. value must be a number.");
81              }
82              if (value < 0) {
83                  throw new ConfigurationException("Invalid \"initialPause\" property in "+this.getService()+" configuration. value must be positive.");
84              }
85              this.initialPause = value;
86          }
87      }
88      
89      protected void parseScheduledActionSets() throws ConfigurationException {
90          List list = ServicesUtil.getConfigurationService().getConfigFile().getScheduledActions();
91          if (list == null || list.isEmpty()) {
92              if (log.isTraceEnabled()) log.trace(" NECTAR: SchedulerConfiguration has no jobs configured");
93              return;
94          }
95          if (log.isTraceEnabled()) log.trace(" NECTAR: SchedulerConfiguration has "+Integer.toString(list.size())+" jobs configured");
96          for (Iterator iter = list.iterator(); iter.hasNext(); ) {
97              this.jobList.add(iter.next());
98          }
99      }
100 }