it.netgrid.bauer.helpers.SubstituteTopicFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bauer-api Show documentation
Show all versions of bauer-api Show documentation
Standard Topic-Based Messaging Facade for Java
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