Search in sources :

Example 11 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData in project rocketmq by apache.

the class BrokerLiveInfo method getHasUnitSubUnUnitTopicList.

public byte[] getHasUnitSubUnUnitTopicList() {
    TopicList topicList = new TopicList();
    try {
        try {
            this.lock.readLock().lockInterruptibly();
            Iterator<Entry<String, List<QueueData>>> topicTableIt = this.topicQueueTable.entrySet().iterator();
            while (topicTableIt.hasNext()) {
                Entry<String, List<QueueData>> topicEntry = topicTableIt.next();
                String topic = topicEntry.getKey();
                List<QueueData> queueDatas = topicEntry.getValue();
                if (queueDatas != null && queueDatas.size() > 0 && !TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag()) && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) {
                    topicList.getTopicList().add(topic);
                }
            }
        } finally {
            this.lock.readLock().unlock();
        }
    } catch (Exception e) {
        log.error("getAllTopicList Exception", e);
    }
    return topicList.encode();
}
Also used : Entry(java.util.Map.Entry) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 12 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData in project rocketmq by apache.

the class BrokerLiveInfo method createAndUpdateQueueData.

private void createAndUpdateQueueData(final String brokerName, final TopicConfig topicConfig) {
    QueueData queueData = new QueueData();
    queueData.setBrokerName(brokerName);
    queueData.setWriteQueueNums(topicConfig.getWriteQueueNums());
    queueData.setReadQueueNums(topicConfig.getReadQueueNums());
    queueData.setPerm(topicConfig.getPerm());
    queueData.setTopicSynFlag(topicConfig.getTopicSysFlag());
    List<QueueData> queueDataList = this.topicQueueTable.get(topicConfig.getTopicName());
    if (null == queueDataList) {
        queueDataList = new LinkedList<QueueData>();
        queueDataList.add(queueData);
        this.topicQueueTable.put(topicConfig.getTopicName(), queueDataList);
        log.info("new topic registered, {} {}", topicConfig.getTopicName(), queueData);
    } else {
        boolean addNewOne = true;
        Iterator<QueueData> it = queueDataList.iterator();
        while (it.hasNext()) {
            QueueData qd = it.next();
            if (qd.getBrokerName().equals(brokerName)) {
                if (qd.equals(queueData)) {
                    addNewOne = false;
                } else {
                    log.info("topic changed, {} OLD: {} NEW: {}", topicConfig.getTopicName(), qd, queueData);
                    it.remove();
                }
            }
        }
        if (addNewOne) {
            queueDataList.add(queueData);
        }
    }
}
Also used : QueueData(org.apache.rocketmq.common.protocol.route.QueueData)

Example 13 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData in project rocketmq by apache.

the class BrokerLiveInfo method pickupTopicRouteData.

public TopicRouteData pickupTopicRouteData(final String topic) {
    TopicRouteData topicRouteData = new TopicRouteData();
    boolean foundQueueData = false;
    boolean foundBrokerData = false;
    Set<String> brokerNameSet = new HashSet<String>();
    List<BrokerData> brokerDataList = new LinkedList<BrokerData>();
    topicRouteData.setBrokerDatas(brokerDataList);
    HashMap<String, List<String>> filterServerMap = new HashMap<String, List<String>>();
    topicRouteData.setFilterServerTable(filterServerMap);
    try {
        try {
            this.lock.readLock().lockInterruptibly();
            List<QueueData> queueDataList = this.topicQueueTable.get(topic);
            if (queueDataList != null) {
                topicRouteData.setQueueDatas(queueDataList);
                foundQueueData = true;
                Iterator<QueueData> it = queueDataList.iterator();
                while (it.hasNext()) {
                    QueueData qd = it.next();
                    brokerNameSet.add(qd.getBrokerName());
                }
                for (String brokerName : brokerNameSet) {
                    BrokerData brokerData = this.brokerAddrTable.get(brokerName);
                    if (null != brokerData) {
                        BrokerData brokerDataClone = new BrokerData(brokerData.getCluster(), brokerData.getBrokerName(), (HashMap<Long, String>) brokerData.getBrokerAddrs().clone());
                        brokerDataList.add(brokerDataClone);
                        foundBrokerData = true;
                        for (final String brokerAddr : brokerDataClone.getBrokerAddrs().values()) {
                            List<String> filterServerList = this.filterServerTable.get(brokerAddr);
                            filterServerMap.put(brokerAddr, filterServerList);
                        }
                    }
                }
            }
        } finally {
            this.lock.readLock().unlock();
        }
    } catch (Exception e) {
        log.error("pickupTopicRouteData Exception", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("pickupTopicRouteData {} {}", topic, topicRouteData);
    }
    if (foundBrokerData && foundQueueData) {
        return topicRouteData;
    }
    return null;
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) LinkedList(java.util.LinkedList) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet)

Example 14 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData in project rocketmq by apache.

the class BrokerLiveInfo method getHasUnitSubTopicList.

public byte[] getHasUnitSubTopicList() {
    TopicList topicList = new TopicList();
    try {
        try {
            this.lock.readLock().lockInterruptibly();
            Iterator<Entry<String, List<QueueData>>> topicTableIt = this.topicQueueTable.entrySet().iterator();
            while (topicTableIt.hasNext()) {
                Entry<String, List<QueueData>> topicEntry = topicTableIt.next();
                String topic = topicEntry.getKey();
                List<QueueData> queueDatas = topicEntry.getValue();
                if (queueDatas != null && queueDatas.size() > 0 && TopicSysFlag.hasUnitSubFlag(queueDatas.get(0).getTopicSynFlag())) {
                    topicList.getTopicList().add(topic);
                }
            }
        } finally {
            this.lock.readLock().unlock();
        }
    } catch (Exception e) {
        log.error("getAllTopicList Exception", e);
    }
    return topicList.encode();
}
Also used : Entry(java.util.Map.Entry) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 15 with QueueData

use of org.apache.rocketmq.common.protocol.route.QueueData in project rocketmq by apache.

the class BrokerLiveInfo method getUnitTopics.

public byte[] getUnitTopics() {
    TopicList topicList = new TopicList();
    try {
        try {
            this.lock.readLock().lockInterruptibly();
            Iterator<Entry<String, List<QueueData>>> topicTableIt = this.topicQueueTable.entrySet().iterator();
            while (topicTableIt.hasNext()) {
                Entry<String, List<QueueData>> topicEntry = topicTableIt.next();
                String topic = topicEntry.getKey();
                List<QueueData> queueDatas = topicEntry.getValue();
                if (queueDatas != null && queueDatas.size() > 0 && TopicSysFlag.hasUnitFlag(queueDatas.get(0).getTopicSynFlag())) {
                    topicList.getTopicList().add(topic);
                }
            }
        } finally {
            this.lock.readLock().unlock();
        }
    } catch (Exception e) {
        log.error("getAllTopicList Exception", e);
    }
    return topicList.encode();
}
Also used : Entry(java.util.Map.Entry) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

QueueData (org.apache.rocketmq.common.protocol.route.QueueData)42 List (java.util.List)30 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)24 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)20 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)20 HashMap (java.util.HashMap)18 ArrayList (java.util.ArrayList)16 LinkedList (java.util.LinkedList)16 Entry (java.util.Map.Entry)16 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)16 HashSet (java.util.HashSet)14 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Field (java.lang.reflect.Field)10 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)10 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)10 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)10 BeforeClass (org.junit.BeforeClass)10 Set (java.util.Set)8 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)8