Search in sources :

Example 1 with BrokerGroup

use of pers.cy.iris.commons.cluster.BrokerGroup 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);
}
Also used : Broker(pers.cy.iris.commons.cluster.Broker) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) BrokerGroup(pers.cy.iris.commons.cluster.BrokerGroup)

Example 2 with BrokerGroup

use of pers.cy.iris.commons.cluster.BrokerGroup 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

Broker (pers.cy.iris.commons.cluster.Broker)2 BrokerGroup (pers.cy.iris.commons.cluster.BrokerGroup)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)1 BrokerCluster (pers.cy.iris.commons.cluster.BrokerCluster)1