All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.otto.synapse.info.MessageReceiverEndpointInfos Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.info;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

import static de.otto.synapse.info.MessageReceiverEndpointInfo.builder;
import static java.util.Comparator.comparing;

public class MessageReceiverEndpointInfos {

    private static final String MSG_CHANNEL_STARTING = "Channel is starting";

    private Map channelNameToEndpointInfo = new ConcurrentHashMap<>();


    public void add(final String channelName) {
        channelNameToEndpointInfo.put(channelName, builder()
                .withChannelName(channelName)
                .withMessage(MSG_CHANNEL_STARTING)
                .withStatus(MessageReceiverStatus.STARTING)
                .build());
    }

    public void update(final String channelName,
                       final MessageReceiverEndpointInfo info) {
        channelNameToEndpointInfo.put(channelName, info);
    }

    public Stream stream() {
        return channelNameToEndpointInfo.values().stream().sorted(comparing(MessageReceiverEndpointInfo::getChannelName));
    }

    public MessageReceiverEndpointInfo getChannelInfoFor(final String channel) {
        if (!channelNameToEndpointInfo.containsKey(channel)) {
            throw new IllegalArgumentException("Unknown channel '" + channel + "'");
        }
        return channelNameToEndpointInfo.get(channel);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy