KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
21  * The batch class is the class in which tasks are created and provided to a service that executes them.<br>
22  * The batch class must implements the interface IBatch. Each method corresponds to a step of the batch life cycle.<br>
23  * If a BatchException is throw into one of these methods, the method
24  * <i>manageFatalError</i> will be called and the batch will be shutdown.
25  *
26  * @see ITask
27  * @author Jérôme Bertèche (cyberteche@users.sourceforge.net)
28  */

29 public interface IBatch {
30     
31     /**
32      * Initialization method of the batch.<br>
33      * The batch configuration (loading from the configuration file in the automatic mode)
34      * can be modified here to change the behavior of the batch before it is launched.<bR>
35      * <i>Use:</i> init JDBC connections pool, read proprietary configuration, sending of a notification mail, ...
36      * @param configuration the configuration of the batch
37      * @throws BatchException if throw, then the batch is stopped
38      */

39     public void init(BatchConfiguration configuration) throws BatchException;
40     
41     /**
42      * Execution method of the batch.<br>
43      * Tasks must be given to the executor service at this time.
44      * Called one time, or more if the batch is schedule for a number of loop or at fixed period.<br>
45      * <i>Note:</i> the building tasks are of type ITask. Each task must provides an unique identifier to differentiate them.<br>
46      * <i>Use:</i> build of tasks that are provided to the executor service.
47      * @see ITask
48      * @param executor the tasks executor
49      * @throws BatchException if throw, then the batch is stopped
50      */

51     public void execute(ITaskExecutor executor) throws BatchException;
52     
53     /**
54      * Called then the batch execution has been put into waking through the call of the corresponding JMX operation.
55      * No more tasks are executed by the executor service at this time.<br>
56      * <i>Use:</i> free connections of the JDBC connections pool,...
57      * @throws BatchException if throw, then the batch is stopped
58      */

59     public void pause() throws BatchException;
60     
61     /**
62      * Called then the batch execution has been resumed through the call of the corresponding JMX operation.
63      * The executor service takes back the tasks execution.
64      * <i>Use:</i> re-establish the connections of the JDBC connections pool, ...
65      * @throws BatchException if throw, then the batch is stopped
66      */

67     public void resume() throws BatchException;
68     
69     /**
70      * Called at the end of the batch execution.<br>
71      * The execution report contains the start date of the execution, the end date, a list of ids of tasks
72      * for which the execution has been a success and an another for the tasks for which the execution has failed.
73      * <i>Use:</i> destroy of the JDBC connections pool, sending of a report mail, log of the execution report, ...
74      * @param report the execution report
75      * @throws BatchException if throw, then the batch is stopped
76      */

77     public void end(ExecutionReport report) throws BatchException;
78     
79     /**
80      * Called after the end of the execution of a task.<br>
81      * <b>Warning:</b> called by a worker thread (the content must be ThreadSafe)
82      * @param task the failed task
83      * @param exception the cause of the failure
84      */

85     public void endOfExecution(ITask task, Throwable JavaDoc exception);
86     
87     /**
88      * Called if a fatal error occurred. In this case, the batch will be stopped just after this call.<br>
89      * A fatal error is an exception throws into one of the batch class method.<br>
90      * <i>Use:</i> sending of a notification mail, ...<br>
91      * <b>Warning:</b> called by a worker thread.
92      * @param report the execution report
93      * @param throwable the cause of the error
94      */

95     public void manageFatalError(ExecutionReport report, Throwable JavaDoc throwable);
96 }
97
Popular Tags