org.glassfish.jersey.process.internal
Class AsyncInflectorAdapter<REQUEST,RESPONSE>

java.lang.Object
  extended by com.google.common.util.concurrent.AbstractFuture<RESPONSE>
      extended by org.glassfish.jersey.process.internal.AsyncInflectorAdapter<REQUEST,RESPONSE>
Type Parameters:
REQUEST - request processing data type.
RESPONSE - response processing data type.
All Implemented Interfaces:
com.google.common.util.concurrent.ListenableFuture<RESPONSE>, java.util.concurrent.Future<RESPONSE>, ExecutionContext, Inflector<REQUEST,com.google.common.util.concurrent.ListenableFuture<RESPONSE>>, InvocationContext

public abstract class AsyncInflectorAdapter<REQUEST,RESPONSE>
extends com.google.common.util.concurrent.AbstractFuture<RESPONSE>
implements Inflector<REQUEST,com.google.common.util.concurrent.ListenableFuture<RESPONSE>>, InvocationContext

Suspendable, asynchronous inflector adapter that provides implementation of the request suspend/resume capabilities of the invocation context and returns a listenable response future instead of a plain response object.

Author:
Marek Potociar (marek.potociar at oracle.com)

Nested Class Summary
static interface AsyncInflectorAdapter.Builder<REQUEST,RESPONSE>
          Asynchronous inflector adapter factory.
 
Nested classes/interfaces inherited from interface org.glassfish.jersey.process.internal.InvocationContext
InvocationContext.State
 
Constructor Summary
protected AsyncInflectorAdapter(Inflector<REQUEST,RESPONSE> wrapped, InvocationCallback<RESPONSE> callback)
          Construct and initialize asynchronous inflector adapter for an inflector.
 
Method Summary
 com.google.common.util.concurrent.ListenableFuture<RESPONSE> apply(REQUEST request)
          Invoke request on the wrapped inflector.
 void cancel()
           
protected abstract  RESPONSE convertResponse(REQUEST originatingRequest, Response response)
          Convert the JAX-RS response to supported response data type.
 Response getResponse()
           
protected  void interruptTask()
           
 boolean isSuspended()
           
 void resume(java.lang.Object response)
           
 void resume(java.lang.Throwable response)
           
 void setResponse(java.lang.Object response)
           
 void setSuspendTimeout(long time, java.util.concurrent.TimeUnit unit)
           
 InvocationContext.State state()
          Get the current state of the invocation context.
 void suspend()
           
 void suspend(long millis)
           
 void suspend(long time, java.util.concurrent.TimeUnit unit)
           
 java.lang.String toString()
           
 boolean trySuspend()
          Try to suspend the request invocation.
 
Methods inherited from class com.google.common.util.concurrent.AbstractFuture
addListener, cancel, get, get, isCancelled, isDone, set, setException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.ws.rs.core.ExecutionContext
isCancelled, isDone
 

Constructor Detail

AsyncInflectorAdapter

protected AsyncInflectorAdapter(Inflector<REQUEST,RESPONSE> wrapped,
                                InvocationCallback<RESPONSE> callback)
Construct and initialize asynchronous inflector adapter for an inflector.

Parameters:
wrapped - wrapped inflector.
callback - invocation callback.
Method Detail

apply

public com.google.common.util.concurrent.ListenableFuture<RESPONSE> apply(REQUEST request)
Invoke request on the wrapped inflector. The adapter itself serves as a listenable response future.

Specified by:
apply in interface Inflector<REQUEST,com.google.common.util.concurrent.ListenableFuture<RESPONSE>>
Parameters:
request - request data to be processed.
Returns:
data transformation result. Return value must not be null.

state

public InvocationContext.State state()
Description copied from interface: InvocationContext
Get the current state of the invocation context.

Specified by:
state in interface InvocationContext
Returns:
current state of the invocation context

resume

public void resume(java.lang.Object response)
Specified by:
resume in interface ExecutionContext

resume

public void resume(java.lang.Throwable response)
            throws java.lang.IllegalStateException
Specified by:
resume in interface ExecutionContext
Throws:
java.lang.IllegalStateException

setSuspendTimeout

public void setSuspendTimeout(long time,
                              java.util.concurrent.TimeUnit unit)
Specified by:
setSuspendTimeout in interface ExecutionContext

trySuspend

public boolean trySuspend()
Description copied from interface: InvocationContext
Try to suspend the request invocation. Unlike the suspend() method, this method does not throw an exception in case the suspend operation fails. Instead, the method returns true if the invocation has been suspended successfully, returns false otherwise.

Specified by:
trySuspend in interface InvocationContext
Returns:
true if the invocation has been suspended successfully, returns false otherwise.

suspend

public void suspend()
Specified by:
suspend in interface ExecutionContext

suspend

public void suspend(long millis)
Specified by:
suspend in interface ExecutionContext

suspend

public void suspend(long time,
                    java.util.concurrent.TimeUnit unit)
Specified by:
suspend in interface ExecutionContext

cancel

public void cancel()
Specified by:
cancel in interface ExecutionContext

isSuspended

public boolean isSuspended()
Specified by:
isSuspended in interface ExecutionContext

interruptTask

protected void interruptTask()
Overrides:
interruptTask in class com.google.common.util.concurrent.AbstractFuture<RESPONSE>

setResponse

public void setResponse(java.lang.Object response)
Specified by:
setResponse in interface ExecutionContext

getResponse

public Response getResponse()
Specified by:
getResponse in interface ExecutionContext

convertResponse

protected abstract RESPONSE convertResponse(REQUEST originatingRequest,
                                            Response response)
Convert the JAX-RS response to supported response data type.

Parameters:
originatingRequest - originating request data.
response - JAX-RS response.
Returns:
JAX-RS response converted to supported response data type.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.