1 package com.atlassian.sal.api.executor;
2
3 import java.util.concurrent.Callable;
4 import java.util.concurrent.Executor;
5 import java.util.concurrent.ExecutorService;
6 import java.util.concurrent.ScheduledExecutorService;
7
8 /**
9 * Factory to create {@link Executor} instances that delegate to a specific Executor and ensure the executed code runs
10 * in the same thread local context.
11 *
12 * @since 2.0
13 */
14 public interface ThreadLocalDelegateExecutorFactory {
15 /**
16 * Creates an executor that ensures the executed delegate instance runs in the same thread local context as the
17 * calling code.
18 *
19 * @param delegate The Executor instance to delegate to
20 * @return The wrapping executor that manages thread local state transfer
21 */
22 Executor createExecutor(Executor delegate);
23
24 /**
25 * Creates an executor service that ensures the executed delegate instance runs in the same thread local context as
26 * the calling code.
27 *
28 * @param delegate The ExecutorService instance to delegate to
29 * @return The wrapping ExecutorService that manages thread local state transfer
30 */
31 ExecutorService createExecutorService(ExecutorService delegate);
32
33 /**
34 * Creates a scheduled executor service that ensures the executed delegate instance runs in the same thread local
35 * context as the calling code.
36 *
37 * @param delegate The ScheduledExecutorService instance to delegate to
38 * @return The wrapping ScheduledExecutorService that manages thread local state transfer
39 */
40 ScheduledExecutorService createScheduledExecutorService(ScheduledExecutorService delegate);
41
42 /**
43 * Creates a runnable that ensures the executed runnable instance runs in the same thread local context as the
44 * calling code
45 *
46 * @param delegate The runnable to delegate to
47 * @return The wrapping Runnable that manages thread local state transfer
48 */
49 Runnable createRunnable(Runnable delegate);
50
51 /**
52 * Creates a callable that ensures the executed runnable instance runs in the same thread local context as the
53 * calling code.
54 *
55 * @param delegate The callable to delegate to
56 * @param <T> The type that the callable returns
57 * @return The wrapping Callable that manages thread local state transfer
58 */
59 <T> Callable<T> createCallable(Callable<T> delegate);
60 }