/** * 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. * * <p>The returned callable will throw a {@link ScopingException} when called if there is a * request scope already active on the current thread. * * @param callable code to be executed which depends on the request scope. Typically in another * thread, but not necessarily so. * @param seedMap the initial set of scoped instances for Guice to seed the request scope with. To * seed a key with null, use {@code null} as the value. * @return a callable that when called will run inside the a request scope that exposes the * instances in the {@code seedMap} as scoped keys. * @since 3.0 */ public static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap) { return wrap(callable, scopeRequest(seedMap)); }
/** * Wraps the given callable in a contextual callable that "transfers" the request to another * thread. This acts as a way of transporting request context data from the current thread to a * future thread. * * <p>As opposed to {@link #continueRequest}, this method propagates all existing scoped objects. * The primary use case is in server implementations where you can detach the request processing * thread while waiting for data, and reattach to a different thread to finish processing at a * later time. * * <p>Because request-scoped objects are not typically thread-safe, the callable returned by this * method must not be run on a different thread until the current request scope has terminated. * The returned callable will block until the current thread has released the request scope. * * @param callable code to be executed in another thread, which depends on the request scope. * @return 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 4.0 */ public static <T> Callable<T> transferRequest(Callable<T> callable) { return wrap(callable, transferRequest()); }
return wrap(callable, continueRequest(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. * * <p>The returned callable will throw a {@link ScopingException} when called if there is a * request scope already active on the current thread. * * @param callable code to be executed which depends on the request scope. Typically in another * thread, but not necessarily so. * @param seedMap the initial set of scoped instances for Guice to seed the request scope with. To * seed a key with null, use {@code null} as the value. * @return a callable that when called will run inside the a request scope that exposes the * instances in the {@code seedMap} as scoped keys. * @since 3.0 */ public static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap) { return wrap(callable, scopeRequest(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. * * <p>The returned callable will throw a {@link ScopingException} when called if there is a * request scope already active on the current thread. * * @param callable code to be executed which depends on the request scope. Typically in another * thread, but not necessarily so. * @param seedMap the initial set of scoped instances for Guice to seed the request scope with. To * seed a key with null, use {@code null} as the value. * @return a callable that when called will run inside the a request scope that exposes the * instances in the {@code seedMap} as scoped keys. * @since 3.0 */ public static <T> Callable<T> scopeRequest(Callable<T> callable, Map<Key<?>, Object> seedMap) { return wrap(callable, scopeRequest(seedMap)); }
/** * Wraps the given callable in a contextual callable that "transfers" the request to another * thread. This acts as a way of transporting request context data from the current thread to a * future thread. * * <p>As opposed to {@link #continueRequest}, this method propagates all existing scoped objects. * The primary use case is in server implementations where you can detach the request processing * thread while waiting for data, and reattach to a different thread to finish processing at a * later time. * * <p>Because request-scoped objects are not typically thread-safe, the callable returned by this * method must not be run on a different thread until the current request scope has terminated. * The returned callable will block until the current thread has released the request scope. * * @param callable code to be executed in another thread, which depends on the request scope. * @return 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 4.0 */ public static <T> Callable<T> transferRequest(Callable<T> callable) { return wrap(callable, transferRequest()); }
/** * Wraps the given callable in a contextual callable that "transfers" the request to another * thread. This acts as a way of transporting request context data from the current thread to a * future thread. * * <p>As opposed to {@link #continueRequest}, this method propagates all existing scoped objects. * The primary use case is in server implementations where you can detach the request processing * thread while waiting for data, and reattach to a different thread to finish processing at a * later time. * * <p>Because request-scoped objects are not typically thread-safe, the callable returned by this * method must not be run on a different thread until the current request scope has terminated. * The returned callable will block until the current thread has released the request scope. * * @param callable code to be executed in another thread, which depends on the request scope. * @return 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 4.0 */ public static <T> Callable<T> transferRequest(Callable<T> callable) { return wrap(callable, transferRequest()); }
return wrap(callable, continueRequest(seedMap));
return wrap(callable, continueRequest(seedMap));