Java Code Examples for com.alibaba.rocketmq.common.MixAll#MASTER_ID

The following examples show how to use com.alibaba.rocketmq.common.MixAll#MASTER_ID . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PullAPIWrapper.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public long recalculatePullFromWhichNode(final MessageQueue mq) {
    if (this.isConnectBrokerByUser()) {
        return this.defaultBrokerId;
    }

    AtomicLong suggest = this.pullFromWhichNodeTable.get(mq);
    if (suggest != null) {
        return suggest.get();
    }

    return MixAll.MASTER_ID;
}
 
Example 2
Source File: MQClientInstance.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private void sendHeartbeatToAllBroker() {
    final HeartbeatData heartbeatData = this.prepareHeartbeatData();
    final boolean producerEmpty = heartbeatData.getProducerDataSet().isEmpty();
    final boolean consumerEmpty = heartbeatData.getConsumerDataSet().isEmpty();
    if (producerEmpty && consumerEmpty) {
        log.warn("sending hearbeat, but no consumer and no producer");
        return;
    }

    Iterator<Entry<String, HashMap<Long, String>>> it = this.brokerAddrTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, HashMap<Long, String>> entry = it.next();
        String brokerName = entry.getKey();
        HashMap<Long, String> oneTable = entry.getValue();
        if (oneTable != null) {
            for (Long id : oneTable.keySet()) {
                String addr = oneTable.get(id);
                if (addr != null) {
                    if (consumerEmpty) {
                        if (id != MixAll.MASTER_ID)
                            continue;
                    }

                    try {
                        this.mQClientAPIImpl.sendHearbeat(addr, heartbeatData, 3000);
                        log.info("send heart beat to broker[{} {} {}] success", brokerName, id, addr);
                        log.info(heartbeatData.toString());
                    }
                    catch (Exception e) {
                        log.error("send heart beat to broker exception", e);
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: MQClientInstance.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInAdmin(final String brokerName) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        FOR_SEG: for (Map.Entry<Long, String> entry : map.entrySet()) {
            Long id = entry.getKey();
            brokerAddr = entry.getValue();
            if (brokerAddr != null) {
                found = true;
                if (MixAll.MASTER_ID == id) {
                    slave = false;
                    break FOR_SEG;
                }
                else {
                    slave = true;
                }
                break;

            }
        } // end of for
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave);
    }

    return null;
}
 
Example 4
Source File: MQClientInstance.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInSubscribe(//
        final String brokerName,//
        final long brokerId,//
        final boolean onlyThisBroker//
) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        brokerAddr = map.get(brokerId);
        slave = (brokerId != MixAll.MASTER_ID);
        found = (brokerAddr != null);

        if (!found && !onlyThisBroker) {
            Entry<Long, String> entry = map.entrySet().iterator().next();
            brokerAddr = entry.getValue();
            slave = (entry.getKey() != MixAll.MASTER_ID);
            found = true;
        }
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave);
    }

    return null;
}
 
Example 5
Source File: PullAPIWrapper.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public long recalculatePullFromWhichNode(final MessageQueue mq) {
    if (this.isConnectBrokerByUser()) {
        return this.defaultBrokerId;
    }

    AtomicLong suggest = this.pullFromWhichNodeTable.get(mq);
    if (suggest != null) {
        return suggest.get();
    }

    return MixAll.MASTER_ID;
}
 
Example 6
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInAdmin(final String brokerName) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        FOR_SEG:
        for (Map.Entry<Long, String> entry : map.entrySet()) {
            Long id = entry.getKey();
            brokerAddr = entry.getValue();
            if (brokerAddr != null) {
                found = true;
                if (MixAll.MASTER_ID == id) {
                    slave = false;
                    break FOR_SEG;
                } else {
                    slave = true;
                }
                break;

            }
        } // end of for
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave);
    }

    return null;
}
 
Example 7
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInSubscribe(//
                                                     final String brokerName, //
                                                     final long brokerId, //
                                                     final boolean onlyThisBroker//
) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        brokerAddr = map.get(brokerId);
        slave = (brokerId != MixAll.MASTER_ID);
        found = (brokerAddr != null);

        if (!found && !onlyThisBroker) {
            Entry<Long, String> entry = map.entrySet().iterator().next();
            brokerAddr = entry.getValue();
            slave = (entry.getKey() != MixAll.MASTER_ID);
            found = true;
        }
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave);
    }

    return null;
}
 
Example 8
Source File: PullAPIWrapper.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public long recalculatePullFromWhichNode(final MessageQueue mq) {
    if (this.isConnectBrokerByUser()) {
        return this.defaultBrokerId;
    }

    AtomicLong suggest = this.pullFromWhichNodeTable.get(mq);
    if (suggest != null) {
        return suggest.get();
    }

    return MixAll.MASTER_ID;
}
 
