com.xxdb.streaming.client.QueueManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dolphindb-javaapi Show documentation
Show all versions of dolphindb-javaapi Show documentation
The messaging and data conversion protocol between Java and DolphinDB server
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);
}
}