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

pl.allegro.tech.hermes.consumers.supervisor.ConsumerHolder Maven / Gradle / Ivy

There is a newer version: 2.10.4
Show newest version
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