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

it.netgrid.bauer.helpers.SubstituteTopicFactory Maven / Gradle / Ivy

There is a newer version: 1.1.6
Show newest version
package it.netgrid.bauer.helpers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;

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

public class SubstituteTopicFactory implements ITopicFactory {

    boolean postInitialization = false;
    
    final Map> topics = new HashMap>();
    final LinkedBlockingQueue eventQueue = new LinkedBlockingQueue();

    @Override
    synchronized public  Topic getTopic(String name) {
    	@SuppressWarnings("unchecked")
		SubstituteTopic topic = (SubstituteTopic)topics.get(name);
    	if(topic == null) {
    		topic = new SubstituteTopic(name, eventQueue, postInitialization);
    		topics.put(name, topic);
    	}
    	
    	return (Topic) topic;
    }
    
    public LinkedBlockingQueue getEventQueue() {
        return eventQueue;
    }

    public List getTopicNames() {
        return new ArrayList(topics.keySet());
    }

    public List> getTopics() {
        return new ArrayList>(topics.values());
    }
    
    public void postInitialization() {
    	postInitialization = true;
    }
    
    public void clear() {
    	topics.clear();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy