01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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 = Logger
44: .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 {
55: this .bean = bean;
56: }
57:
58: /**
59: * This method replaces the run method in the BasicThread.
60: *
61: * @exception Exception
62: */
63: public void process() throws Exception {
64: try {
65: bean.process();
66: } catch (Exception ex) {
67: log.error("Failed to process with this thread : "
68: + ex.getMessage(), ex);
69: }
70: }
71:
72: /**
73: * This method will be implemented by child objects to terminate the
74: * processing of this thread.
75: */
76: public void terminate() {
77: try {
78: bean.terminate();
79: } catch (Exception ex) {
80: log.error("Failed to terminate this thread : "
81: + ex.getMessage(), ex);
82: }
83: }
84: }
|