Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
  */
 
 package org.apache.tuscany.sca.core.invocation.impl;
 
 import java.util.Map;
 import java.util.UUID;
 
 
A class which provides an Implementation of a Future<V> and Response<V> for use with the JAXWS defined client asynchronous APIs. This implementation class provides the interfaces for use by the client code, but also provides methods for the Tuscany system code to set the result of the asynchronous service invocation, both Regular and Fault responses. This class is constructed to be fully thread-safe

Parameters:
<V> - this is the type of the response message from the invoked service.
 
 public class AsyncInvocationFutureImpl<V> implements Future<V>, Response<V>, AsyncResponseHandler<V> {
 	
 	// Lock for handling the completion of this Future
 	private final Lock lock = new ReentrantLock();
     private final Condition isDone  = .newCondition(); 
     
 	// The result
 	private volatile V response = null;
 	private volatile Throwable fault = null
 	
 	private String uniqueID = UUID.randomUUID().toString();
 	
 	private ClassLoader classLoader = null;
 	
 	protected AsyncInvocationFutureImpl() {
 		super();
 	} // end constructor
 	
Public constructor for AsyncInvocationFutureImpl - newInstance is necessary in order to enable the Type variable to be set for the class instances

Parameters:
<V> - the type of the response from the asynchronously invoked service
type - the type of the AsyncInvocationFutureImpl expressed as a parameter
classLoader - the classloader used for the business interface to which this Future applies
Returns:
- an instance of AsyncInvocationFutureImpl<V>
 
 	public static <V> AsyncInvocationFutureImpl<V> newInstanceClass<V> typeClassLoader classLoader ) {
 		future.setClassLoaderclassLoader );
 		return future;
 	}

Cancels the asynchronous process - not possible in this version, so always returns false
 
 	public boolean cancel(boolean mayInterruptIfRunning) {
 		return false;
 	}

Gets the response value returned by the asynchronous process - waits forever

Returns:
- the response value of type V
Throws:
java.lang.InterruptedException if the get() method was interrupted while waiting for the async process to finish
java.util.concurrent.ExecutionException if the async process threw an exception - the exception thrown is nested
 
 	public V get() throws InterruptedExceptionExecutionException {
 		try {
 			V response = get(..);
 			return response;
 		} catch (TimeoutException t) {
			throw new InterruptedException("Timed out waiting for Future to complete");
// end try
// end method get()
Gets the response value returned by the asynchronous process

Returns:
- the response value of type V
Throws:
java.lang.InterruptedException if the get() method was interrupted while waiting for the async process to finish
java.util.concurrent.ExecutionException if the async process threw an exception - the exception thrown is nested
java.util.concurrent.TimeoutException if the get() method timed out waiting for the async process to finish
	public V get(long timeoutTimeUnit unitthrows InterruptedException,
		try {
			// wait for result to be available
			ifnotSetYet() ) .awaittimeoutunit);
			if != null ) return ;
			if != null ) throw new ExecutionException );
			throw new TimeoutException("get on this Future timed out");
finally {
// end try
// end method get(long timeout, TimeUnit unit)
Indicates if the asynchronous process has been cancelled - not possible in this version so always returns false
	public boolean isCancelled() {
		return false;
	}

Indicates if the asynchronous process is completed

Returns:
- true if the process is completed, false otherwise
	public boolean isDone() {
		try {
			return !notSetYet();
finally {
// end try
// end method isDone
Async process completed with a Fault. Must only be invoked once.

Parameters:
e - the Fault to send
Throws:
java.lang.IllegalStateException if either the setResponse method or the setFault method have been called previously
	public void setFaultThrowable e ) {
		try {
			ifnotSetYet() ) {
				 = e;
else {
				throw new IllegalStateException("setResponse() or setFault() has been called previously");
// end if 
finally {
// end try
// end method setFault( Throwable )
Async process completed with a wrapped Fault. Must only be invoked once.

Parameters:
w - the wrapped Fault to send
Throws:
java.lang.IllegalStateException if either the setResponse method or the setFault method have been called previously
		try {
			 // Set the TCCL to the classloader of the business interface
            Thread.currentThread().setContextClassLoader(this.getClassLoader());
			e = w.retrieveFault();
finally {
// end try
		ife == null ) throw new IllegalArgumentException("AsyncFaultWrapper did not return an Exception");
		setFaulte );
// end method setFault( AsyncFaultWrapper )
Async process completed with a response message. Must only be invoked once

Parameters:
res - the response message, which is of type V
Throws:
java.lang.IllegalStateException if either the setResponse method or the setFault method have been called previously
	public void setResponse(V res) {
		try {
			ifnotSetYet() ) {
				 = res;
else {
				throw new IllegalStateException("setResponse() or setFault() has been called previously");
			}
finally {
// end try
// end method setResponse
Gets the unique ID of this future as a String
	public String getUniqueID() { return ; }

Indicates that setting a response value is OK - can only set the response value or fault once

Returns:
- true if it is OK to set the response, false otherwise
	private boolean notSetYet() {
		return (  == null &&  == null );
	}

Returns the JAXWS context for the response

Returns:
- a Map containing the context
	public Map<StringObjectgetContext() {
		// Intentionally returns null
		return null;
	}

Gets the classloader associated with the business interface to which this Future relates

Returns:
the ClassLoader of the business interface
		return ;
	}

Sets the classloader associated with the business interface to which this Future relates

Parameters:
classLoader - the classloader of the business interface
	public void setClassLoader(ClassLoader classLoader) {
		this. = classLoader;
	}
// end class AsyncInvocationFutureImpl
New to GrepCode? Check out our FAQ X