Example 9
Source File: MQClientInstance.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
private void sendHeartbeatToAllBroker() {
    final HeartbeatData heartbeatData = this.prepareHeartbeatData();
    final boolean producerEmpty = heartbeatData.getProducerDataSet().isEmpty();
    final boolean consumerEmpty = heartbeatData.getConsumerDataSet().isEmpty();
    if (producerEmpty && consumerEmpty) {
        log.warn("sending hearbeat, but no consumer and no producer");
        return;
    }

    Iterator<Entry<String, HashMap<Long, String>>> it = this.brokerAddrTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, HashMap<Long, String>> entry = it.next();
        String brokerName = entry.getKey();
        HashMap<Long, String> oneTable = entry.getValue();
        if (oneTable != null) {
            for (Long id : oneTable.keySet()) {
                String addr = oneTable.get(id);
                if (addr != null) {
                    if (consumerEmpty) {
                        if (id != MixAll.MASTER_ID)
                            continue;
                    }

                    try {
                        this.mQClientAPIImpl.sendHearbeat(addr, heartbeatData, 3000);
                        log.info("send heart beat to broker[{} {} {}] success", brokerName, id, addr);
                        log.info(heartbeatData.toString());
                    } catch (Exception e) {
                        log.error("send heart beat to broker exception", e);
                    }
                }
            }
        }
    }
}
 
Example 10
Source File: MQClientInstance.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInAdmin(final String brokerName) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        FOR_SEG:
        for (Map.Entry<Long, String> entry : map.entrySet()) {
            Long id = entry.getKey();
            brokerAddr = entry.getValue();
            if (brokerAddr != null) {
                found = true;
                if (MixAll.MASTER_ID == id) {
                    slave = false;
                    break FOR_SEG;
                } else {
                    slave = true;
                }
                break;

            }
        } // end of for
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave);
    }

    return null;
}
 
Example 11
Source File: MQClientInstance.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public FindBrokerResult findBrokerAddressInSubscribe(//
                                                     final String brokerName, //
                                                     final long brokerId, //
                                                     final boolean onlyThisBroker//
) {
    String brokerAddr = null;
    boolean slave = false;
    boolean found = false;

    HashMap<Long/* brokerId */, String/* address */> map = this.brokerAddrTable.get(brokerName);
    if (map != null && !map.isEmpty()) {
        brokerAddr = map.get(brokerId);
        slave = (brokerId != MixAll.MASTER_ID);
        found = (brokerAddr != null);

        if (!found && !onlyThisBroker) {
            Entry<Long, String> entry = map.entrySet().iterator().next();
            brokerAddr = entry.getValue();
            slave = (entry.getKey() != MixAll.MASTER_ID);
            found = true;
        }
    }

    if (found) {
        return new FindBrokerResult(brokerAddr, slave);
    }

    return null;
}
 
Example 12
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private void sendHeartbeatToAllBroker() {
    final HeartbeatData heartbeatData = this.prepareHeartbeatData();
    final boolean producerEmpty = heartbeatData.getProducerDataSet().isEmpty();
    final boolean consumerEmpty = heartbeatData.getConsumerDataSet().isEmpty();
    if (producerEmpty && consumerEmpty) {
        log.warn("sending hearbeat, but no consumer and no producer");
        return;
    }

    long times = this.storeTimesTotal.getAndIncrement();
    Iterator<Entry<String, HashMap<Long, String>>> it = this.brokerAddrTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, HashMap<Long, String>> entry = it.next();
        String brokerName = entry.getKey();
        HashMap<Long, String> oneTable = entry.getValue();
        if (oneTable != null) {
            for (Map.Entry<Long, String> entry1 : oneTable.entrySet()) {
                Long id = entry1.getKey();
                String addr = entry1.getValue();
                if (addr != null) {
                    if (consumerEmpty) {
                        if (id != MixAll.MASTER_ID)
                            continue;
                    }

                    try {
                        this.mQClientAPIImpl.sendHearbeat(addr, heartbeatData, 3000);
                        if (times % 20 == 0) {
                            log.info("send heart beat to broker[{} {} {}] success", brokerName, id, addr);
                            log.info(heartbeatData.toString());
                        }
                    } catch (Exception e) {
                        if (this.isBrokerInNameServer(addr)) {
                            log.error("send heart beat to broker exception", e);
                        } else {
                            log.info("send heart beat to broker[{} {} {}] exception, because the broker not up, forget it", brokerName,
                                    id, addr);
                        }
                    }
                }
            }
        }
    }
}