1 package com.atlassian.event.internal;
2
3 import com.atlassian.event.config.EventThreadPoolConfiguration;
4 import com.atlassian.event.spi.EventExecutorFactory;
5
6 import java.util.concurrent.BlockingQueue;
7 import java.util.concurrent.Executor;
8 import java.util.concurrent.ThreadPoolExecutor;
9
10 import static com.google.common.base.Preconditions.checkNotNull;
11
12
13
14
15
16
17 public abstract class AbstractEventExecutorFactory implements EventExecutorFactory {
18 private final EventThreadPoolConfiguration configuration;
19 private final EventThreadFactory eventThreadFactory;
20
21
22
23
24
25
26 public AbstractEventExecutorFactory(EventThreadPoolConfiguration configuration, EventThreadFactory eventThreadFactory) {
27 this.configuration = checkNotNull(configuration);
28 this.eventThreadFactory = checkNotNull(eventThreadFactory);
29 }
30
31 public AbstractEventExecutorFactory(EventThreadPoolConfiguration configuration) {
32 this(configuration, new EventThreadFactory());
33 }
34
35
36
37
38 protected abstract BlockingQueue<Runnable> getQueue();
39
40 public Executor getExecutor() {
41 return new ThreadPoolExecutor(
42 configuration.getCorePoolSize(),
43 configuration.getMaximumPoolSize(),
44 configuration.getKeepAliveTime(),
45 configuration.getTimeUnit(),
46 getQueue(),
47 eventThreadFactory);
48 }
49 }