From f115b528668736544f5a8632670655f875145f72 Mon Sep 17 00:00:00 2001 From: Jaskey Date: Sat, 27 May 2017 11:24:02 +0800 Subject: [PATCH] [ROCKETMQ-200]-Cluster name is always missing when fetch ClusterInfo from name server closes apache/incubator-rocketmq#105 --- .../rocketmq/common/protocol/route/BrokerData.java | 14 +++++++++++--- .../namesrv/routeinfo/RouteInfoManager.java | 10 ++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java b/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java index 612e5b41..9d868ae0 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/route/BrokerData.java @@ -15,9 +15,7 @@ * limitations under the License. */ -/** - * $Id: BrokerData.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ - */ + package org.apache.rocketmq.common.protocol.route; import java.util.HashMap; @@ -29,6 +27,16 @@ public class BrokerData implements Comparable { private String brokerName; private HashMap brokerAddrs; + public BrokerData() { + + } + + public BrokerData(String cluster, String brokerName, HashMap brokerAddrs) { + this.cluster = cluster; + this.brokerName = brokerName; + this.brokerAddrs = brokerAddrs; + } + public String selectBrokerAddr() { String value = this.brokerAddrs.get(MixAll.MASTER_ID); if (null == value) { diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java index 16b7847a..5a953a9e 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java @@ -125,11 +125,7 @@ public class RouteInfoManager { BrokerData brokerData = this.brokerAddrTable.get(brokerName); if (null == brokerData) { registerFirst = true; - brokerData = new BrokerData(); - brokerData.setBrokerName(brokerName); - HashMap brokerAddrs = new HashMap(); - brokerData.setBrokerAddrs(brokerAddrs); - + brokerData = new BrokerData(clusterName, brokerName, new HashMap()); this.brokerAddrTable.put(brokerName, brokerData); } String oldAddr = brokerData.getBrokerAddrs().put(brokerId, brokerAddr); @@ -381,9 +377,7 @@ public class RouteInfoManager { for (String brokerName : brokerNameSet) { BrokerData brokerData = this.brokerAddrTable.get(brokerName); if (null != brokerData) { - BrokerData brokerDataClone = new BrokerData(); - brokerDataClone.setBrokerName(brokerData.getBrokerName()); - brokerDataClone.setBrokerAddrs((HashMap) brokerData + BrokerData brokerDataClone = new BrokerData(brokerData.getCluster(), brokerData.getBrokerName(), (HashMap) brokerData .getBrokerAddrs().clone()); brokerDataList.add(brokerDataClone); foundBrokerData = true; -- GitLab