Details
-
Wish
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
4.0.0-incubating
-
None
Description
in the clientComponent ,org.apache.rocketmq.client.impl.factory.MQClientInstance class has the method like this:
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; }
the code FOR_SEG is not useful,It is not multiple loop,You do not need to jump to the specified loop,so i suggest remove the FOR_SEQ code like this:
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 (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; } else { slave = true; } break; } } // end of for } if (found) { return new FindBrokerResult(brokerAddr, slave); } return null; }