org.springframework.orm.hibernate4.support

## Class AsyncRequestInterceptor

- java.lang.Object
- - org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter
  - - org.springframework.orm.hibernate4.support.AsyncRequestInterceptor

- All Implemented Interfaces:
    CallableProcessingInterceptor, DeferredResultProcessingInterceptor

      public class AsyncRequestInterceptor
      extends CallableProcessingInterceptorAdapter
      implements 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
  Since:
    3.2.5
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from interface org.springframework.web.context.request.async.CallableProcessingInterceptor

      `RESPONSE_HANDLED, RESULT_NONE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AsyncRequestInterceptor(SessionFactory sessionFactory, SessionHolder sessionHolder)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> void` | `afterCompletion(NativeWebRequest request, Callable<T> task)` This implementation is empty.
    `<T> void` | `afterCompletion(NativeWebRequest request, DeferredResult<T> deferredResult)` Invoked from a container thread when an async request completed for any reason including timeout and network error.
    `<T> void` | `beforeConcurrentHandling(NativeWebRequest request, DeferredResult<T> deferredResult)` Invoked immediately before the start of concurrent handling, in the same thread that started it.
    `void` | `bindSession()`
    `<T> Object` | `handleTimeout(NativeWebRequest request, Callable<T> task)` This implementation always returns `RESULT_NONE`.
    `<T> boolean` | `handleTimeout(NativeWebRequest request, DeferredResult<T> deferredResult)` Invoked from a container thread when an async request times out before the `DeferredResult` has been set.
    `<T> void` | `postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult)` This implementation is empty.
    `<T> void` | `postProcess(NativeWebRequest request, DeferredResult<T> deferredResult, Object result)` Invoked after a `DeferredResult` has been set, via `DeferredResult.setResult(Object)` or `DeferredResult.setErrorResult(Object)`, and is also ready to handle the concurrent result.
    `<T> void` | `preProcess(NativeWebRequest request, Callable<T> task)` This implementation is empty.
    `<T> void` | `preProcess(NativeWebRequest request, DeferredResult<T> deferredResult)` Invoked immediately after the start of concurrent handling, in the same thread that started it.

    - ### Methods inherited from class org.springframework.web.context.request.async.CallableProcessingInterceptorAdapter

      `beforeConcurrentHandling`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AsyncRequestInterceptor

          public AsyncRequestInterceptor(SessionFactory sessionFactory,
                                 SessionHolder sessionHolder)

  - ### Method Detail

    - #### preProcess

          public <T> void preProcess(NativeWebRequest request,
                            Callable<T> task)

      Description copied from class: `CallableProcessingInterceptorAdapter`
      This implementation is empty.
      Specified by:
        `preProcess` in interface `CallableProcessingInterceptor`
      Overrides:
        `preProcess` in class `CallableProcessingInterceptorAdapter`
      Parameters:
        `request` - the current request
        `task` - the task for the current async request

    - #### bindSession

          public void bindSession()

    - #### postProcess

          public <T> void postProcess(NativeWebRequest request,
                             Callable<T> task,
                             Object concurrentResult)

      Description copied from class: `CallableProcessingInterceptorAdapter`
      This implementation is empty.
      Specified by:
        `postProcess` in interface `CallableProcessingInterceptor`
      Overrides:
        `postProcess` in class `CallableProcessingInterceptorAdapter`
      Parameters:
        `request` - the current request
        `task` - the task for the current async request
        `concurrentResult` - the result of concurrent processing, which could be a `Throwable` if the `Callable` raised an exception

    - #### handleTimeout

          public <T> Object handleTimeout(NativeWebRequest request,
                                 Callable<T> task)

      Description copied from class: `CallableProcessingInterceptorAdapter`
      This implementation always returns `RESULT_NONE`.
      Specified by:
        `handleTimeout` in interface `CallableProcessingInterceptor`
      Overrides:
        `handleTimeout` in class `CallableProcessingInterceptorAdapter`
      Parameters:
        `request` - the current request
        `task` - the task for the current async request
      Returns:
        a concurrent result value; if the value is anything other than `CallableProcessingInterceptor.RESULT_NONE` or `CallableProcessingInterceptor.RESPONSE_HANDLED`, concurrent processing is resumed and subsequent interceptors are not invoked

    - #### afterCompletion

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

      Description copied from class: `CallableProcessingInterceptorAdapter`
      This implementation is empty.
      Specified by:
        `afterCompletion` in interface `CallableProcessingInterceptor`
      Overrides:
        `afterCompletion` in class `CallableProcessingInterceptorAdapter`
      Parameters:
        `request` - the current request
        `task` - the task for the current async request
      Throws:
        `Exception` - in case of errors

    - #### beforeConcurrentHandling

          public <T> void beforeConcurrentHandling(NativeWebRequest request,
                                          DeferredResult<T> deferredResult)

      Description copied from interface: `DeferredResultProcessingInterceptor`
      Invoked immediately before the start of concurrent handling, in the same thread that started it. This method may be used to capture state just prior to the start of concurrent processing with the given `DeferredResult`.
      Specified by:
        `beforeConcurrentHandling` in interface `DeferredResultProcessingInterceptor`
      Parameters:
        `request` - the current request
        `deferredResult` - the DeferredResult for the current request

    - #### preProcess

          public <T> void preProcess(NativeWebRequest request,
                            DeferredResult<T> deferredResult)

      Description copied from interface: `DeferredResultProcessingInterceptor`
      Invoked immediately after the start of concurrent handling, in the same thread that started it. This method may be used to detect the start of concurrent processing with the given `DeferredResult`.

      The `DeferredResult` may have already been set, for example at the time of its creation or by another thread.

      Specified by:
        `preProcess` in interface `DeferredResultProcessingInterceptor`
      Parameters:
        `request` - the current request
        `deferredResult` - the DeferredResult for the current request

    - #### postProcess

          public <T> void postProcess(NativeWebRequest request,
                             DeferredResult<T> deferredResult,
                             Object result)

      Description copied from interface: `DeferredResultProcessingInterceptor`
      Invoked after a `DeferredResult` has been set, via `DeferredResult.setResult(Object)` or `DeferredResult.setErrorResult(Object)`, and is also ready to handle the concurrent result.

      This method may also be invoked after a timeout when the `DeferredResult` was created with a constructor accepting a default timeout result.

      Specified by:
        `postProcess` in interface `DeferredResultProcessingInterceptor`
      Parameters:
        `request` - the current request
        `deferredResult` - the DeferredResult for the current request
        `result` - the result to which the `DeferredResult`

    - #### handleTimeout

          public <T> boolean handleTimeout(NativeWebRequest request,
                                  DeferredResult<T> deferredResult)

      Description copied from interface: `DeferredResultProcessingInterceptor`
      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.
      Specified by:
        `handleTimeout` in interface `DeferredResultProcessingInterceptor`
      Parameters:
        `request` - the current request
        `deferredResult` - the DeferredResult for the current request; if the `DeferredResult` is set, then concurrent processing is resumed and subsequent interceptors are not invoked
      Returns:
        `true` if processing should continue, or `false` if other interceptors should not be invoked

    - #### afterCompletion

          public <T> void afterCompletion(NativeWebRequest request,
                                 DeferredResult<T> deferredResult)

      Description copied from interface: `DeferredResultProcessingInterceptor`
      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.
      Specified by:
        `afterCompletion` in interface `DeferredResultProcessingInterceptor`
      Parameters:
        `request` - the current request
        `deferredResult` - the DeferredResult for the current request