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

eu.project.ttc.stream.ConsumerRegistry Maven / Gradle / Ivy

Go to download

A Java UIMA-based toolbox for multilingual and efficient terminology extraction an multilingual term alignment

There is a newer version: 3.0.10
Show newest version
package eu.project.ttc.stream;

import java.util.Map;

import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;

import eu.project.ttc.readers.StreamingCollectionReader;

/**
 * 
 * A registry for {@link CasConsumer}s.
 * 
 * @author Damien Cram
 * @see CasConsumer
 * @see StreamingCollectionReader
 *
 */
public class ConsumerRegistry {

	/*
	 * SINGLETON
	 */
	private static ConsumerRegistry instance = null;

	private ConsumerRegistry() {
		super();
	}
	
	/**
	 * Returns the registry singleton.
	 * 
	 * @return the registry
	 */
	public static ConsumerRegistry getInstance() {
		if(instance == null)
			instance = new ConsumerRegistry();
		return instance;
	}
	
	private Map registry = Maps.newConcurrentMap();
	
	public CasConsumer getConsumer(String consumerName) {
		Preconditions.checkArgument(registry.containsKey(consumerName), "Queue %s does not exist", consumerName);
		return registry.get(consumerName);
	}

	
	public void registerConsumer(String consumerName, CasConsumer consumer) {
		Preconditions.checkNotNull(consumer);
		Preconditions.checkArgument(!registry.containsKey(consumerName), "Consumer %s already exists", consumerName);
		registry.put(consumerName, consumer);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy