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

de.otto.synapse.endpoint.sender.InMemoryMessageSenderFactory Maven / Gradle / Ivy

package de.otto.synapse.endpoint.sender;

import de.otto.synapse.channel.InMemoryChannels;
import de.otto.synapse.channel.selector.Selector;
import de.otto.synapse.endpoint.MessageInterceptorRegistry;
import de.otto.synapse.translator.MessageFormat;
import de.otto.synapse.translator.TextMessageTranslator;
import jakarta.annotation.Nonnull;

public class InMemoryMessageSenderFactory implements MessageSenderEndpointFactory {

    private final MessageInterceptorRegistry registry;
    private final InMemoryChannels inMemoryChannels;
    private final Class selector;

    public InMemoryMessageSenderFactory(final MessageInterceptorRegistry registry,
                                        final InMemoryChannels inMemoryChannels,
                                        final Class selector) {
        this.registry = registry;
        this.inMemoryChannels = inMemoryChannels;
        this.selector = selector;
    }

    @Override
    public InMemoryMessageSender create(@Nonnull final String channelName, MessageFormat messageFormat) {
        final InMemoryMessageSender messageSender = new InMemoryMessageSender(
                registry,
                new TextMessageTranslator(),
                inMemoryChannels.getChannel(channelName));
        return messageSender;
    }

    @Override
    public boolean matches(Class channelSelector) {
        return selector == null || selector.isAssignableFrom(channelSelector);
    }

    @Override
    public Class selector() {
        return selector;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy