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

com.xxdb.streaming.client.QueueManager Maven / Gradle / Ivy

There is a newer version: 3.00.2.2
Show newest version
package com.xxdb.streaming.client;

import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class QueueManager {
    private HashMap>> queueMap = new HashMap>>();

    public synchronized BlockingQueue> addQueue(String topic) {
        if (!queueMap.containsKey(topic)) {
            BlockingQueue> q = new ArrayBlockingQueue<>(4096);
            queueMap.put(topic, q);
            return q;
        }
        throw new RuntimeException("Topic " + topic + " already subscribed");
    }

    public synchronized void changeQueue(String topic, BlockingQueue> q) {
        if (queueMap.containsKey(topic)) {
            queueMap.put(topic, q);
        } else {
            throw new RuntimeException("Topic " + topic + " doesn't subscribed");
        }
    }

    public synchronized BlockingQueue> getQueue(String topic) {
        BlockingQueue> q = queueMap.get(topic);
        return q;
    }

    public synchronized List getAllTopic() {
        java.util.Iterator its = queueMap.keySet().iterator();
        List re = new ArrayList<>();
        while (its.hasNext()) {
            re.add(its.next());
        }
        return re;
    }

    public synchronized void removeQueue(String topic) {
        queueMap.remove(topic);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy