KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > jca > workmanager > ResourceWork


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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: ResourceWork.java 666 2006-06-18 17:55:41Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.jca.workmanager;
27
28 import javax.resource.spi.work.ExecutionContext JavaDoc;
29 import javax.resource.spi.work.Work JavaDoc;
30 import javax.resource.spi.work.WorkListener JavaDoc;
31
32 import org.objectweb.easybeans.log.JLog;
33 import org.objectweb.easybeans.log.JLogFactory;
34
35 /**
36  * This class defines a work of the JCA API by adding some properties around
37  * this work.
38  * @author Philippe Durieux (JOnAS)
39  * @author Florent Benoit (EasyBeans)
40  */

41 public class ResourceWork {
42
43     /**
44      * Logger.
45      */

46     private static JLog logger = JLogFactory.getLog(ResourceWorkThread.class);
47
48     /**
49      * Work object that is wrapped.
50      */

51     private Work JavaDoc work;
52
53     /**
54      * Timeout for the given work.
55      */

56     private long timeout;
57
58     /**
59      * JCA Execution context (contains information about transactions).
60      */

61     private ExecutionContext JavaDoc executionContext;
62
63     /**
64      * Listener that is notified when work are
65      * accepted/rejected/started/completed.
66      */

67     private WorkListener JavaDoc workListener;
68
69     /**
70      * Creation of this object.
71      */

72     private long creationTime;
73
74     /**
75      * This work has been started or not ? (default = false).
76      */

77     private boolean started = false;
78
79     /**
80      * Default constructor : build a wrapper around the given work.
81      * @param work the given work
82      * @param timeout the timeout of this work
83      * @param executionContext the context for the given work
84      * @param workListener the listener on this work object
85      */

86     @SuppressWarnings JavaDoc("boxing")
87     public ResourceWork(final Work JavaDoc work, final long timeout, final ExecutionContext JavaDoc executionContext,
88             final WorkListener JavaDoc workListener) {
89         this.work = work;
90         this.timeout = timeout;
91         this.executionContext = executionContext;
92         this.workListener = workListener;
93         creationTime = System.currentTimeMillis();
94         if (logger.isDebugEnabled()) {
95             logger.debug("Timeout value is {0}", timeout);
96         }
97     }
98
99     /**
100      * @return the work object
101      */

102     public Work JavaDoc getWork() {
103         return work;
104     }
105
106     /**
107      * @return the timeout of this object
108      */

109     public long getTimeout() {
110         return timeout;
111     }
112
113     /**
114      * @return the execution context of this work
115      */

116     public ExecutionContext JavaDoc getExecutionContext() {
117         return executionContext;
118     }
119
120     /**
121      * @return the listener of this work.
122      */

123     public WorkListener JavaDoc getWorkListener() {
124         return workListener;
125     }
126
127     /**
128      * @return the creation time of this object.
129      */

130     public long getCreationTime() {
131         return creationTime;
132     }
133
134     /**
135      * @return true if the work has been started, else false.
136      */

137     public boolean isStarted() {
138         return started;
139     }
140
141     /**
142      * Sets the started mode to true.
143      */

144     public void setStarted() {
145         started = true;
146     }
147 }
148
Popular Tags