mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
43 lines
1.0 KiB
Java
43 lines
1.0 KiB
Java
package io.ebean.config;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
/**
|
|
* BackgroundExecutorWrapper that can be used to wrap tasks that are sent to background (i.e. another thread).
|
|
* It should copy all necessary thread-local variables. See {@link MdcBackgroundExecutorWrapper} for implementation details.
|
|
*
|
|
* @author Roland Praml, FOCONIS AG
|
|
*/
|
|
public interface BackgroundExecutorWrapper {
|
|
|
|
/**
|
|
* Wrap the task with MDC context if defined.
|
|
*/
|
|
<T> Callable<T> wrap(Callable<T> task);
|
|
|
|
/**
|
|
* Wrap the task with MDC context if defined.
|
|
*/
|
|
Runnable wrap(Runnable task);
|
|
|
|
/**
|
|
* Combines two wrappers by nesting them.
|
|
*/
|
|
default BackgroundExecutorWrapper with(BackgroundExecutorWrapper inner) {
|
|
return new BackgroundExecutorWrapper() {
|
|
|
|
@Override
|
|
public Runnable wrap(Runnable task) {
|
|
return BackgroundExecutorWrapper.this.wrap(inner.wrap(task));
|
|
}
|
|
|
|
@Override
|
|
public <T> Callable<T> wrap(Callable<T> task) {
|
|
return BackgroundExecutorWrapper.this.wrap(inner.wrap(task));
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
}
|