io.eventuate.tram.sagas.testing.commandhandling.ReconfigurableCommandHandlers Maven / Gradle / Ivy
package io.eventuate.tram.sagas.testing.commandhandling;
import io.eventuate.tram.commands.common.Command;
import io.eventuate.tram.commands.consumer.CommandExceptionHandler;
import io.eventuate.tram.commands.consumer.CommandHandler;
import io.eventuate.tram.commands.consumer.CommandHandlers;
import io.eventuate.tram.messaging.common.Message;
import java.util.*;
public class ReconfigurableCommandHandlers extends CommandHandlers {
private final Set commandChannels;
private List handlers = new ArrayList<>();
public ReconfigurableCommandHandlers(Set commandChannels) {
super(Collections.emptyList());
this.commandChannels = commandChannels;
}
@Override
public Set getChannels() {
return commandChannels;
}
public void add(SagaParticipantStubCommandHandler commandHandler) {
this.handlers.add(commandHandler);
}
@Override
public Optional findTargetMethod(Message message) {
return handlers.stream().filter(h -> h.handles(message)).findFirst().map(x -> (CommandHandler)x);
}
public void reset() {
handlers.clear();
}
public Optional findCommandHandler(String channel, Class commandClass) {
return handlers.stream().filter(h -> h.handles(channel, commandClass)).findFirst();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy