public abstract class RequestScopePropagator
extends java.lang.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> java.util.concurrent.Callable<T> |
cleanup(java.util.concurrent.Callable<T> callable) |
protected <T> java.util.concurrent.Callable<T> |
context(RequestContext context,
java.util.concurrent.Callable<T> callable) |
<T> java.util.concurrent.Callable<T> |
wrap(java.util.concurrent.Callable<T> callable)
Ensures that the current request state is available when the passed in Callable is invoked.
|
java.lang.Runnable |
wrap(java.lang.Runnable runnable)
Wraps runnable in a new
Runnable that propagates the current request state when the
runnable is invoked. |
protected abstract <T> java.util.concurrent.Callable<T> |
wrapImpl(java.util.concurrent.Callable<T> callable) |
protected RequestScopePropagator(com.google.inject.Scope scope, ThreadLocalRequestContext local, com.google.inject.Provider<RequestScopedReviewDbProvider> dbProviderProvider)
public final <T> java.util.concurrent.Callable<T> wrap(java.util.concurrent.Callable<T> callable)
If needed wraps the passed in Callable in a new 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 ScheduledThreadPoolExecutor
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 java.lang.Runnable wrap(java.lang.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> java.util.concurrent.Callable<T> wrapImpl(java.util.concurrent.Callable<T> callable)
wrap(Callable)
protected <T> java.util.concurrent.Callable<T> context(RequestContext context, java.util.concurrent.Callable<T> callable)
protected <T> java.util.concurrent.Callable<T> cleanup(java.util.concurrent.Callable<T> callable)