Uploaded image for project: 'Apache RocketMQ'
  1. Apache RocketMQ
  2. ROCKETMQ-226

Remove the code that is not useful in the loop

    XMLWordPrintableJSON

    Details

    • Type: Wish
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.0.0-incubating
    • Fix Version/s: 4.2.0
    • Component/s: rocketmq-client
    • Labels:
      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;
          }
      

        Attachments

        1. 555.png
          128 kB
          huangyiminghappy
        2. 666.png
          48 kB
          huangyiminghappy

          Activity

            People

            • Assignee:
              vintagewang Xiaorui Wang
              Reporter:
              huangyiminghappy huangyiminghappy
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified