import org.sonar.api.utils.UriReader;
import org.sonar.api.utils.Version;
import org.sonar.ce.CeConfigurationModule;
+import org.sonar.ce.CeDistributedInformationImpl;
import org.sonar.ce.CeHttpModule;
import org.sonar.ce.CeQueueModule;
import org.sonar.ce.CeTaskCommonsModule;
+import org.sonar.ce.StandaloneCeDistributedInformation;
import org.sonar.ce.cleaning.CeCleaningModule;
import org.sonar.ce.cluster.HazelcastClientWrapperImpl;
import org.sonar.ce.db.ReadOnlyPropertiesDao;
import org.sonar.ce.settings.ProjectSettingsFactory;
import org.sonar.ce.taskprocessor.CeTaskProcessorModule;
import org.sonar.ce.user.CeUserSession;
-import org.sonar.ce.CeDistributedInformationImpl;
-import org.sonar.ce.StandaloneCeDistributedInformation;
import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.i18n.DefaultI18n;
import org.sonar.server.metric.CoreCustomMetrics;
import org.sonar.server.metric.DefaultMetricFinder;
import org.sonar.server.notification.DefaultNotificationManager;
-import org.sonar.server.notification.NotificationCenter;
import org.sonar.server.notification.NotificationService;
import org.sonar.server.notification.email.AlertsEmailTemplate;
import org.sonar.server.notification.email.EmailNotificationChannel;
AlertsEmailTemplate.class,
EmailSettings.class,
NotificationService.class,
- NotificationCenter.class,
DefaultNotificationManager.class,
EmailNotificationChannel.class,
assertThat(picoContainer.getComponentAdapters())
.hasSize(
CONTAINER_ITSELF
- + 74 // level 4
+ + 73 // level 4
+ 4 // content of CeConfigurationModule
+ 4 // content of CeQueueModule
+ 3 // content of CeHttpModule
import org.sonar.db.notification.NotificationQueueDto;
import org.sonar.db.property.PropertiesDao;
+import static java.util.Collections.singletonList;
+
public class DefaultNotificationManager implements NotificationManager {
private static final Logger LOG = Loggers.get(DefaultNotificationManager.class);
@Override
public void scheduleForSending(Notification notification) {
NotificationQueueDto dto = NotificationQueueDto.toNotificationQueueDto(notification);
- notificationQueueDao.insert(Arrays.asList(dto));
+ notificationQueueDao.insert(singletonList(dto));
}
-
- @Override
- public void scheduleForSending(List<Notification> notification) {
- notificationQueueDao.insert(Lists.transform(notification, NotificationQueueDto::toNotificationQueueDto));
- }
-
/**
* Give the notification queue so that it can be processed
*/
LOG.info("Notification service stopped");
}
- @VisibleForTesting
- synchronized void processQueue() {
+ private synchronized void processQueue() {
long start = now();
long lastLog = start;
long notifSentCount = 0;
* to know who should receive the notification.
*/
public interface Context {
- /**
- * This method is not used any longer. Calling it will result in an {@link UnsupportedOperationException}.
- *
- * @deprecated Use {@link #addUser(String, NotificationChannel)} instead.
- */
- @Deprecated
- void addUser(String userLogin);
-
/**
* Adds a user that will be notified through the given notification channel.
*
import org.sonar.api.server.ServerSide;
/**
- * <p>
* Notification dispatchers (see {@link NotificationDispatcher}) can define their own metadata class in order
* to tell more about them.
- * <p/>
+ * <p>
* Instances of these classes must be declared by {@link org.sonar.api.Plugin}.
+ * </p>
*/
@ServerSide
@ComputeEngineSide
package org.sonar.server.notification;
import com.google.common.collect.Multimap;
-import java.util.List;
import javax.annotation.Nullable;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
*/
void scheduleForSending(Notification notification);
- /**
- * Receives notifications and stores them so that they are processed by the notification service.
- *
- * @param notifications the notifications.
- * @since 3.7.1
- */
- void scheduleForSending(List<Notification> notifications);
-
/**
* <p>
* Returns the list of users who subscribed to the given dispatcher, along with the notification channels (email, twitter, ...) that they choose
this(dbClient, new NotificationDispatcher[0]);
}
- @VisibleForTesting
- long now() {
- return System.currentTimeMillis();
- }
-
public void deliver(Notification notification) {
- final SetMultimap<String, NotificationChannel> recipients = HashMultimap.create();
+ SetMultimap<String, NotificationChannel> recipients = HashMultimap.create();
for (NotificationDispatcher dispatcher : dispatchers) {
NotificationDispatcher.Context context = new ContextImpl(recipients);
try {
dispatch(notification, recipients);
}
- private void dispatch(Notification notification, SetMultimap<String, NotificationChannel> recipients) {
+ private static void dispatch(Notification notification, SetMultimap<String, NotificationChannel> recipients) {
for (Map.Entry<String, Collection<NotificationChannel>> entry : recipients.asMap().entrySet()) {
String username = entry.getKey();
Collection<NotificationChannel> userChannels = entry.getValue();
}
@VisibleForTesting
- protected List<NotificationDispatcher> getDispatchers() {
+ List<NotificationDispatcher> getDispatchers() {
return dispatchers;
}
private static class ContextImpl implements NotificationDispatcher.Context {
private final Multimap<String, NotificationChannel> recipients;
- public ContextImpl(Multimap<String, NotificationChannel> recipients) {
+ ContextImpl(Multimap<String, NotificationChannel> recipients) {
this.recipients = recipients;
}
- @Override
- public void addUser(String username) {
- // This method is not used anymore
- }
-
@Override
public void addUser(@Nullable String userLogin, NotificationChannel notificationChannel) {
if (userLogin != null) {