Search in sources :

Example 1 with BrokerCluster

use of pers.cy.iris.commons.cluster.BrokerCluster 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();
}
Also used : Broker(pers.cy.iris.commons.cluster.Broker) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BrokerGroup(pers.cy.iris.commons.cluster.BrokerGroup) BrokerCluster(pers.cy.iris.commons.cluster.BrokerCluster)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Broker (pers.cy.iris.commons.cluster.Broker)1 BrokerCluster (pers.cy.iris.commons.cluster.BrokerCluster)1 BrokerGroup (pers.cy.iris.commons.cluster.BrokerGroup)1