Fix creating duplicate triggers from TriggersModule
@@ -38,7 +38,6 @@ import java.util.function.Supplier;
import static com.google.common.collect.Iterators.getLast;
import static io.datakernel.util.guice.GuiceUtils.*;
import static java.util.Collections.emptyList;
-import static java.util.Collections.emptySet;
public final class TriggersModule extends AbstractModule implements Initializable<TriggersModule> {
private Function<Key<?>, String> keyToString = GuiceUtils::prettyPrintSimpleKeyName;
@@ -52,8 +51,8 @@ public final class TriggersModule extends AbstractModule implements Initializabl
private final Map<Key<?>, List<TriggerRegistryRecorder>> singletonRegistryRecords = new HashMap<>();
private final Map<KeyWithWorkerData, List<TriggerRegistryRecorder>> workerRegistryRecords = new HashMap<>();
- private final Map<Class<?>, Set<TriggerConfig<?>>> classSettings = new LinkedHashMap<>();
- private final Map<Key<?>, Set<TriggerConfig<?>>> keySettings = new LinkedHashMap<>();
+ private final Map<Class<?>, List<TriggerConfig<?>>> classSettings = new LinkedHashMap<>();
+ private final Map<Key<?>, List<TriggerConfig<?>>> keySettings = new LinkedHashMap<>();
private static final class TriggerConfig<T> {
private final Severity severity;
@@ -175,13 +174,13 @@ public final class TriggersModule extends AbstractModule implements Initializabl
public <T> TriggersModule with(Class<T> type, Severity severity, String name,
Function<T, TriggerResult> triggerFunction) {
- classSettings.computeIfAbsent(type, $ -> new LinkedHashSet<>()).add(new TriggerConfig<>(severity, name, triggerFunction));
+ classSettings.computeIfAbsent(type, $ -> new ArrayList<>()).add(new TriggerConfig<>(severity, name, triggerFunction));
return this;
}
public <T> TriggersModule with(Key<T> key, Severity severity, String name,
Function<T, TriggerResult> triggerFunction) {
- keySettings.computeIfAbsent(key, $ -> new LinkedHashSet<>()).add(new TriggerConfig<>(severity, name, triggerFunction));
+ keySettings.computeIfAbsent(key, $ -> new ArrayList<>()).add(new TriggerConfig<>(severity, name, triggerFunction));
return this;
}
@@ -378,7 +377,7 @@ public final class TriggersModule extends AbstractModule implements Initializabl
@SuppressWarnings("unchecked")
private void scanKeySettings(Map<KeyWithWorkerData, List<TriggerRegistryRecord>> triggers, KeyWithWorkerData internalKey, Object instance) {
Key<Object> key = (Key<Object>) internalKey.key;
- for (TriggerConfig<?> config : keySettings.getOrDefault(key, emptySet())) {
+ for (TriggerConfig<?> config : keySettings.getOrDefault(key, emptyList())) {
triggers.computeIfAbsent(internalKey, $ -> new ArrayList<>())
.add(new TriggerRegistryRecord(config.severity, config.name, () ->
((TriggerConfig<Object>) config).triggerFunction.apply(instance)));
