1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.pool; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleRuntimeException; |
11 | |
import org.mule.api.config.ThreadingProfile; |
12 | |
import org.mule.api.context.MuleContextAware; |
13 | |
import org.mule.config.PreferredObjectSelector; |
14 | |
import org.mule.config.i18n.MessageFactory; |
15 | |
|
16 | |
import java.util.Iterator; |
17 | |
|
18 | |
import javax.imageio.spi.ServiceRegistry; |
19 | |
|
20 | |
import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public abstract class ThreadPoolFactory implements MuleContextAware |
28 | |
{ |
29 | |
|
30 | |
protected MuleContext muleContext; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public static ThreadPoolFactory newInstance() |
36 | |
{ |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | final Iterator<ThreadPoolFactory> servicesIterator = ServiceRegistry.lookupProviders(ThreadPoolFactory.class); |
48 | |
|
49 | 0 | PreferredObjectSelector<ThreadPoolFactory> selector = new PreferredObjectSelector<ThreadPoolFactory>(); |
50 | 0 | ThreadPoolFactory threadPoolFactory = selector.select(servicesIterator); |
51 | |
|
52 | 0 | if (threadPoolFactory == null) |
53 | |
{ |
54 | 0 | throw new MuleRuntimeException(MessageFactory.createStaticMessage( |
55 | |
"Couldn't find config via SPI mechanism. Corrupted Mule core jar?" |
56 | |
)); |
57 | |
} |
58 | |
|
59 | 0 | return threadPoolFactory; |
60 | |
} |
61 | |
|
62 | |
public void setMuleContext(MuleContext context) |
63 | |
{ |
64 | 0 | this.muleContext = context; |
65 | 0 | } |
66 | |
|
67 | |
public abstract ThreadPoolExecutor createPool(String name, ThreadingProfile tp); |
68 | |
} |