KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > scheduler > SchedulerMBean


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.varia.scheduler;
23
24 import java.security.InvalidParameterException JavaDoc;
25
26 import javax.management.ObjectName JavaDoc;
27
28 import org.jboss.mx.util.ObjectNameFactory;
29 import org.jboss.system.ServiceMBean;
30
31 /**
32  * ScheduleMBean interface.
33  *
34  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
35  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
36  * @version $Revision: 58158 $
37  */

38 public interface SchedulerMBean extends ServiceMBean
39 {
40    /** The default ObjectName */
41    ObjectName JavaDoc OBJECT_NAME = ObjectNameFactory.create("jboss:service=Scheduler");
42
43    // Attributes ----------------------------------------------------
44

45    /**
46     * The first scheduled call
47     *
48     * - NOW: date will be the current date (new Date()) plus 1 seconds
49     * - Date as String able to be parsed by SimpleDateFormat with default format
50     * - Date as String parsed using the date format attribute
51     * - Milliseconds since 1/1/1970
52     *
53     * If the date is in the past the Scheduler will search a start date in the future
54     * with respect to the initial repetitions and the period between calls.
55     * This means that when you restart the MBean (restarting JBoss etc.) it will start
56     * at the next scheduled time. When no start date is available in the future the
57     * Scheduler will not start.
58     *
59     * Example: if you start your Schedulable everyday at Noon and you restart your JBoss
60     * server then it will start at the next Noon (the same if started before Noon or the
61     * next day if start after Noon).
62     */

63    void setInitialStartDate(String JavaDoc startDate);
64    String JavaDoc getInitialStartDate();
65    
66    /** The date format used to parse date/times - when empty or null the locale is used to parse dates */
67    void setDateFormat(String JavaDoc dateFormat);
68    String JavaDoc getDateFormat();
69    
70    /** The Schedule Period between two scheduled call (in msecs) */
71    void setSchedulePeriod(long period);
72    long getSchedulePeriod();
73    
74    /** The number of scheduled calls */
75    void setInitialRepetitions(long numberOfCalls);
76    long getInitialRepetitions();
77    
78    /** The fully qualified Class name of the Schedulable Class being called by the Scheduler. */
79    void setSchedulableClass(String JavaDoc schedulableClass) throws java.security.InvalidParameterException JavaDoc;
80    String JavaDoc getSchedulableClass();
81    
82    /** The arguments to pass to the schedule */
83    void setSchedulableArguments(String JavaDoc argumentList);
84    String JavaDoc getSchedulableArguments();
85    
86    /**
87     * The comma seperated list of argument types for the Schedulable class.
88     * This will be used to find the right constructor and to created the right
89     * instances to call the constructor with. This list must have as many elements
90     * as the Schedulable Arguments list otherwise the start of the Scheduler will fail.
91     * Right now only basic data types, String and Classes with a Constructor with a
92     * String as only argument are supported.
93     *
94     * If the list is null or empty then the no-args constructor is used.
95     */

96    void setSchedulableArgumentTypes(String JavaDoc typeList) throws java.security.InvalidParameterException JavaDoc;
97    String JavaDoc getSchedulableArgumentTypes();
98    
99    /** The fully qualified JMX MBean name of the Schedulable MBean to be called.
100     * Attention: if set the values set by {@link #setSchedulableClass},
101     * {@link #setSchedulableArguments} and {@link #setSchedulableArgumentTypes}
102     * are cleared and not used anymore. Therefore only use either Schedulable Class
103     * or Schedulable MBean. If {@link #setSchedulableMBeanMethod} is not set then
104     * the schedule method as in the {@link Schedulable#perform} will be called with
105     * the same arguments. Also note that the Object Name will not be checked if the
106     * MBean is available. If the MBean is not available it will not be called but the
107     * remaining repetitions will be decreased. */

108    void setSchedulableMBean(String JavaDoc schedulableMBean) throws java.security.InvalidParameterException JavaDoc;
109    String JavaDoc getSchedulableMBean();
110    
111    /**
112     * The method name to be called on the Schedulable MBean. It can optionally be
113     * followed by an opening bracket, list of attributes (see below) and a closing bracket.
114     * The list of attributes can contain:
115     * - NOTIFICATION which will be replaced by the timers notification instance (javax.management.Notification)
116     * - DATE which will be replaced by the date of the notification call (java.util.Date)
117     * - REPETITIONS which will be replaced by the number of remaining repetitions (long)
118     * - SCHEDULER_NAME which will be replaced by the Object Name of the Scheduler (javax.management.ObjectName)
119     * - any full qualified Class name which the Scheduler will be set a "null" value for it
120     *
121     * An example could be: "doSomething( NOTIFICATION, REPETITIONS, String )" where the Scheduler
122     * will pass the timer's notification instance, the remaining repetitions as int and a null to
123     * the MBean's doSomething() method which must have the following signature:
124     * doSomething( javax.management.Notification, long, String ).
125     */

126    void setSchedulableMBeanMethod(String JavaDoc schedulableMBeanMethod) throws java.security.InvalidParameterException JavaDoc;
127    String JavaDoc getSchedulableMBeanMethod();
128    
129    /** The default scheduling to use, fixed-rate or fixed-delay (false, default) */
130    void setFixedRate(boolean fixedRate);
131    boolean getFixedRate();
132
133    /** Start the scheduler when the MBean started or not. */
134    void setStartAtStartup(boolean startAtStartup);
135    boolean isStartAtStartup();
136    
137    /** The JMX Timer to use (or create if not there) */
138    void setTimerName(String JavaDoc timerName);
139    String JavaDoc getTimerName();
140    
141    // Informative Attributes ----------------------------------------
142

143    long getRemainingRepetitions();
144    boolean isActive();
145    boolean isStarted();
146    boolean isRestartPending();
147    boolean isUsingMBean();
148    
149    // Operations ----------------------------------------------------
150

151    /**
152     * Starts the schedule if the schedule is stopped otherwise nothing will happen.
153     * The Schedule is immediately set to started even the first call is in the future.
154     * @throws InvalidParameterException If any of the necessary values are not set or invalid
155     * (especially for the Schedulable class attributes).
156     */

157    void startSchedule();
158
159    /**
160     * Stops the schedule because it is either not used anymore or to restart it with new values.
161     * @param doItNow If true the schedule will be stopped without waiting for the next scheduled
162     * call otherwise the next call will be performed before the schedule is stopped.
163     */

164    void stopSchedule(boolean doItNow);
165
166    /**
167     * Stops the schedule immediately.
168     */

169    void stopSchedule();
170
171    /**
172     * Stops the server right now and starts it right now.
173     */

174    void restartSchedule();
175 }
176
Popular Tags