public class

ServletScopes

extends Object
java.lang.Object
   ↳ com.google.inject.servlet.ServletScopes

Class Overview

Servlet scopes.

Summary

Constants
Scope REQUEST HTTP servlet request scope.
Scope SESSION HTTP session scope.
Public Methods
static <T> Callable<T> continueRequest(Callable<T> callable, Map<Key<?>, Object> seedMap)
Wraps the given callable in a contextual callable that "continues" the HTTP request in another thread.
static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap)
Scopes the given callable inside a request scope.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final Scope REQUEST

HTTP servlet request scope.

public static final Scope SESSION

HTTP session scope.

Public Methods

public static Callable<T> continueRequest (Callable<T> callable, Map<Key<?>, Object> seedMap)

Wraps the given callable in a contextual callable that "continues" the HTTP request in another thread. This acts as a way of transporting request context data from the request processing thread to to worker threads.

There are some limitations:

  • Derived objects (i.e. anything marked @RequestScoped will not be transported.
  • State changes to the HttpServletRequest after this method is called will not be seen in the continued thread.
  • Only the HttpServletRequest, ServletContext and request parameter map are available in the continued thread. The response and session are not available.

Parameters
callable code to be executed in another thread, which depends on the request scope.
seedMap the initial set of scoped instances for Guice to seed the request scope with. To seed a key with null, use null as the value.
Returns
  • a callable that will invoke the given callable, making the request context available to it.
Throws
OutOfScopeException if this method is called from a non-request thread, or if the request has completed.

public static Callable<T> scopeRequest (Callable<T> callable, Map<Key<?>, Object> seedMap)

Scopes the given callable inside a request scope. This is not the same as the HTTP request scope, but is used if no HTTP request scope is in progress. In this way, keys can be scoped as @RequestScoped and exist in non-HTTP requests (for example: RPC requests) as well as in HTTP request threads.

Parameters
callable code to be executed which depends on the request scope. Typically in another thread, but not necessarily so.
seedMap the initial set of scoped instances for Guice to seed the request scope with. To seed a key with null, use null as the value.
Returns
  • a callable that when called will run inside the a request scope that exposes the instances in the seedMap as scoped keys.