com.sun.jersey.api.client.async
Class TypeListener<T>

java.lang.Object
  extended by com.sun.jersey.api.client.async.TypeListener<T>
Type Parameters:
T - the type of the response.
All Implemented Interfaces:
FutureListener<T>, ITypeListener<T>

public abstract class TypeListener<T>
extends java.lang.Object
implements ITypeListener<T>

A listener to be implemented by clients that wish to receive callback notification of the completion of requests invoked asynchronously.

This listener is a helper class providing implementions for the methods ITypeListener.getType() and ITypeListener.getGenericType().

Instances of this class may be passed to appropriate methods on AsyncWebResource (or more specifically methods on AsyncUniformInterface). For example,

     AsyncWebResource r = ..
     Future<String> f = r.get(new TypeListener<String>(String.class) {
         public void onComplete(Future<String> f) throws InterruptedException {
             try {
                 String s = f.get();
             } catch (ExecutionException ex) {
                 // Do error processing
                 if (t instanceof UniformInterfaceException) {
                     // Request/response error
                 } else
                     // Error making request e.g. timeout
                 }

             }
         }
     });
 


Constructor Summary
TypeListener(java.lang.Class<T> type)
          Construct a new listener defining the class of the response to receive.
TypeListener(GenericType<T> genericType)
          Construct a new listener defining the generic type of the response to receive.
 
Method Summary
 GenericType<T> getGenericType()
          Get the generic type declaring the Java type of the instance to receive for FutureListener.onComplete(java.util.concurrent.Future).
 java.lang.Class<T> getType()
          Get the class of the instance to receive for FutureListener.onComplete(java.util.concurrent.Future).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.jersey.api.client.async.FutureListener
onComplete
 

Constructor Detail

TypeListener

public TypeListener(java.lang.Class<T> type)
Construct a new listener defining the class of the response to receive.

Parameters:
type - the class of the response.

TypeListener

public TypeListener(GenericType<T> genericType)
Construct a new listener defining the generic type of the response to receive.

Parameters:
genericType - the generic type of the response.
Method Detail

getType

public java.lang.Class<T> getType()
Description copied from interface: ITypeListener
Get the class of the instance to receive for FutureListener.onComplete(java.util.concurrent.Future).

Specified by:
getType in interface ITypeListener<T>
Returns:
the class of the response.

getGenericType

public GenericType<T> getGenericType()
Description copied from interface: ITypeListener
Get the generic type declaring the Java type of the instance to receive for FutureListener.onComplete(java.util.concurrent.Future).

Specified by:
getGenericType in interface ITypeListener<T>
Returns:
the generic type of the response. If null then the method ITypeListener.getType() must not return null. Otherwise, if not null, the type information declared by the generic type takes precedence over the value returned by ITypeListener.getType().


Copyright © 2010 Oracle Corporation. All Rights Reserved.