View Javadoc

1   package com.atlassian.sal.api.executor;
2   
3   import java.util.concurrent.Executor;
4   import java.util.concurrent.ExecutorService;
5   import java.util.concurrent.Callable;
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      /**
17       * Creates an executor that ensures the executed delegate instance runs in the same thread local context as the
18       * calling code.
19       *
20       * @param delegate The Executor instance to delegate to
21       * @return The wrapping executor that manages thread local state transfer
22       */
23      Executor createExecutor(Executor delegate);
24  
25      /**
26       * Creates an executor service that ensures the executed delegate instance runs in the same thread local context as
27       * the calling code.
28       *
29       * @param delegate The ExecutorService instance to delegate to
30       * @return The wrapping ExecutorService that manages thread local state transfer
31       */
32      ExecutorService createExecutorService(ExecutorService delegate);
33  
34      /**
35       * Creates a scheduled executor service that ensures the executed delegate instance runs in the same thread local
36       * context as the calling code.
37       *
38       * @param delegate The ScheduledExecutorService instance to delegate to
39       * @return The wrapping ScheduledExecutorService that manages thread local state transfer
40       */
41      ScheduledExecutorService createScheduledExecutorService(ScheduledExecutorService delegate);
42  
43      /**
44       * Creates a runnable that ensures the executed runnable instance runs in the same thread local context as the
45       * calling code
46       *
47       * @param delegate The runnable to delegate to
48       * @return The wrapping Runnable that manages thread local state transfer
49       */
50      Runnable createRunnable(Runnable delegate);
51  
52      /**
53       * Creates a callable that ensures the executed runnable instance runs in the same thread local context as the
54       * calling code.
55       *
56       * @param delegate The callable to delegate to
57       * @param <T>      The type that the callable returns
58       * @return The wrapping Callable that manages thread local state transfer
59       */
60      <T> Callable<T> createCallable(Callable<T> delegate);
61  }