com.alibaba.rocketmq.common.protocol.route.BrokerData Maven / Gradle / Ivy
/**
* $Id: BrokerData.java 1835 2013-05-16 02:00:50Z shijia.wxr $
*/
package com.alibaba.rocketmq.common.protocol.route;
import com.alibaba.rocketmq.common.MixAll;
import java.util.HashMap;
/**
* @author shijia.wxr
* @since 2013-7-2
*/
public class BrokerData implements Comparable {
private String cluster;
private String brokerName;
private HashMap brokerAddrs;
/**
* 优先获取Master,如果没有Master尝试找Slave
*/
public String selectBrokerAddr() {
String value = this.brokerAddrs.get(MixAll.MASTER_ID);
if (null == value) {
for (Long key : this.brokerAddrs.keySet()) {
return this.brokerAddrs.get(key);
}
}
return value;
}
public String getBrokerName() {
return brokerName;
}
public void setBrokerName(String brokerName) {
this.brokerName = brokerName;
}
public HashMap getBrokerAddrs() {
return brokerAddrs;
}
public void setBrokerAddrs(HashMap brokerAddrs) {
this.brokerAddrs = brokerAddrs;
}
public String getCluster() {
return cluster;
}
public void setCluster(String cluster) {
this.cluster = cluster;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((brokerAddrs == null) ? 0 : brokerAddrs.hashCode());
result = prime * result + ((brokerName == null) ? 0 : brokerName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BrokerData other = (BrokerData) obj;
if (brokerAddrs == null) {
if (other.brokerAddrs != null)
return false;
}
else if (!brokerAddrs.equals(other.brokerAddrs))
return false;
if (brokerName == null) {
if (other.brokerName != null)
return false;
}
else if (!brokerName.equals(other.brokerName))
return false;
return true;
}
@Override
public String toString() {
return "BrokerData [brokerName=" + brokerName + ", brokerAddrs=" + brokerAddrs + "]";
}
@Override
public int compareTo(BrokerData o) {
return this.brokerName.compareTo(o.getBrokerName());
}
}