use of pers.cy.iris.commons.cluster.Broker in project iris by chicc999.
the class MetaManager method updateCluster.
private void updateCluster(List<Broker> brokers) {
Map<String, BrokerCluster> current = new HashMap<String, BrokerCluster>();
Broker source = this.broker;
Map<String, Broker> currentBrokers = new HashMap<String, Broker>(brokers.size());
Map<String, BrokerGroup> currentGroups = new HashMap<String, BrokerGroup>(brokers.size());
BrokerGroup group;
boolean isMatch = false;
// 遍历Broker
for (Broker broker : brokers) {
// 存放当前Broker
currentBrokers.put(broker.getName(), broker);
// 获取分组
group = currentGroups.get(broker.getGroup());
if (group == null) {
// 分组不存在,则创建
group = new BrokerGroup();
group.setGroup(broker.getGroup());
currentGroups.put(broker.getGroup(), group);
}
// 添加到分组中
group.addBroker(broker);
if (broker.equals(source)) {
// 等于当前Broker
source.setPermission(broker.getPermission());
source.setGroup(broker.getGroup());
source.setAlias(broker.getAlias());
source.setDataCenter(broker.getDataCenter());
source.setSyncMode(broker.getSyncMode());
source.setRetryType(broker.getRetryType());
// source.setRole(broker.getRole());
if (broker.getReplicationPort() > 0) {
source.setReplicationPort(broker.getReplicationPort());
}
this.brokerGroup = group;
isMatch = true;
}
}
if (!isMatch) {
logger.error(String.format("broker config maybe error,can not find %s", this.broker));
}
this.brokers = currentBrokers;
this.groups = currentGroups;
clusters.clear();
}
use of pers.cy.iris.commons.cluster.Broker in project iris by chicc999.
the class MetaManager method beforeStart.
@Override
public void beforeStart() throws Exception {
if (zkClient == null) {
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(metaConfig.getZookeeperBaseSleepTimeMs(), metaConfig.getZookeeperMaxRetries());
zkClient = CuratorFrameworkFactory.builder().connectString(metaConfig.getConnectionString()).retryPolicy(retryPolicy).connectionTimeoutMs(metaConfig.getConnectionTimeout()).sessionTimeoutMs(metaConfig.getSessionTimeout()).namespace(metaConfig.getNameSpace()).build();
}
// 初始化本地broker
if (this.broker == null) {
this.broker = new Broker(System.getProperty(ServerType.Broker.nameKey()));
}
// 初始化本地所在brokerGroup
if (this.brokerGroup == null) {
this.brokerGroup = new BrokerGroup();
}
this.brokerGroup.addBroker(this.broker);
}
Aggregations