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 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 this(DEFAULT_THREADING_PROFILE);
61 }
62
63
64
65
66
67
68
69 public ChainedThreadingProfile(ThreadingProfile delegate)
70 {
71 this(delegate, true);
72 }
73
74
75
76
77
78
79
80
81
82 public ChainedThreadingProfile(ThreadingProfile delegate, boolean dynamic)
83 {
84 if (!dynamic)
85 {
86
87 delegate = new ImmutableThreadingProfile(delegate);
88 }
89 this.delegate = delegate;
90 }
91
92 public int getMaxThreadsActive()
93 {
94 return null != maxThreadsActive ? maxThreadsActive.intValue() : delegate.getMaxThreadsActive();
95 }
96
97 public int getMaxThreadsIdle()
98 {
99 return null != maxThreadsIdle ? maxThreadsIdle.intValue() : delegate.getMaxThreadsIdle();
100 }
101
102 public long getThreadTTL()
103 {
104 return null != threadTTL ? threadTTL.longValue() : delegate.getThreadTTL();
105 }
106
107 public long getThreadWaitTimeout()
108 {
109 return null != threadWaitTimeout ? threadWaitTimeout.longValue() : delegate.getThreadWaitTimeout();
110 }
111
112 public int getPoolExhaustedAction()
113 {
114 return null != poolExhaustedAction ? poolExhaustedAction.intValue() : delegate.getPoolExhaustedAction();
115 }
116
117 public RejectedExecutionHandler getRejectedExecutionHandler()
118 {
119 return rejectedExecutionHandler;
120 }
121
122 public ThreadFactory getThreadFactory()
123 {
124 return threadFactory;
125 }
126
127 public void setMaxThreadsActive(int maxThreadsActive)
128 {
129 this.maxThreadsActive = new Integer(maxThreadsActive);
130 }
131
132 public void setMaxThreadsIdle(int maxThreadsIdle)
133 {
134 this.maxThreadsIdle = new Integer(maxThreadsIdle);
135 }
136
137 public void setThreadTTL(long threadTTL)
138 {
139 this.threadTTL = new Long(threadTTL);
140 }
141
142 public void setThreadWaitTimeout(long threadWaitTimeout)
143 {
144 this.threadWaitTimeout = new Long(threadWaitTimeout);
145 }
146
147 public void setPoolExhaustedAction(int poolExhaustPolicy)
148 {
149 this.poolExhaustedAction = new Integer(poolExhaustPolicy);
150 }
151
152 public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
153 {
154 this.rejectedExecutionHandler = rejectedExecutionHandler;
155 }
156
157 public void setThreadFactory(ThreadFactory threadFactory)
158 {
159 this.threadFactory = threadFactory;
160 }
161
162 public int getMaxBufferSize()
163 {
164 return null != maxBufferSize ? maxBufferSize.intValue() : delegate.getMaxBufferSize();
165 }
166
167 public void setMaxBufferSize(int maxBufferSize)
168 {
169 this.maxBufferSize = new Integer(maxBufferSize);
170 }
171
172 public WorkManagerFactory getWorkManagerFactory()
173 {
174 return workManagerFactory;
175 }
176
177 public void setWorkManagerFactory(WorkManagerFactory workManagerFactory)
178 {
179 this.workManagerFactory = workManagerFactory;
180 }
181
182 public WorkManager createWorkManager(String name)
183 {
184 return workManagerFactory.createWorkManager(this, name);
185 }
186
187 public ThreadPoolExecutor createPool()
188 {
189 return createPool(null);
190 }
191
192 public ThreadPoolExecutor createPool(String name)
193 {
194 return ImmutableThreadingProfile.createPool(name, this);
195 }
196
197 public boolean isDoThreading()
198 {
199 return null != doThreading ? doThreading.booleanValue() : delegate.isDoThreading();
200 }
201
202 public void setDoThreading(boolean doThreading)
203 {
204 this.doThreading = Boolean.valueOf(doThreading);
205 }
206
207 public String toString()
208 {
209 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 }