class HAManager {

    public RoleChangeInfo selectNewMaster(String cluster, String brokerName) {
        BrokerData brokerData = namesrvController.getRouteInfoManager().getBrokerData(brokerName);
        if (brokerData == null || !cluster.equals(brokerData.getCluster())) {
            log.warn("no broker data for broker name:{}, broker data:{}", brokerName, brokerData);
            return null;
        }

        HashMap<Long, String> brokerAddrs = new HashMap<>(brokerData.getBrokerAddrs());
        for (Iterator<Map.Entry<Long, String>> it = brokerAddrs.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<Long, String> item = it.next();
            if (item.getKey() > namesrvController.getNamesrvConfig().getMaxIdForRoleSwitch()) {
                it.remove();
            }
        }

        //no broker
        if (brokerAddrs == null || brokerAddrs.isEmpty()) {
            log.warn("no broker addrs, for broker name:{}, broker data:{}", brokerName, brokerData);
            return null;
        }

        //only one, and master
        if (brokerAddrs.size() == 1 && brokerAddrs.get(MixAll.MASTER_ID) != null) {
            log.warn("only on broker, but it is current master");
            return null;
        }

        //slave exist
        RoleChangeInfo roleChangeInfo = new RoleChangeInfo();
        SortedSet<Long> ids = new TreeSet<>(brokerAddrs.keySet());
        if (ids.first() == MixAll.MASTER_ID) {
            roleChangeInfo.oldMaster = new RoleInChange(brokerAddrs.get(ids.first()), ids.first(), ids.last() + 1);
        }

        long newMasterId = pickMaster(brokerAddrs);
        if (newMasterId == -1) {
            //newMasterId = ids.last();
            log.error("do not get master, broker name:{}", brokerName);
            return null;
        }
        roleChangeInfo.newMaster = new RoleInChange(brokerAddrs.get(newMasterId), newMasterId, MixAll.MASTER_ID);

        return roleChangeInfo;
    }

    public  HAManager();
    public  HAManager(NamesrvController namesrvController);

}