KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > bean > BeanThread


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
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  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * BeanThread.java
20  *
21  * This object is responsible for calling the run and terminate methods on the
22  * BeanRunnable object.
23  */

24
25 // package path
26
package com.rift.coad.lib.bean;
27
28 // logging import
29
import org.apache.log4j.Logger;
30
31 // coadunation imports
32
import com.rift.coad.lib.thread.BasicThread;
33
34 /**
35  * This object is responsible for calling the run and terminate methods on the
36  * BeanRunnable object.
37  *
38  * @author Brett Chaldecott
39  */

40 public class BeanThread extends BasicThread {
41     
42     // the class log variable
43
protected Logger log =
44         Logger.getLogger(BasicThread.class.getName());
45     
46     // the classes member variables
47
private BeanRunnable bean = null;
48     
49     /**
50      * Creates a new instance of BeanThread
51      *
52      * @param bean The reference to the
53      */

54     public BeanThread(BeanRunnable bean) throws Exception JavaDoc
55     {
56         this.bean = bean;
57     }
58     
59     
60     /**
61      * This method replaces the run method in the BasicThread.
62      *
63      * @exception Exception
64      */

65     public void process() throws Exception JavaDoc {
66         try {
67             bean.process();
68         } catch (Exception JavaDoc ex) {
69             log.error("Failed to process with this thread : " + ex.getMessage(),
70                     ex);
71         }
72     }
73     
74     
75     /**
76      * This method will be implemented by child objects to terminate the
77      * processing of this thread.
78      */

79     public void terminate() {
80         try {
81             bean.terminate();
82         } catch (Exception JavaDoc ex) {
83             log.error("Failed to terminate this thread : " + ex.getMessage(),
84                     ex);
85         }
86     }
87 }
88
Popular Tags