Top Description Fields Constructors Methods
org.springframework.orm.hibernate5.support

pack-priv Class AsyncRequestInterceptor

extends Object
implements CallableProcessingInterceptor, DeferredResultProcessingInterceptor
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.request.async.DeferredResultProcessingInterceptor, org.springframework.web.context.request.async.CallableProcessingInterceptor
Imports
java.util.concurrent.Callable, org.apache.commons.logging.Log, .LogFactory, org.hibernate.SessionFactory, org.springframework.orm.hibernate5.SessionFactoryUtils, .SessionHolder, org.springframework.transaction.support.TransactionSynchronizationManager, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.context.request.async.CallableProcessingInterceptor, .DeferredResult, .DeferredResultProcessingInterceptor

An interceptor with asynchronous web requests used in OpenSessionInViewFilter and OpenSessionInViewInterceptor. Ensures the following: 1) The session is bound/unbound when "callable processing" is started 2) The session is closed if an async request times out or an error occurred
Author
Rossen Stoyanchev
Since
4.2

Field Summary

Modifier and TypeField and Description
private volatile boolean
private static final Log
private final SessionFactory
sessionFactory

Deprecated as a consequence of SessionFactory being deprecated.
private final SessionHolder
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
AsyncRequestInterceptor(SessionFactory sessionFactory, SessionHolder sessionHolder)

Deprecated as a consequence of SessionFactory being deprecated.

Method Summary

Modifier and TypeMethod and Description
public <T> void
afterCompletion(NativeWebRequest
the current request
request
,
Callable<T>
the task for the current async request
task
)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.afterCompletion.

Invoked from a container thread when async processing completes for any reason including timeout or network error.
public <T> void
afterCompletion(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request
deferredResult
)

Overrides default org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.afterCompletion.

Invoked from a container thread when an async request completed for any reason including timeout and network error.
public void
private void
public <T> Object
handleError(NativeWebRequest
the current request
request
,
Callable<T>
the task for the current async request
task
,
Throwable
the error that occurred while request processing
t
)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.handleError.

Invoked from a container thread when an error occurred while processing the async request before the Callable task completes.
public <T> boolean
handleError(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked
deferredResult
,
Throwable
the error that occurred while request processing
t
)

Overrides default org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.handleError.

Invoked from a container thread when an error occurred while processing an async request before the DeferredResult has been set.
public <T> Object
handleTimeout(NativeWebRequest
the current request
request
,
Callable<T>
the task for the current async request
task
)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.handleTimeout.

Invoked from a container thread when the async request times out before the Callable task completes.
public <T> boolean
handleTimeout(NativeWebRequest
the current request
request
,
DeferredResult<T>
the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked
deferredResult
)

Overrides default org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.handleTimeout.

Invoked from a container thread when an async request times out before the DeferredResult has been set.
public <T> void
postProcess(NativeWebRequest
the current request
request
,
Callable<T>
the task for the current async request
task
,
Object
the result of concurrent processing, which could be a Throwable if the Callable raised an exception
concurrentResult
)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.postProcess.

Invoked after the Callable has produced a result in the async thread in which the Callable is executed.
public <T> void
preProcess(NativeWebRequest
the current request
request
,
Callable<T>
the task for the current async request
task
)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.preProcess.

Invoked after the start of concurrent handling in the async thread in which the Callable is executed and before the actual invocation of the Callable.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorInProgressback to summary
private volatile boolean errorInProgress
loggerback to summary
private static final Log logger
sessionFactoryback to summary
private final SessionFactory sessionFactory

Deprecated

as a consequence of SessionFactory being deprecated. See corresponding docs for further information.

sessionHolderback to summary
private final SessionHolder sessionHolder
timeoutInProgressback to summary
private volatile boolean timeoutInProgress

Constructor Detail

AsyncRequestInterceptorback to summary
public AsyncRequestInterceptor(SessionFactory sessionFactory, SessionHolder sessionHolder)

Deprecated

as a consequence of SessionFactory being deprecated. See corresponding docs for further information.

Method Detail

afterCompletionback to summary
public <T> void afterCompletion(NativeWebRequest request, Callable<T> task) throws Exception

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.afterCompletion.

Doc from org.springframework.web.context.request.async.CallableProcessingInterceptor.afterCompletion.

