1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.pool; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.MuleRuntimeException; |
15 | |
import org.mule.api.config.ThreadingProfile; |
16 | |
import org.mule.api.context.MuleContextAware; |
17 | |
import org.mule.config.i18n.MessageFactory; |
18 | |
import org.mule.util.ClassUtils; |
19 | |
|
20 | |
import java.util.Iterator; |
21 | |
|
22 | |
import javax.imageio.spi.ServiceRegistry; |
23 | |
|
24 | |
import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor; |
25 | |
|
26 | |
import org.apache.commons.logging.Log; |
27 | |
import org.apache.commons.logging.LogFactory; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 0 | public abstract class ThreadPoolFactory implements MuleContextAware |
35 | |
{ |
36 | |
|
37 | 0 | private static final Log logger = LogFactory.getLog(ThreadPoolFactory.class); |
38 | |
|
39 | |
private static final String PREFERRED_CONFIG_CLASSNAME = "com.mulesoft.mule.config.Preferred"; |
40 | 0 | private static boolean extensionsAvailable = ClassUtils.isClassOnPath(PREFERRED_CONFIG_CLASSNAME, ThreadPoolFactory.class); |
41 | |
|
42 | |
protected MuleContext muleContext; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public static ThreadPoolFactory newInstance() |
48 | |
{ |
49 | 0 | Class preferredMarker = null; |
50 | 0 | if (extensionsAvailable) |
51 | |
{ |
52 | |
try |
53 | |
{ |
54 | 0 | preferredMarker = ClassUtils.loadClass(PREFERRED_CONFIG_CLASSNAME, ThreadPoolFactory.class); |
55 | |
} |
56 | 0 | catch (ClassNotFoundException e) |
57 | |
{ |
58 | 0 | extensionsAvailable = false; |
59 | 0 | if (logger.isDebugEnabled()) |
60 | |
{ |
61 | 0 | logger.debug("Failed to load EE extensions", e); |
62 | |
} |
63 | 0 | } |
64 | |
|
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | 0 | final Iterator<ThreadPoolFactory> it = ServiceRegistry.lookupProviders(ThreadPoolFactory.class); |
78 | 0 | ThreadPoolFactory candidate = null; |
79 | 0 | while (it.hasNext()) |
80 | |
{ |
81 | 0 | ThreadPoolFactory threadPoolFactory = it.next(); |
82 | |
|
83 | 0 | if (extensionsAvailable && preferredMarker.isAssignableFrom(threadPoolFactory.getClass())) |
84 | |
{ |
85 | 0 | return threadPoolFactory; |
86 | |
} |
87 | |
else |
88 | |
{ |
89 | |
|
90 | |
|
91 | 0 | if (candidate == null) |
92 | |
{ |
93 | 0 | candidate = threadPoolFactory; |
94 | |
} |
95 | |
} |
96 | 0 | } |
97 | |
|
98 | 0 | if (candidate != null) |
99 | |
{ |
100 | 0 | return candidate; |
101 | |
} |
102 | |
|
103 | 0 | throw new MuleRuntimeException(MessageFactory.createStaticMessage( |
104 | |
"Couldn't find config via SPI mechanism. Corrupted Mule core jar?" |
105 | |
)); |
106 | |
} |
107 | |
|
108 | |
public void setMuleContext(MuleContext context) |
109 | |
{ |
110 | 0 | this.muleContext = context; |
111 | 0 | } |
112 | |
|
113 | |
public abstract ThreadPoolExecutor createPool(String name, ThreadingProfile tp); |
114 | |
} |