
pl.allegro.tech.hermes.consumers.supervisor.ConsumerHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-consumers Show documentation
Show all versions of hermes-consumers Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.consumers.supervisor;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Table;
import pl.allegro.tech.hermes.api.TopicName;
import pl.allegro.tech.hermes.consumers.consumer.Consumer;
import java.util.Iterator;
import java.util.Optional;
public class ConsumerHolder implements Iterable {
private Table consumers = HashBasedTable.create();
public synchronized void add(TopicName topicName, String subscriptionName, Consumer consumer) {
consumers.put(topicName, subscriptionName, consumer);
}
public synchronized void remove(TopicName topicName, String subscriptionName) {
consumers.remove(topicName, subscriptionName);
}
public synchronized Optional get(TopicName topicName, String subscriptionName) {
return Optional.ofNullable(consumers.get(topicName, subscriptionName));
}
public synchronized boolean contains(TopicName topicName, String subscriptionName) {
return consumers.contains(topicName, subscriptionName);
}
@Override
public synchronized Iterator iterator() {
return Lists.newArrayList(consumers.values()).iterator();
}
public synchronized void clear() {
consumers.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy