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

it.netgrid.bauer.impl.StreamTopicFactory Maven / Gradle / Ivy

package it.netgrid.bauer.impl;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;

import it.netgrid.bauer.ITopicFactory;
import it.netgrid.bauer.Topic;

public class StreamTopicFactory implements ITopicFactory {

    private static final Logger log = LoggerFactory.getLogger(StreamTopicFactory.class);

    private final StreamManager manager;
    private final StreamMessageFactory messageFactory;
    private final Map> topics;

    @Inject
    public StreamTopicFactory(StreamManager manager, StreamMessageFactory messageFactory) {
        this.topics = new HashMap<>();
        this.messageFactory = messageFactory;
        this.manager = manager;
    }

    @Override
    @SuppressWarnings("unchecked")
    public  Topic getTopic(String name) {
        if(!topics.containsKey(name)) {
            StreamTopic topic = new StreamTopic<>(manager, messageFactory, name);
            topics.put(name, topic);
        } else {
            log.debug(String.format("Topic %s already exists", name));
        }

        return (Topic) topics.get(name);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy