[ 
https://issues.apache.org/jira/browse/ROCKETMQ-226?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

huangyiminghappy updated ROCKETMQ-226:
--------------------------------------
    Description: 
in the clientComponent 
,org.apache.rocketmq.client.impl.factory.MQClientInstance class has the method 
like this:
{code:java}
 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;
    }
{code}

I think the FOR_SEG should remove,it is not useful,it should modify like this:

{code:java}
    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;
    }
{code}


  was:
in the clint Component 
,org.apache.rocketmq.client.impl.factory.MQClientInstance class has the method 
like this:
{code:java}
 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;
    }
{code}

I think the FOR_SEG should remove,it is not useful


> Remove the code that is not useful in the loop
> ----------------------------------------------
>
>                 Key: ROCKETMQ-226
>                 URL: https://issues.apache.org/jira/browse/ROCKETMQ-226
>             Project: Apache RocketMQ
>          Issue Type: Wish
>          Components: rocketmq-client
>    Affects Versions: 4.0.0-incubating
>            Reporter: huangyiminghappy
>            Assignee: Xiaorui Wang
>            Priority: Minor
>             Fix For: 4.1.0-incubating
>
>         Attachments: 555.png, 666.png
>
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> in the clientComponent 
> ,org.apache.rocketmq.client.impl.factory.MQClientInstance class has the 
> method like this:
> {code:java}
>  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;
>     }
> {code}
> I think the FOR_SEG should remove,it is not useful,it should modify like this:
> {code:java}
>     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;
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to