1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config; |
12 | |
|
13 | |
import org.mule.api.config.ThreadingProfile; |
14 | |
import org.mule.api.context.WorkManager; |
15 | |
|
16 | |
import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionHandler; |
17 | |
import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory; |
18 | |
import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class ChainedThreadingProfile implements ThreadingProfile |
37 | |
{ |
38 | |
|
39 | |
private Integer maxThreadsActive; |
40 | |
private Integer maxThreadsIdle; |
41 | |
private Integer maxBufferSize; |
42 | |
private Long threadTTL; |
43 | |
private Long threadWaitTimeout; |
44 | |
private Integer poolExhaustedAction; |
45 | |
private Boolean doThreading; |
46 | |
|
47 | 5730 | private WorkManagerFactory workManagerFactory = new ImmutableThreadingProfile.DefaultWorkManagerFactory(); |
48 | |
private RejectedExecutionHandler rejectedExecutionHandler; |
49 | |
private ThreadFactory threadFactory; |
50 | |
|
51 | |
private ThreadingProfile delegate; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public ChainedThreadingProfile() |
58 | |
{ |
59 | |
|
60 | 1146 | this(DEFAULT_THREADING_PROFILE); |
61 | 1146 | } |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public ChainedThreadingProfile(ThreadingProfile delegate) |
70 | |
{ |
71 | 5730 | this(delegate, true); |
72 | 5730 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public ChainedThreadingProfile(ThreadingProfile delegate, boolean dynamic) |
83 | 5730 | { |
84 | 5730 | if (!dynamic) |
85 | |
{ |
86 | |
|
87 | 0 | delegate = new ImmutableThreadingProfile(delegate); |
88 | |
} |
89 | 5730 | this.delegate = delegate; |
90 | 5730 | } |
91 | |
|
92 | |
public int getMaxThreadsActive() |
93 | |
{ |
94 | 5556 | return null != maxThreadsActive ? maxThreadsActive.intValue() : delegate.getMaxThreadsActive(); |
95 | |
} |
96 | |
|
97 | |
public int getMaxThreadsIdle() |
98 | |
{ |
99 | 1916 | return null != maxThreadsIdle ? maxThreadsIdle.intValue() : delegate.getMaxThreadsIdle(); |
100 | |
} |
101 | |
|
102 | |
public long getThreadTTL() |
103 | |
{ |
104 | 1924 | return null != threadTTL ? threadTTL.longValue() : delegate.getThreadTTL(); |
105 | |
} |
106 | |
|
107 | |
public long getThreadWaitTimeout() |
108 | |
{ |
109 | 0 | return null != threadWaitTimeout ? threadWaitTimeout.longValue() : delegate.getThreadWaitTimeout(); |
110 | |
} |
111 | |
|
112 | |
public int getPoolExhaustedAction() |
113 | |
{ |
114 | 1916 | return null != poolExhaustedAction ? poolExhaustedAction.intValue() : delegate.getPoolExhaustedAction(); |
115 | |
} |
116 | |
|
117 | |
public RejectedExecutionHandler getRejectedExecutionHandler() |
118 | |
{ |
119 | 958 | return rejectedExecutionHandler; |
120 | |
} |
121 | |
|
122 | |
public ThreadFactory getThreadFactory() |
123 | |
{ |
124 | 958 | return threadFactory; |
125 | |
} |
126 | |
|
127 | |
public void setMaxThreadsActive(int maxThreadsActive) |
128 | |
{ |
129 | 1146 | this.maxThreadsActive = new Integer(maxThreadsActive); |
130 | 1146 | } |
131 | |
|
132 | |
public void setMaxThreadsIdle(int maxThreadsIdle) |
133 | |
{ |
134 | 1146 | this.maxThreadsIdle = new Integer(maxThreadsIdle); |
135 | 1146 | } |
136 | |
|
137 | |
public void setThreadTTL(long threadTTL) |
138 | |
{ |
139 | 1146 | this.threadTTL = new Long(threadTTL); |
140 | 1146 | } |
141 | |
|
142 | |
public void setThreadWaitTimeout(long threadWaitTimeout) |
143 | |
{ |
144 | 1146 | this.threadWaitTimeout = new Long(threadWaitTimeout); |
145 | 1146 | } |
146 | |
|
147 | |
public void setPoolExhaustedAction(int poolExhaustPolicy) |
148 | |
{ |
149 | 1146 | this.poolExhaustedAction = new Integer(poolExhaustPolicy); |
150 | 1146 | } |
151 | |
|
152 | |
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) |
153 | |
{ |
154 | 0 | this.rejectedExecutionHandler = rejectedExecutionHandler; |
155 | 0 | } |
156 | |
|
157 | |
public void setThreadFactory(ThreadFactory threadFactory) |
158 | |
{ |
159 | 0 | this.threadFactory = threadFactory; |
160 | 0 | } |
161 | |
|
162 | |
public int getMaxBufferSize() |
163 | |
{ |
164 | 1916 | return null != maxBufferSize ? maxBufferSize.intValue() : delegate.getMaxBufferSize(); |
165 | |
} |
166 | |
|
167 | |
public void setMaxBufferSize(int maxBufferSize) |
168 | |
{ |
169 | 1146 | this.maxBufferSize = new Integer(maxBufferSize); |
170 | 1146 | } |
171 | |
|
172 | |
public WorkManagerFactory getWorkManagerFactory() |
173 | |
{ |
174 | 0 | return workManagerFactory; |
175 | |
} |
176 | |
|
177 | |
public void setWorkManagerFactory(WorkManagerFactory workManagerFactory) |
178 | |
{ |
179 | 0 | this.workManagerFactory = workManagerFactory; |
180 | 0 | } |
181 | |
|
182 | |
public WorkManager createWorkManager(String name) |
183 | |
{ |
184 | 1334 | return workManagerFactory.createWorkManager(this, name); |
185 | |
} |
186 | |
|
187 | |
public ThreadPoolExecutor createPool() |
188 | |
{ |
189 | 0 | return createPool(null); |
190 | |
} |
191 | |
|
192 | |
public ThreadPoolExecutor createPool(String name) |
193 | |
{ |
194 | 958 | return ImmutableThreadingProfile.createPool(name, this); |
195 | |
} |
196 | |
|
197 | |
public boolean isDoThreading() |
198 | |
{ |
199 | 4 | return null != doThreading ? doThreading.booleanValue() : delegate.isDoThreading(); |
200 | |
} |
201 | |
|
202 | |
public void setDoThreading(boolean doThreading) |
203 | |
{ |
204 | 0 | this.doThreading = Boolean.valueOf(doThreading); |
205 | 0 | } |
206 | |
|
207 | |
public String toString() |
208 | |
{ |
209 | 11460 | return "ThreadingProfile{" + "maxThreadsActive=" + maxThreadsActive + ", maxThreadsIdle=" |
210 | |
+ maxThreadsIdle + ", maxBufferSize=" + maxBufferSize + ", threadTTL=" + threadTTL |
211 | |
+ ", poolExhaustedAction=" + poolExhaustedAction + ", threadWaitTimeout=" |
212 | |
+ threadWaitTimeout + ", doThreading=" + doThreading + ", workManagerFactory=" |
213 | |
+ workManagerFactory + ", rejectedExecutionHandler=" + rejectedExecutionHandler |
214 | |
+ ", threadFactory=" + threadFactory + "}"; |
215 | |
} |
216 | |
|
217 | |
} |