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