001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ResourceWork.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.jca.workmanager;
025:
026: import javax.resource.spi.work.ExecutionContext;
027: import javax.resource.spi.work.Work;
028: import javax.resource.spi.work.WorkListener;
029:
030: import org.ow2.util.log.Log;
031: import org.ow2.util.log.LogFactory;
032:
033: /**
034: * This class defines a work of the JCA API by adding some properties around
035: * this work.
036: * @author Philippe Durieux (JOnAS)
037: * @author Florent Benoit (EasyBeans)
038: */
039: public class ResourceWork {
040:
041: /**
042: * Logger.
043: */
044: private static Log logger = LogFactory
045: .getLog(ResourceWorkThread.class);
046:
047: /**
048: * Work object that is wrapped.
049: */
050: private Work work;
051:
052: /**
053: * Timeout for the given work.
054: */
055: private long timeout;
056:
057: /**
058: * JCA Execution context (contains information about transactions).
059: */
060: private ExecutionContext executionContext;
061:
062: /**
063: * Listener that is notified when work are
064: * accepted/rejected/started/completed.
065: */
066: private WorkListener workListener;
067:
068: /**
069: * Creation of this object.
070: */
071: private long creationTime;
072:
073: /**
074: * This work has been started or not ? (default = false).
075: */
076: private boolean started = false;
077:
078: /**
079: * Default constructor : build a wrapper around the given work.
080: * @param work the given work
081: * @param timeout the timeout of this work
082: * @param executionContext the context for the given work
083: * @param workListener the listener on this work object
084: */
085: @SuppressWarnings("boxing")
086: public ResourceWork(final Work work, final long timeout,
087: final ExecutionContext executionContext,
088: final WorkListener workListener) {
089: this .work = work;
090: this .timeout = timeout;
091: this .executionContext = executionContext;
092: this .workListener = workListener;
093: creationTime = System.currentTimeMillis();
094: if (logger.isDebugEnabled()) {
095: logger.debug("Timeout value is {0}", timeout);
096: }
097: }
098:
099: /**
100: * @return the work object
101: */
102: public Work 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 getExecutionContext() {
117: return executionContext;
118: }
119:
120: /**
121: * @return the listener of this work.
122: */
123: public WorkListener 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: }
|