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 .util .concurrent .Executors ;
22
+ import java .util .concurrent .ThreadFactory ;
19
23
import jenkins .model .Jenkins ;
20
- import jenkins .model .Jenkins .MasterComputer ;
21
24
import jenkins .model .ParameterizedJobMixIn ;
22
25
import jenkins .triggers .SCMTriggerItem .SCMTriggerItems ;
23
26
import org .apache .commons .jelly .XMLOutput ;
45
48
import java .util .Set ;
46
49
47
50
import static org .apache .commons .lang3 .StringUtils .isEmpty ;
48
- import static org .jenkinsci .plugins .github .Messages .github_trigger_check_method_warning_details ;
49
51
import static org .jenkinsci .plugins .github .util .JobInfoHelpers .asParameterizedJobMixIn ;
50
52
51
53
/**
@@ -72,7 +74,9 @@ public void onPost() {
72
74
*/
73
75
public void onPost (String triggeredByUser ) {
74
76
final String pushBy = triggeredByUser ;
75
- getDescriptor ().queue .execute (new Runnable () {
77
+ DescriptorImpl d = getDescriptor ();
78
+ d .checkThreadPoolSizeAndUpdateIfNecessary ();
79
+ d .queue .execute (new Runnable () {
76
80
private boolean runPolling () {
77
81
try {
78
82
StreamTaskListener listener = new StreamTaskListener (getLogFile ());
@@ -226,7 +230,7 @@ public void writeLogTo(XMLOutput out) throws IOException {
226
230
@ Extension
227
231
public static class DescriptorImpl extends TriggerDescriptor {
228
232
private final transient SequentialExecutionQueue queue =
229
- new SequentialExecutionQueue (MasterComputer . threadPoolForRemoting );
233
+ new SequentialExecutionQueue (Executors . newSingleThreadExecutor ( threadFactory ()) );
230
234
231
235
private transient String hookUrl ;
232
236
@@ -235,6 +239,32 @@ public static class DescriptorImpl extends TriggerDescriptor {
235
239
@ Inject
236
240
private transient GitHubHookRegisterProblemMonitor monitor ;
237
241
242
+ @ Inject
243
+ private transient SCMTrigger .DescriptorImpl scmTrigger ;
244
+
245
+ private transient int maximumThreads = Integer .MIN_VALUE ;
246
+
247
+ public DescriptorImpl () {
248
+ checkThreadPoolSizeAndUpdateIfNecessary ();
249
+ }
250
+
251
+ /**
252
+ * Update the {@link java.util.concurrent.ExecutorService} instance.
253
+ */
254
+ /*package*/
255
+ synchronized void checkThreadPoolSizeAndUpdateIfNecessary () {
256
+ if (scmTrigger != null ) {
257
+ int count = scmTrigger .getPollingThreadCount ();
258
+ if (maximumThreads != count ) {
259
+ maximumThreads = count ;
260
+ queue .setExecutors (
261
+ (count == 0
262
+ ? Executors .newCachedThreadPool (threadFactory ())
263
+ : Executors .newFixedThreadPool (maximumThreads , threadFactory ())));
264
+ }
265
+ }
266
+ }
267
+
238
268
@ Override
239
269
public boolean isApplicable (Item item ) {
240
270
return item instanceof Job && SCMTriggerItems .asSCMTriggerItem (item ) != null
@@ -333,6 +363,10 @@ public static boolean allowsHookUrlOverride() {
333
363
return ALLOW_HOOKURL_OVERRIDE ;
334
364
}
335
365
366
+ private static ThreadFactory threadFactory () {
367
+ return new NamingThreadFactory (Executors .defaultThreadFactory (), "GitHubPushTrigger" );
368
+ }
369
+
336
370
/**
337
371
* Checks that repo defined in this job is not in administrative monitor as failed to be registered.
338
372
* If that so, shows warning with some instructions
@@ -351,7 +385,7 @@ public FormValidation doCheckHookRegistered(@AncestorInPath Job<?, ?> job) {
351
385
for (GitHubRepositoryName repo : repos ) {
352
386
if (monitor .isProblemWith (repo )) {
353
387
return FormValidation .warning (
354
- github_trigger_check_method_warning_details (
388
+ org . jenkinsci . plugins . github . Messages . github_trigger_check_method_warning_details (
355
389
repo .getUserName (), repo .getRepositoryName (), repo .getHost ()
356
390
));
357
391
}
0 commit comments