public abstract class RequestScopePropagator extends Object
Request scopes are typically linked to a ThreadLocal
, which is only
available to the current thread. In order to allow background work involving
RequestScoped data, the ThreadLocal data must be copied from the request thread to
the new background thread.
Every type of RequestScope must provide an implementation of
RequestScopePropagator. See wrap(Callable)
for details on the
implementation, usage, and restrictions.
ThreadLocalRequestScopePropagator
Modifier | Constructor and Description |
---|---|
protected |
RequestScopePropagator(com.google.inject.Scope scope,
ThreadLocalRequestContext local,
com.google.inject.Provider<RequestScopedReviewDbProvider> dbProviderProvider) |
Modifier and Type | Method and Description |
---|---|
protected <T> Callable<T> |
cleanup(Callable<T> callable) |
protected <T> Callable<T> |
context(RequestContext context,
Callable<T> callable) |
<T> Callable<T> |
wrap(Callable<T> callable)
Ensures that the current request state is available when the passed in
Callable is invoked.
|
Runnable |
wrap(Runnable runnable)
Wraps runnable in a new
Runnable that propagates the current
request state when the runnable is invoked. |
protected abstract <T> Callable<T> |
wrapImpl(Callable<T> callable) |
protected RequestScopePropagator(com.google.inject.Scope scope, ThreadLocalRequestContext local, com.google.inject.Provider<RequestScopedReviewDbProvider> dbProviderProvider)
public final <T> Callable<T> wrap(Callable<T> callable)
Callable
that
propagates the current request state when the returned Callable is invoked.
The method must be called in a request scope and the returned Callable may
only be invoked in a thread that is not already in a request scope or is in
the same request scope. The returned Callable will inherit toString() from
the passed in Callable. A
WorkQueue.Executor
does not accept a
Callable, so there is no ProjectCallable implementation. Implementations of
this method must be consistent with Guice's
ServletScopes.continueRequest(Callable, java.util.Map)
.
There are some limitations:
callable
- the Callable to wrap.public final Runnable wrap(Runnable runnable)
Runnable
that propagates the current
request state when the runnable is invoked. The method must be called in a
request scope and the returned Runnable may only be invoked in a thread
that is not already in a request scope. The returned Runnable will inherit
toString() from the passed in Runnable. Furthermore, if the passed runnable
is of type ProjectRunnable
, the returned runnable will be of the
same type with the methods delegated.
See wrap(Callable)
for details on implementation and usage.runnable
- the Runnable to wrap.protected abstract <T> Callable<T> wrapImpl(Callable<T> callable)
wrap(Callable)
protected <T> Callable<T> context(RequestContext context, Callable<T> callable)