From: Sébastien Lesaint Date: Thu, 17 Mar 2016 13:15:37 +0000 (+0100) Subject: SONAR-6732 asynchronous notification service runs only in Web Server X-Git-Tag: 5.5-M11~63 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2bcf361c8c2458d00b4711da65b099a59a266912;p=sonarqube.git SONAR-6732 asynchronous notification service runs only in Web Server --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java index ca619690bae..e44f313b79f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notification/NotificationService.java @@ -76,9 +76,11 @@ public class NotificationService implements Startable { private ScheduledExecutorService executorService; private boolean stopping = false; + private final boolean disabled; public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient, NotificationDispatcher[] dispatchers) { + this.disabled = "ComputeEngineSettings".equals(settings.getClass().getSimpleName()); this.delayInSeconds = settings.getLong(PROPERTY_DELAY); this.delayBeforeReportingStatusInSeconds = settings.getLong(PROPERTY_DELAY_BEFORE_REPORTING_STATUS); this.manager = manager; @@ -95,35 +97,39 @@ public class NotificationService implements Startable { @Override public void start() { - executorService = - Executors.newSingleThreadScheduledExecutor( - new ThreadFactoryBuilder() - .setNameFormat(THREAD_NAME_PREFIX + "%d") - .setPriority(Thread.MIN_PRIORITY) - .build()); - executorService.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - try { - processQueue(); - } catch (Exception e) { - LOG.error("Error in NotificationService", e); + if (!disabled) { + executorService = + Executors.newSingleThreadScheduledExecutor( + new ThreadFactoryBuilder() + .setNameFormat(THREAD_NAME_PREFIX + "%d") + .setPriority(Thread.MIN_PRIORITY) + .build()); + executorService.scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + try { + processQueue(); + } catch (Exception e) { + LOG.error("Error in NotificationService", e); + } } - } - }, 0, delayInSeconds, TimeUnit.SECONDS); - LOG.info("Notification service started (delay {} sec.)", delayInSeconds); + }, 0, delayInSeconds, TimeUnit.SECONDS); + LOG.info("Notification service started (delay {} sec.)", delayInSeconds); + } } @Override public void stop() { - try { - stopping = true; - executorService.shutdown(); - executorService.awaitTermination(5, TimeUnit.SECONDS); - } catch (InterruptedException e) { - LOG.error("Error during stop of notification service", e); + if (!disabled) { + try { + stopping = true; + executorService.shutdown(); + executorService.awaitTermination(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + LOG.error("Error during stop of notification service", e); + } + LOG.info("Notification service stopped"); } - LOG.info("Notification service stopped"); } @VisibleForTesting