001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.xml.internal.ws.client.dispatch;
026:
027: import com.sun.xml.internal.ws.client.AsyncHandlerService;
028: import com.sun.xml.internal.ws.client.ResponseContext;
029:
030: import javax.xml.ws.Response;
031: import java.rmi.server.UID;
032: import java.util.Map;
033: import java.util.concurrent.Callable;
034: import java.util.concurrent.FutureTask;
035: import java.util.concurrent.locks.Lock;
036: import java.util.concurrent.locks.ReentrantLock;
037: import java.util.logging.Logger;
038:
039: /**
040: * The <code>Response</code> interface provides methods used to obtain the
041: * payload and context a message sent in response to an operation invocation.
042: * For asynchronous operation invocations it provides additional methods to
043: * check the status of the request.
044: *
045: * @author JAXWS Development Team
046: * @version 1.0
047: */
048:
049: public class ResponseImpl<T> extends FutureTask<T> implements
050: Response<T> {
051: private static final Logger logger = Logger
052: .getLogger(new StringBuffer()
053: .append(
054: com.sun.xml.internal.ws.util.Constants.LoggingDomain)
055: .append(".client.dispatch").toString());
056: private UID uid;
057: private Lock _lock;
058: private AsyncHandlerService _handlerService;
059: private ResponseContext _responseContext;
060: private boolean handler;
061:
062: public ResponseImpl(Callable<T> callable) {
063: super (callable);
064: _lock = new ReentrantLock();
065: }
066:
067: public ResponseImpl(Runnable runable, T result) {
068: super (runable, result);
069: _lock = new ReentrantLock();
070: }
071:
072: //protected method need to overide
073: public void setException(Exception ex) {
074: _lock.lock();
075: try {
076: super .setException(ex);
077: } catch (Exception e) {
078: } finally {
079: _lock.unlock();
080: }
081: }
082:
083: public void set(T result) {
084: _lock.lock();
085: try {
086: super .set(result);
087: } catch (Exception e) {
088: } finally {
089: _lock.unlock();
090: }
091: }
092:
093: /**
094: * Gets the contained response context.
095: *
096: * @return The contained response context. May be <code>null</code> if a
097: * response is not yet available.
098: */
099: public Map<String, Object> getContext() {
100: if (!isDone()) {
101: return null;
102: } else {
103: return (_responseContext);
104: }
105: }
106:
107: public void setResponseContext(Map context) {
108: _responseContext = (ResponseContext) context;
109: }
110:
111: public synchronized void setUID(UID id) {
112: uid = id;
113: }
114:
115: public synchronized UID getUID() {
116: return uid;
117: }
118:
119: public void setHandlerService(AsyncHandlerService handlerService) {
120: _handlerService = handlerService;
121: }
122:
123: //got to lock
124:
125: public void done() {
126: _lock.lock();
127: try {
128: if (!isCancelled())
129: _handlerService.executeWSFuture();
130:
131: } catch (Exception e) {
132: } finally {
133: _lock.unlock();
134: }
135: }
136: }
|