Skip to content

Simplify DefaultScopedContextProvider #2450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static <R> R callWhere(final Map<String, ?> map, final Callable<R> task)
* @param key the key.
* @return the value of the key or null.
*/
public static Object get(String key) {
public static Object get(final String key) {
return provider.getValue(key);
}

Expand All @@ -161,7 +161,7 @@ public static Object get(String key) {
* @param key The key.
* @return The value of the key in the current ScopedContext.
*/
public static String getString(String key) {
public static String getString(final String key) {
return provider.getString(key);
}

Expand Down Expand Up @@ -193,31 +193,39 @@ public interface Instance {
*
* @param task the code block to execute.
*/
void run(Runnable task);
default void run(final Runnable task) {
wrap(task).run();
}

/**
* Executes a code block that includes all the key/value pairs added to the ScopedContext on a different Thread.
*
* @param task the code block to execute.
* @return a Future representing pending completion of the task
*/
Future<Void> run(ExecutorService executorService, Runnable task);
default Future<Void> run(final ExecutorService executorService, final Runnable task) {
return executorService.submit(wrap(task), null);
}

/**
* Executes a code block that includes all the key/value pairs added to the ScopedContext.
*
* @param task the code block to execute.
* @return the return value from the code block.
*/
<R> R call(Callable<R> task) throws Exception;
default <R> R call(final Callable<? extends R> task) throws Exception {
return wrap(task).call();
}

/**
* Executes a code block that includes all the key/value pairs added to the ScopedContext on a different Thread.
*
* @param task the code block to execute.
* @return a Future representing pending completion of the task
*/
<R> Future<R> call(ExecutorService executorService, Callable<R> task);
default <R> Future<R> call(final ExecutorService executorService, final Callable<? extends R> task) {
return executorService.submit(wrap(task));
}

/**
* Wraps the provided Runnable method with a Runnable method that will instantiate the Scoped and Thread
Expand All @@ -233,6 +241,6 @@ public interface Instance {
* @param task the Callable task to perform.
* @return a Callable.
*/
<R> Callable<R> wrap(Callable<R> task);
<R> Callable<R> wrap(Callable<? extends R> task);
}
}
Loading