11
11
import hudson .model .Item ;
12
12
import hudson .model .Job ;
13
13
import hudson .model .Project ;
14
+ import hudson .triggers .SCMTrigger ;
14
15
import hudson .triggers .Trigger ;
15
16
import hudson .triggers .TriggerDescriptor ;
16
17
import hudson .util .FormValidation ;
18
+ import hudson .util .NamingThreadFactory ;
17
19
import hudson .util .SequentialExecutionQueue ;
18
20
import hudson .util .StreamTaskListener ;
21
+ import java .lang .reflect .Field ;
22
+ import java .util .concurrent .Executors ;
23
+ import java .util .concurrent .ThreadFactory ;
19
24
import jenkins .model .Jenkins ;
20
- import jenkins .model .Jenkins .MasterComputer ;
21
25
import jenkins .model .ParameterizedJobMixIn ;
22
26
import jenkins .triggers .SCMTriggerItem .SCMTriggerItems ;
23
27
import org .apache .commons .jelly .XMLOutput ;
45
49
import java .util .Set ;
46
50
47
51
import static org .apache .commons .lang3 .StringUtils .isEmpty ;
48
- import static org .jenkinsci .plugins .github .Messages .github_trigger_check_method_warning_details ;
49
52
import static org .jenkinsci .plugins .github .util .JobInfoHelpers .asParameterizedJobMixIn ;
50
53
51
54
/**
@@ -72,7 +75,9 @@ public void onPost() {
72
75
*/
73
76
public void onPost (String triggeredByUser ) {
74
77
final String pushBy = triggeredByUser ;
75
- getDescriptor ().queue .execute (new Runnable () {
78
+ DescriptorImpl d = getDescriptor ();
79
+ d .checkThreadPoolSize ();
80
+ d .queue .execute (new Runnable () {
76
81
private boolean runPolling () {
77
82
try {
78
83
StreamTaskListener listener = new StreamTaskListener (getLogFile ());
@@ -226,7 +231,7 @@ public void writeLogTo(XMLOutput out) throws IOException {
226
231
@ Extension
227
232
public static class DescriptorImpl extends TriggerDescriptor {
228
233
private final transient SequentialExecutionQueue queue =
229
- new SequentialExecutionQueue (MasterComputer . threadPoolForRemoting );
234
+ new SequentialExecutionQueue (Executors . newSingleThreadExecutor ( threadFactory ()) );
230
235
231
236
private transient String hookUrl ;
232
237
@@ -235,6 +240,43 @@ public static class DescriptorImpl extends TriggerDescriptor {
235
240
@ Inject
236
241
private transient GitHubHookRegisterProblemMonitor monitor ;
237
242
243
+ @ Inject
244
+ private transient SCMTrigger .DescriptorImpl scmTrigger ;
245
+
246
+ private transient int maximumThreads = Integer .MIN_VALUE ;
247
+
248
+ private static ThreadFactory threadFactory () {
249
+ return new NamingThreadFactory (Executors .defaultThreadFactory (), "GitHubPushTrigger" );
250
+ }
251
+
252
+ public DescriptorImpl () {
253
+ checkThreadPoolSize ();
254
+ }
255
+
256
+ /**
257
+ * Update the {@link java.util.concurrent.ExecutorService} instance.
258
+ */
259
+ /*package*/
260
+ synchronized void checkThreadPoolSize () {
261
+ if (scmTrigger != null ) {
262
+ int count = scmTrigger .getPollingThreadCount ();
263
+ if (maximumThreads != count ) {
264
+ maximumThreads = count ;
265
+ try {
266
+ Field getQueue = SCMTrigger .DescriptorImpl .class .getDeclaredField ("queue" );
267
+ getQueue .setAccessible (true );
268
+ SequentialExecutionQueue q = (SequentialExecutionQueue ) getQueue .get (scmTrigger );
269
+ this .queue .setExecutors (q .getExecutors ());
270
+ } catch (NoSuchFieldException | IllegalAccessException | ClassCastException e ) {
271
+ queue .setExecutors (
272
+ (count == 0
273
+ ? Executors .newCachedThreadPool (threadFactory ())
274
+ : Executors .newFixedThreadPool (maximumThreads , threadFactory ())));
275
+ }
276
+ }
277
+ }
278
+ }
279
+
238
280
@ Override
239
281
public boolean isApplicable (Item item ) {
240
282
return item instanceof Job && SCMTriggerItems .asSCMTriggerItem (item ) != null
@@ -351,7 +393,7 @@ public FormValidation doCheckHookRegistered(@AncestorInPath Job<?, ?> job) {
351
393
for (GitHubRepositoryName repo : repos ) {
352
394
if (monitor .isProblemWith (repo )) {
353
395
return FormValidation .warning (
354
- github_trigger_check_method_warning_details (
396
+ org . jenkinsci . plugins . github . Messages . github_trigger_check_method_warning_details (
355
397
repo .getUserName (), repo .getRepositoryName (), repo .getHost ()
356
398
));
357
399
}
0 commit comments