1 package com.atlassian.sal.core.executor;
2
3 import com.atlassian.sal.api.executor.ThreadLocalDelegateExecutorFactory;
4
5 import java.util.concurrent.Executor;
6
7 import static com.google.common.base.Preconditions.checkNotNull;
8
9
10
11
12 class ThreadLocalDelegateExecutor implements Executor {
13 private final Executor delegate;
14 private final ThreadLocalDelegateExecutorFactory delegateExecutorFactory;
15
16 ThreadLocalDelegateExecutor(Executor delegate, ThreadLocalDelegateExecutorFactory delegateExecutorFactory) {
17 this.delegateExecutorFactory = checkNotNull(delegateExecutorFactory);
18 this.delegate = checkNotNull(delegate);
19 }
20
21 @Override
22 public void execute(Runnable runnable) {
23 final Runnable wrapper = delegateExecutorFactory.createRunnable(runnable);
24 delegate.execute(wrapper);
25 }
26 }