class RouteInfoManager {

    public RegisterBrokerResult registerBroker(
        final String clusterName,
        final String brokerAddr,
        final String backUpBrokerAddr,
        final String brokerName,
        final long brokerId,
        final String haServerAddr,
        final TopicConfigSerializeWrapper topicConfigWrapper,
        final List<String> filterServerList,
        final Channel channel) {

        /*
         * 注册结果，如果是备节点，会返回它的master地址，否则result返回的字段全为null
         */
        RegisterBrokerResult result = new RegisterBrokerResult();
        try {
            try {
                this.lock.writeLock().lockInterruptibly();

                Set<String> brokerNames = this.clusterAddrTable.get(clusterName);
                if (null == brokerNames) {
                    brokerNames = new HashSet<>();
                    this.clusterAddrTable.put(clusterName, brokerNames);
                }
                brokerNames.add(brokerName);
                //是否是第一次注册
                boolean registerFirst = false;

                BrokerData brokerData = this.brokerAddrTable.get(brokerName);
                if (null == brokerData) {
                    //标记是第一次注册
                    registerFirst = true;

                    brokerData = new BrokerData(clusterName, brokerName, new HashMap<Long, String>(),new HashMap<Long, String>());
                    this.brokerAddrTable.put(brokerName, brokerData);
                }
                //old地址
                String oldAddr = brokerData.getBrokerAddrs().put(brokerId, brokerAddr);
                brokerData.getBackUpBrokerAddrs().put(brokerId, backUpBrokerAddr);

                //如果oldAddr是null，也说明是第一次注册
                registerFirst = registerFirst || (null == oldAddr);
                //如果是Master节点
                if (null != topicConfigWrapper && MixAll.MASTER_ID == brokerId) {
                    //如果有改变或者是第一次注册
                    if (this.isBrokerTopicConfigChanged(brokerAddr, topicConfigWrapper.getDataVersion()) || registerFirst) {
                        ConcurrentMap<String, TopicConfig> tcTable = topicConfigWrapper.getTopicConfigTable();
                        if (tcTable != null) {
                            for (Map.Entry<String, TopicConfig> entry : tcTable.entrySet()) {
                                this.createAndUpdateQueueData(brokerName, entry.getValue());
                            }
                        }
                    }
                }

                /*
                 * 存活的Broker信息
                 */
                BrokerLiveInfo prevBrokerLiveInfo = this.brokerLiveTable.put(brokerAddr,
                    new BrokerLiveInfo(
                        System.currentTimeMillis(),
                        topicConfigWrapper.getDataVersion(),
                        channel,
                        haServerAddr));

                if (null == prevBrokerLiveInfo) {
                    log.info("new broker registered, {} HAServer: {}", brokerAddr, haServerAddr);
                }

                //TODO
                if (filterServerList != null) {
                    if (filterServerList.isEmpty()) {
                        this.filterServerTable.remove(brokerAddr);
                    } else {
                        this.filterServerTable.put(brokerAddr, filterServerList);
                    }
                }
                //如果是备节点
                if (MixAll.MASTER_ID != brokerId) {
                    //主节点地址
                    String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
                    if (masterAddr != null) {
                        BrokerLiveInfo brokerLiveInfo = this.brokerLiveTable.get(masterAddr);
                        if (brokerLiveInfo != null) {
                            //设置备节点地址
                            result.setHaServerAddr(brokerLiveInfo.getHaServerAddr());
                            //设置主节点地址
                            result.setMasterAddr(masterAddr);
                        }
                    }
                }
            } finally {
                this.lock.writeLock().unlock();
            }
        } catch (Exception e) {
            log.error("registerBroker Exception", e);
        }

        return result;
    }

    public  RouteInfoManager();

}