Invoked from a container thread when async processing completes for any reason including timeout or network error.

The default implementation is empty.

Parameters
request:NativeWebRequest

the current request

task:Callable<T>

the task for the current async request

Annotations
@Override
Exceptions
Exception:
in case of errors
afterCompletionback to summary
public <T> void afterCompletion(NativeWebRequest request, DeferredResult<T> deferredResult)

Overrides default org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.afterCompletion.

Doc from org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.afterCompletion.

Invoked from a container thread when an async request completed for any reason including timeout and network error. This method is useful for detecting that a DeferredResult instance is no longer usable.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request

Annotations
@Override
bindSessionback to summary
public void bindSession()
closeSessionback to summary
private void closeSession()
handleErrorback to summary
public <T> Object handleError(NativeWebRequest request, Callable<T> task, Throwable t)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.handleError.

Doc from org.springframework.web.context.request.async.CallableProcessingInterceptor.handleError.

Invoked from a container thread when an error occurred while processing the async request before the Callable task completes. Implementations may return a value, including an Exception, to use instead of the value the Callable did not return in time.

The default implementation always returns RESULT_NONE.

Parameters
request:NativeWebRequest

the current request

task:Callable<T>

the task for the current async request

t:Throwable

the error that occurred while request processing

Returns:Object

a concurrent result value; if the value is anything other than RESULT_NONE or RESPONSE_HANDLED, concurrent processing is resumed and subsequent interceptors are not invoked

Annotations
@Override
handleErrorback to summary
public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> deferredResult, Throwable t)

Overrides default org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.handleError.

Doc from org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.handleError.

Invoked from a container thread when an error occurred while processing an async request before the DeferredResult has been set. Implementations may invoke setResult or setErrorResult to resume processing.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked

t:Throwable

the error that occurred while request processing

Returns:boolean

true if error handling should continue, or false if other interceptors should be bypassed and not be invoked

Annotations
@Override
handleTimeoutback to summary
public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.handleTimeout.

Doc from org.springframework.web.context.request.async.CallableProcessingInterceptor.handleTimeout.

Invoked from a container thread when the async request times out before the Callable task completes. Implementations may return a value, including an Exception, to use instead of the value the Callable did not return in time.

The default implementation always returns RESULT_NONE.

Parameters
request:NativeWebRequest

the current request

task:Callable<T>

the task for the current async request

Returns:Object

a concurrent result value; if the value is anything other than RESULT_NONE or RESPONSE_HANDLED, concurrent processing is resumed and subsequent interceptors are not invoked

Annotations
@Override
handleTimeoutback to summary
public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult)

Overrides default org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.handleTimeout.

Doc from org.springframework.web.context.request.async.DeferredResultProcessingInterceptor.handleTimeout.

Invoked from a container thread when an async request times out before the DeferredResult has been set. Implementations may invoke setResult or setErrorResult to resume processing.

Parameters
request:NativeWebRequest

the current request

deferredResult:DeferredResult<T>

the DeferredResult for the current request; if the DeferredResult is set, then concurrent processing is resumed and subsequent interceptors are not invoked

Returns:boolean

true if processing should continue, or false if other interceptors should not be invoked

Annotations
@Override
postProcessback to summary
public <T> void postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.postProcess.

Doc from org.springframework.web.context.request.async.CallableProcessingInterceptor.postProcess.

Invoked after the Callable has produced a result in the async thread in which the Callable is executed. This method may be invoked later than afterTimeout or afterCompletion depending on when the Callable finishes processing.

The default implementation is empty.

Parameters
request:NativeWebRequest

the current request

task:Callable<T>

the task for the current async request

concurrentResult:Object

the result of concurrent processing, which could be a Throwable if the Callable raised an exception

Annotations
@Override
preProcessback to summary
public <T> void preProcess(NativeWebRequest request, Callable<T> task)

Overrides default org.springframework.web.context.request.async.CallableProcessingInterceptor.preProcess.

Doc from org.springframework.web.context.request.async.CallableProcessingInterceptor.preProcess.

Invoked after the start of concurrent handling in the async thread in which the Callable is executed and before the actual invocation of the Callable.

The default implementation is empty.

Parameters
request:NativeWebRequest

the current request

task:Callable<T>

the task for the current async request

Annotations
@Override