com.google.inject.servlet
Class ServletScopes

java.lang.Object
  extended by com.google.inject.servlet.ServletScopes

public class ServletScopes
extends Object

Servlet scopes.

Author:
crazybob@google.com (Bob Lee)

Field Summary
static Scope REQUEST
          HTTP servlet request scope.
static Scope SESSION
          HTTP session scope.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUEST

public static final Scope REQUEST
HTTP servlet request scope.


SESSION

public static final Scope SESSION
HTTP session scope.

Method Detail

continueRequest

public 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. This acts as a way of transporting request context data from the request processing thread to to worker threads.

There are some limitations:

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.
Since:
3.0

scopeRequest

public static <T> 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.
Since:
3.0


Copyright © 2006-2011 Google, Inc.. All Rights Reserved.