001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.aspects.asynchronous.concurrent;
023:
024: import EDU.oswego.cs.dl.util.concurrent.Callable;
025: import org.jboss.aspects.asynchronous.AsynchronousConstants;
026: import org.jboss.aspects.asynchronous.AsynchronousParameters;
027: import org.jboss.aspects.asynchronous.AsynchronousResponse;
028: import org.jboss.aspects.asynchronous.AsynchronousUserTask;
029: import org.jboss.aspects.asynchronous.ProcessingTime;
030: import org.jboss.aspects.asynchronous.ThreadManagerResponse;
031: import org.jboss.aspects.asynchronous.common.ThreadManagerResponseImpl;
032:
033: /**
034: * @author <a href="mailto:chussenet@yahoo.com">{Claude Hussenet Independent Consultant}</a>.
035: * @version <tt>$Revision: 57186 $</tt>
036: */
037:
038: final class AdapterTask
039:
040: implements Callable, AsynchronousConstants, ProcessingTime {
041:
042: private AsynchronousParameters _inputParametersImpl = null;
043:
044: private AsynchronousUserTask _taskImpl = null;
045:
046: private String id = null;
047:
048: private long startingTime = -1;
049:
050: private long endingTime = -1;
051:
052: AdapterTask(String id,
053:
054: AsynchronousParameters inputParametersImpl,
055:
056: AsynchronousUserTask taskImpl) {
057:
058: _inputParametersImpl = inputParametersImpl;
059:
060: _taskImpl = taskImpl;
061:
062: this .id = id;
063:
064: }
065:
066: public void cleanup() {
067:
068: _taskImpl.cleanup(_inputParametersImpl);
069:
070: }
071:
072: public java.lang.Object call() {
073:
074: try {
075:
076: startingTime = System.currentTimeMillis();
077:
078: AsynchronousResponse taskResult =
079:
080: _taskImpl.process(_inputParametersImpl);
081:
082: endingTime = System.currentTimeMillis();
083:
084: ThreadManagerResponse myResult =
085:
086: new ThreadManagerResponseImpl(getId(),
087:
088: OK,
089:
090: null,
091:
092: taskResult,
093:
094: startingTime,
095:
096: endingTime);
097:
098: return myResult;
099:
100: } catch (Exception e) {
101:
102: try {
103:
104: endingTime = System.currentTimeMillis();
105:
106: return new ThreadManagerResponseImpl(getId(),
107:
108: UNKNOWN,
109:
110: e.getMessage(),
111:
112: e);
113:
114: } catch (Exception ee) {
115:
116: endingTime = System.currentTimeMillis();
117:
118: return new ThreadManagerResponseImpl(getId(),
119:
120: UNKNOWN,
121:
122: e.getMessage(),
123:
124: ee);
125:
126: }
127:
128: }
129:
130: }
131:
132: public String getId() {
133:
134: return id;
135:
136: }
137:
138: public long getStartingTime() {
139:
140: return startingTime;
141:
142: }
143:
144: public long getEndingTime() {
145:
146: return endingTime;
147:
148: }
149:
150: }
|