use of org.graylog2.cluster.leader.LeaderChangedEvent in project graylog2-server by Graylog2.
the class InputEventListener method leaderChanged.
@Subscribe
public void leaderChanged(LeaderChangedEvent event) {
if (serverStatus.getLifecycle() == Lifecycle.STARTING) {
LOG.debug("Ignoring LeaderChangedEvent during server startup.");
return;
}
if (leaderElectionService.isLeader()) {
for (MessageInput input : persistedInputs) {
final IOState<MessageInput> inputState = inputRegistry.getInputState(input.getId());
if (input.onlyOnePerCluster() && input.isGlobal() && (inputState == null || inputState.canBeStarted()) && inputLauncher.shouldStartAutomatically(input)) {
LOG.info("Got leader role. Starting input [{}/{}/{}]", input.getName(), input.getTitle(), input.getId());
startMessageInput(input);
}
}
} else {
inputRegistry.getRunningInputs().stream().map(IOState::getStoppable).filter(input -> input.isGlobal() && input.onlyOnePerCluster()).forEach(input -> {
LOG.info("Lost leader role. Stopping input [{}/{}/{}]", input.getName(), input.getTitle(), input.getId());
inputDeleted(InputDeleted.create(input.getId()));
});
}
}
Aggregations