KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > mybatchfwk > ExecutionReport


1 /*
2  * MyBatchFramework - Open-source batch framework.
3  * Copyright (C) 2006 Jérôme Bertèche cyberteche@users.sourceforge.net
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  * Jérôme Bertèche
16  * Email: cyberteche@users.sourceforge.net
17  */

18 package net.sf.mybatchfwk;
19
20 import java.util.Date JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import net.sf.mybatchfwk.history.IExecutionHistory;
24
25 /**
26  * A basic execution report.<br>
27  * It contains informations about the batch execution: begin date, end date, identity of completed and failed tasks.<br>
28  * It is used for creating reports (mail, logs, ...) after the batch has been completed or after a fatal error.<br>
29  * <br>
30  * User can create his own execution report to store extra informations about the completions and the failures.
31  *
32  * @author Jérôme Bertèche (cyberteche@users.sourceforge.net)
33  */

34 public class ExecutionReport {
35     
36     /**
37      * Begin date of the execution
38      */

39     protected Date JavaDoc beginDate;
40     
41     /**
42      * End date of the execution
43      */

44     protected Date JavaDoc endDate;
45     
46     /**
47      * The number of completed tasks
48      */

49     protected volatile long numberOfCompletedTasks;
50     
51     /**
52      * The number of failed tasks
53      */

54     protected volatile long numberOfFailedTasks;
55     
56     /**
57      * The execution history
58      */

59     protected IExecutionHistory history;
60     
61     /**
62      * Default constructor
63      */

64     public ExecutionReport() {
65     }
66     
67     public ExecutionReport(IExecutionHistory history) {
68         this.history = history;
69     }
70     
71     /**
72      * Store informations about a task completion.
73      * @param task the completed task
74      */

75     public void reportCompletion(ITask task) {
76         numberOfCompletedTasks++;
77     }
78     
79     /**
80      * Store informations about a task failure.
81      * @param task the failed task
82      * @param throwable the cause of the failure
83      */

84     public void reportFailure(ITask task, Throwable JavaDoc throwable) {
85         numberOfFailedTasks++;
86     }
87     
88     /**
89      * Return an iterator over the id of the completed tasks, provided by the execution history
90      * @return
91      * @throws BatchException
92      */

93     public Iterator JavaDoc completedTasksIdIterator() throws BatchException {
94         if (history != null) {
95             return history.completedTasksIdIterator();
96         }
97         return null;
98     }
99     
100     /**
101      * Return an iterator over the id of the failed tasks, provided by the execution history
102      * @return
103      * @throws BatchException
104      */

105     public Iterator JavaDoc failedTasksIdIterator() throws BatchException {
106         if (history != null) {
107             return history.failedTasksIdIterator();
108         }
109         return null;
110     }
111     
112     @Override JavaDoc
113     public String JavaDoc toString() {
114         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("[")
115             .append("beginDate='").append(beginDate)
116             .append("', endDate='").append(endDate)
117             .append("', numberOfCompletedTasks='").append(numberOfCompletedTasks)
118             .append("', numberOfFailedTasks='").append(numberOfFailedTasks)
119             .append("']");
120         return buffer.toString();
121     }
122     
123     // ######################################################
124
// ################ GETTERS and SETTERS #################
125
// ######################################################
126

127     /**
128      * Return the begin date of the execution
129      * @return a date
130      */

131     public Date JavaDoc getBeginDate() {
132         return beginDate;
133     }
134
135     /**
136      * Set the begin date of the execution
137      * @param beginDate the begin date to set
138      */

139     public void setBeginDate(Date JavaDoc beginDate) {
140         this.beginDate = beginDate;
141     }
142
143     /**
144      * Return the end date of the execution
145      * @return a date
146      */

147     public Date JavaDoc getEndDate() {
148         return endDate;
149     }
150
151     /**
152      * Set the end date of the execution
153      * @param endDate the end date to set
154      */

155     public void setEndDate(Date JavaDoc endDate) {
156         this.endDate = endDate;
157     }
158
159     /**
160      * @return Returns the numberOfCompletedTasks.
161      */

162     public long getNumberOfCompletedTasks() {
163         return numberOfCompletedTasks;
164     }
165     
166     /**
167      * @return Returns the numberOfFailedTasks.
168      */

169     public long getNumberOfFailedTasks() {
170         return numberOfFailedTasks;
171     }
172
173     /**
174      * @return the history
175      */

176     public IExecutionHistory getHistory() {
177         return history;
178     }
179
180     /**
181      * @param history the history to set
182      */

183     public void setHistory(IExecutionHistory history) {
184         this.history = history;
185     }
186 }
187
Popular Tags