KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > SchedulerMetaData


1
2 /*
3  * Copyright 2004-2005 OpenSymphony
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6  * use this file except in compliance with the License. You may obtain a copy
7  * of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations
15  * under the License.
16  *
17  */

18
19 /*
20  * Previously Copyright (c) 2001-2004 James House
21  */

22 package org.quartz;
23
24 import java.util.Date JavaDoc;
25
26 /**
27  * <p>
28  * Describes the settings and capabilities of a given <code>{@link Scheduler}</code>
29  * instance.
30  * </p>
31  *
32  * @author James House
33  */

34 public class SchedulerMetaData implements java.io.Serializable JavaDoc {
35
36     /*
37      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38      *
39      * Data members.
40      *
41      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42      */

43
44     private String JavaDoc schedName;
45
46     private String JavaDoc schedInst;
47
48     private Class JavaDoc schedClass;
49
50     private boolean isRemote;
51
52     private boolean started;
53
54     private boolean isInStandbyMode;
55
56     private boolean shutdown;
57
58     private Date JavaDoc startTime;
59
60     private int numJobsExec;
61
62     private Class JavaDoc jsClass;
63
64     private boolean jsPersistent;
65
66     private Class JavaDoc tpClass;
67
68     private int tpSize;
69
70     private String JavaDoc version;
71
72     /*
73      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74      *
75      * Constructors.
76      *
77      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78      */

79
80     public SchedulerMetaData(String JavaDoc schedName, String JavaDoc schedInst,
81             Class JavaDoc schedClass, boolean isRemote, boolean started,
82             boolean isInStandbyMode, boolean shutdown, Date JavaDoc startTime, int numJobsExec,
83             Class JavaDoc jsClass, boolean jsPersistent, Class JavaDoc tpClass, int tpSize,
84             String JavaDoc version) {
85         this.schedName = schedName;
86         this.schedInst = schedInst;
87         this.schedClass = schedClass;
88         this.isRemote = isRemote;
89         this.started = started;
90         this.isInStandbyMode = isInStandbyMode;
91         this.shutdown = shutdown;
92         this.startTime = startTime;
93         this.numJobsExec = numJobsExec;
94         this.jsClass = jsClass;
95         this.jsPersistent = jsPersistent;
96         this.tpClass = tpClass;
97         this.tpSize = tpSize;
98         this.version = version;
99     }
100
101     /*
102      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103      *
104      * Interface.
105      *
106      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107      */

108
109     /**
110      * <p>
111      * Returns the name of the <code>Scheduler</code>.
112      * </p>
113      */

114     public String JavaDoc getSchedulerName() {
115         return schedName;
116     }
117
118     /**
119      * <p>
120      * Returns the instance Id of the <code>Scheduler</code>.
121      * </p>
122      */

123     public String JavaDoc getSchedulerInstanceId() {
124         return schedInst;
125     }
126
127     /**
128      * <p>
129      * Returns the class-name of the <code>Scheduler</code> instance.
130      * </p>
131      */

132     public Class JavaDoc getSchedulerClass() {
133         return schedClass;
134     }
135
136     /**
137      * <p>
138      * Returns the <code>Date</code> at which the Scheduler started running.
139      * </p>
140      *
141      * @return null if the scheduler has not been started.
142      */

143     public Date JavaDoc runningSince() {
144         return startTime;
145     }
146
147     /**
148      * <p>
149      * Returns the number of jobs executed since the <code>Scheduler</code>
150      * started..
151      * </p>
152      */

153     public int numJobsExecuted() {
154         return numJobsExec;
155     }
156
157     /**
158      * <p>
159      * Returns whether the <code>Scheduler</code> is being used remotely (via
160      * RMI).
161      * </p>
162      */

163     public boolean isSchedulerRemote() {
164         return isRemote;
165     }
166
167     /**
168      * <p>
169      * Returns whether the scheduler has been started.
170      * </p>
171      *
172      * <p>
173      * Note: <code>isStarted()</code> may return <code>true</code> even if
174      * <code>isInStandbyMode()</code> returns <code>true</code>.
175      * </p>
176      */

177     public boolean isStarted() {
178         return started;
179     }
180
181     /**
182      * Reports whether the <code>Scheduler</code> is in standby mode.
183      */

184     public boolean isInStandbyMode() {
185         return isInStandbyMode;
186     }
187
188     /**
189      * Reports whether the <code>Scheduler</code> is paused.
190      *
191      * @deprecated Please use <code>{@link #isInStandbyMode()}</code>.
192      *
193      * @see #isInStandbyMode()
194      */

195     public boolean isPaused() {
196         return isInStandbyMode();
197     }
198     
199     /**
200      * <p>
201      * Reports whether the <code>Scheduler</code> has been shutdown.
202      * </p>
203      */

204     public boolean isShutdown() {
205         return shutdown;
206     }
207
208     /**
209      * <p>
210      * Returns the class-name of the <code>JobStore</code> instance that is
211      * being used by the <code>Scheduler</code>.
212      * </p>
213      */

214     public Class JavaDoc getJobStoreClass() {
215         return jsClass;
216     }
217
218     /**
219      * <p>
220      * Returns whether or not the <code>Scheduler</code>'s<code>JobStore</code>
221      * instance supports persistence.
222      * </p>
223      */

224     public boolean jobStoreSupportsPersistence() {
225         return jsPersistent;
226     }
227
228     /**
229      * <p>
230      * Returns the class-name of the <code>ThreadPool</code> instance that is
231      * being used by the <code>Scheduler</code>.
232      * </p>
233      */

234     public Class JavaDoc getThreadPoolClass() {
235         return tpClass;
236     }
237
238     /**
239      * <p>
240      * Returns the number of threads currently in the <code>Scheduler</code>'s
241      * <code>ThreadPool</code>.
242      * </p>
243      */

244     public int getThreadPoolSize() {
245         return tpSize;
246     }
247
248     /**
249      * <p>
250      * Returns the version of Quartz that is running.
251      * </p>
252      */

253     public String JavaDoc getVersion() {
254         return version;
255     }
256
257     /**
258      * <p>
259      * Return a simple string representation of this object.
260      * </p>
261      */

262     public String JavaDoc toString() {
263         try {
264             return getSummary();
265         } catch (SchedulerException se) {
266             return "SchedulerMetaData: undeterminable.";
267         }
268     }
269
270     /**
271      * <p>
272      * Returns a formatted (human readable) String describing all the <code>Scheduler</code>'s
273      * meta-data values.
274      * </p>
275      *
276      * <p>
277      * The format of the String looks something like this:
278      *
279      * <pre>
280      *
281      *
282      * Quartz Scheduler 'SchedulerName' with instanceId 'SchedulerInstanceId' Scheduler class: 'org.quartz.impl.StdScheduler' - running locally. Running since: '11:33am on Jul 19, 2002' Not currently paused. Number of Triggers fired: '123' Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with '8' threads Using job-store 'org.quartz.impl.JDBCJobStore' - which supports persistence.
283      * </pre>
284      *
285      * </p>
286      */

287     public String JavaDoc getSummary() throws SchedulerException {
288         StringBuffer JavaDoc str = new StringBuffer JavaDoc("Quartz Scheduler (v");
289         str.append(getVersion());
290         str.append(") '");
291
292         str.append(getSchedulerName());
293         str.append("' with instanceId '");
294         str.append(getSchedulerInstanceId());
295         str.append("'\n");
296
297         str.append(" Scheduler class: '");
298         str.append(getSchedulerClass().getName());
299         str.append("'");
300         if (isSchedulerRemote()) {
301             str.append(" - access via RMI.");
302         } else {
303             str.append(" - running locally.");
304         }
305         str.append("\n");
306
307         if (!isShutdown()) {
308             if (runningSince() != null) {
309                 str.append(" Running since: ");
310                 str.append(runningSince());
311             } else {
312                 str.append("NOT STARTED.");
313             }
314             str.append("\n");
315
316             if (isInStandbyMode()) {
317                 str.append(" Currently in standby mode.");
318             } else {
319                 str.append(" Not currently in standby mode.");
320             }
321         } else {
322             str.append(" Scheduler has been SHUTDOWN.");
323         }
324         str.append("\n");
325
326         str.append(" Number of jobs executed: ");
327         str.append(numJobsExecuted());
328         str.append("\n");
329
330         str.append(" Using thread pool '");
331         str.append(getThreadPoolClass().getName());
332         str.append("' - with ");
333         str.append(getThreadPoolSize());
334         str.append(" threads.");
335         str.append("\n");
336
337         str.append(" Using job-store '");
338         str.append(getJobStoreClass().getName());
339         str.append("' - which ");
340         if (jobStoreSupportsPersistence()) {
341             str.append("supports persistence.");
342         } else {
343             str.append("does not support persistence.");
344         }
345         str.append("\n");
346
347         return str.toString();
348     }
349
350 }
351
Popular Tags