01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: ResourceWorkThread.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.jca.workmanager;
25:
26: import javax.resource.spi.work.WorkException;
27:
28: import org.ow2.util.log.Log;
29: import org.ow2.util.log.LogFactory;
30:
31: /**
32: * Thread executing works for the work manager.
33: * @author Philippe Durieux (JOnAS)
34: * @author Florent Benoit (EasyBeans)
35: */
36: public class ResourceWorkThread extends Thread {
37:
38: /**
39: * Logger.
40: */
41: private Log logger = LogFactory.getLog(ResourceWorkThread.class);
42:
43: /**
44: * Resource WorkManager used by this worker thread.
45: */
46: private ResourceWorkManager workManager;
47:
48: /**
49: * Build a thread doing the work.
50: * @param workManager The implementation of WorkManager API.
51: * @param threadNumber the thread number for this thread (debug info)
52: * @param workManagerNumber identifier of the work manager instance
53: */
54: ResourceWorkThread(final ResourceWorkManager workManager,
55: final int workManagerNumber, final int threadNumber) {
56: this .workManager = workManager;
57: setName(this .getClass().getName() + "-" + workManagerNumber
58: + "/" + threadNumber);
59: }
60:
61: /**
62: * Start the thread work.
63: */
64: @Override
65: public void run() {
66:
67: while (true) {
68: try {
69: workManager.nextWork();
70: } catch (InterruptedException e) {
71: logger
72: .error("Exception while waiting during a work",
73: e);
74: return;
75: } catch (WorkException e) {
76: logger.error("Exception during work run", e);
77: } catch (ResourceWorkManagerStoppedException e) {
78: logger.debug("Manager has been stopped", e);
79: return;
80: }
81: }
82: }
83: }
|