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

java.lang.Object
  extended by org.glassfish.jersey.process.internal.RequestInvoker<REQUEST,RESPONSE>
Type Parameters:
REQUEST - request processing data type.
RESPONSE - response processing data type.

public class RequestInvoker<REQUEST,RESPONSE>
extends java.lang.Object

Request invoker is the main request to response data processing entry point. It accepts request data and returns a listenable response data future.

Request invoker runs the request data through the (injected) request data processing stages until a terminal request processing stage referencing an Inflector is reached. The inflector referenced by the terminal request processing stage is then wrapped into a suspendable inflector which is subsequently invoked. Once a response data from the inflector is available, it is processed by a response processor before it is made available in the response future returned by the request invoker. If a response callback is supplied, it is invoked at the end of the response processing chain.

Request and response processing flows are executed in the context of dedicated customizable executors, one for request and the other one for response data processing. By default, the request processing is executed on the caller thread. If the request processing is not suspended in the inflector, the response processing is by default executed synchronously on the caller thread too. In case the request processing is suspended, the response processing is resumed in the thread executing the code that resumed the response processing.

Author:
Marek Potociar (marek.potociar at oracle.com), Jakub Podlesak (jakub.podlesak at oracle.com)

Constructor Summary
RequestInvoker(Stage<REQUEST> rootStage, RequestScope requestScope, AsyncInflectorAdapter.Builder<REQUEST,RESPONSE> asyncAdapterBuilder, ResponseProcessor.Builder<RESPONSE> responseProcessorBuilder, javax.inject.Provider<Ref<InvocationContext>> invocationContextReferenceFactory, ExecutorsFactory<REQUEST> executorsFactory)
          Create new request invoker.
 
Method Summary
 com.google.common.util.concurrent.ListenableFuture<RESPONSE> apply(REQUEST request)
          Transform request data of a given type into a response result of the different type.
 com.google.common.util.concurrent.ListenableFuture<RESPONSE> apply(REQUEST request, InvocationCallback<RESPONSE> callback)
          Transform request data of a given type into a response result of the different type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestInvoker

public RequestInvoker(Stage<REQUEST> rootStage,
                      RequestScope requestScope,
                      AsyncInflectorAdapter.Builder<REQUEST,RESPONSE> asyncAdapterBuilder,
                      ResponseProcessor.Builder<RESPONSE> responseProcessorBuilder,
                      javax.inject.Provider<Ref<InvocationContext>> invocationContextReferenceFactory,
                      ExecutorsFactory<REQUEST> executorsFactory)
Create new request invoker.

Parameters:
rootStage - root processing stage.
requestScope - request scope.
asyncAdapterBuilder - asynchronous adapter builder.
responseProcessorBuilder - response processor builder.
invocationContextReferenceFactory - invocation context reference provider.
executorsFactory - processing executors factory.
Method Detail

apply

public com.google.common.util.concurrent.ListenableFuture<RESPONSE> apply(REQUEST request)
Transform request data of a given type into a response result of the different type.

Parameters:
request - request data to be transformed into a response result.
Returns:
future response.

apply

public com.google.common.util.concurrent.ListenableFuture<RESPONSE> apply(REQUEST request,
                                                                          InvocationCallback<RESPONSE> callback)
Transform request data of a given type into a response result of the different type.

After the result is produced the provided result callback is invoked. The result callback can be invoked on a different thread but still in the same request invocation context.

Parameters:
request - request data to be transformed into a response result.
callback - result callback called when the request transformation is done. Must not be null.
Returns:
future response.


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