Don't use List in GerritConfigListener API

Currently GerritConfigListener's configUpdated method returns a List of
ConfigUpdatedEvent.Update.

There are only two types of updates (applied and rejected)
and the API returning lists of updates does not reflect this but
gives the impression that there can be an arbitrary amount
of update types.

Instead of returning a List of ConfigUpdatedEvent.Update that each have
a type, return a Multimap<UpdateResult, ConfigUpdateEntry>.

Removed the ConfigUpdatedEvent.Update class.

Change-Id: I81b4327a5878739087cd8a2ea8c0cff035b6ee57
This commit is contained in:
Rikard Almgren
2018-11-12 14:04:27 +01:00
parent 12f16056ca
commit 31300d71e3
9 changed files with 79 additions and 114 deletions

View File

@@ -14,12 +14,14 @@
package com.google.gerrit.server.config;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.server.config.ConfigUpdatedEvent.ConfigUpdateEntry;
import com.google.gerrit.server.config.ConfigUpdatedEvent.UpdateResult;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
/** Issues a configuration reload from the GerritServerConfigProvider and notify all listeners. */
@Singleton
@@ -40,18 +42,20 @@ public class GerritServerConfigReloader {
* Reloads the Gerrit Server Configuration from disk. Synchronized to ensure that one issued
* reload is fully completed before a new one starts.
*/
public List<ConfigUpdatedEvent.Update> reloadConfig() {
public Multimap<UpdateResult, ConfigUpdateEntry> reloadConfig() {
logger.atInfo().log("Starting server configuration reload");
List<ConfigUpdatedEvent.Update> updates = fireUpdatedConfigEvent(configProvider.updateConfig());
Multimap<UpdateResult, ConfigUpdateEntry> updates =
fireUpdatedConfigEvent(configProvider.updateConfig());
logger.atInfo().log("Server configuration reload completed succesfully");
return updates;
}
public List<ConfigUpdatedEvent.Update> fireUpdatedConfigEvent(ConfigUpdatedEvent event) {
ArrayList<ConfigUpdatedEvent.Update> result = new ArrayList<>();
public Multimap<UpdateResult, ConfigUpdateEntry> fireUpdatedConfigEvent(
ConfigUpdatedEvent event) {
Multimap<UpdateResult, ConfigUpdateEntry> updates = ArrayListMultimap.create();
for (GerritConfigListener configListener : configListeners) {
result.addAll(configListener.configUpdated(event));
updates.putAll(configListener.configUpdated(event));
}
return result;
return updates;
}
}