import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.SetMultimap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import org.picocontainer.Startable;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.notification.DefaultNotificationManager;
+import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.server.db.DbClient;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
/**
* @since 2.10
*/
private final long delayInSeconds;
private final long delayBeforeReportingStatusInSeconds;
+ private final DatabaseSessionFactory databaseSessionFactory;
private final DefaultNotificationManager manager;
private final List<NotificationDispatcher> dispatchers;
private final DbClient dbClient;
/**
* Constructor for {@link NotificationService}
*/
- public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient, NotificationDispatcher[] dispatchers) {
+ public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient, DatabaseSessionFactory databaseSessionFactory, NotificationDispatcher[] dispatchers) {
+ this.databaseSessionFactory = databaseSessionFactory;
this.delayInSeconds = settings.getLong(PROPERTY_DELAY);
this.delayBeforeReportingStatusInSeconds = settings.getLong(PROPERTY_DELAY_BEFORE_REPORTING_STATUS);
this.manager = manager;
/**
* Default constructor when no dispatchers.
*/
- public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient) {
- this(settings, manager, dbClient, new NotificationDispatcher[0]);
+ public NotificationService(Settings settings, DefaultNotificationManager manager, DbClient dbClient, DatabaseSessionFactory databaseSessionFactory) {
+ this(settings, manager, dbClient, databaseSessionFactory, new NotificationDispatcher[0]);
}
@Override
processQueue();
} catch (Exception e) {
LOG.error("Error in NotificationService", e);
+ } finally {
+ // Free Hibernate session
+ // See https://jira.codehaus.org/browse/SONAR-6566
+ databaseSessionFactory.clear();
}
}
}, 0, delayInSeconds, TimeUnit.SECONDS);
import org.sonar.api.notifications.NotificationDispatcher;
import org.sonar.core.notification.DefaultNotificationManager;
import org.sonar.core.properties.PropertiesDao;
+import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.server.db.DbClient;
import java.util.Arrays;
Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
service = new NotificationService(settings, manager,
- dbClient, new NotificationDispatcher[] {commentOnIssueAssignedToMe, commentOnIssueCreatedByMe, qualityGateChange});
+ dbClient, mock(DatabaseSessionFactory.class),
+ new NotificationDispatcher[] {commentOnIssueAssignedToMe, commentOnIssueCreatedByMe, qualityGateChange});
}
/**
public void getDispatchers_empty() {
Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
- service = new NotificationService(settings, manager, dbClient);
+ service = new NotificationService(settings, manager, dbClient, mock(DatabaseSessionFactory.class));
assertThat(service.getDispatchers()).hasSize(0);
}