Search in sources :

Example 1 with ShardStrategy

use of com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy in project dal by ctripcorp.

the class ClusterConfigImpl method innerGenerate.

private Cluster innerGenerate() {
    DefaultCluster cluster = (clusterType != ClusterType.DRC && unitStrategyId == null ? new DefaultCluster(this) : new DefaultDrcCluster(this));
    for (DatabaseShardConfig databaseShardConfig : databaseShardConfigs) cluster.addDatabaseShard(databaseShardConfig.generate());
    ShardStrategyProxy shardStrategy = new ShardStrategyProxy(defaultShardStrategy);
    for (ShardStrategy strategy : shardStrategies) shardStrategy.addStrategy(strategy);
    cluster.setShardStrategy(shardStrategy);
    cluster.setIdGeneratorConfig(idGeneratorConfig);
    cluster.setRouteStrategyConfig(routeStrategyConfig);
    LocalizationState localizationState = LocalizationState.NONE;
    if (clusterType == ClusterType.DRC)
        localizationState = LocalizationState.ACTIVE;
    else if (unitStrategyId != null)
        localizationState = LocalizationState.PREPARED;
    cluster.setLocalizationConfig(new LocalizationConfigImpl(unitStrategyId, zoneId, localizationState, drcConsistencyType));
    cluster.setCustomizedOption(customizedOption);
    cluster.setCustomProperties(customProperties);
    cluster.validate();
    return cluster;
}
Also used : ShardStrategy(com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy)

Example 2 with ShardStrategy

use of com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy in project dal by ctripcorp.

the class ClusterConfigXMLParser method parseCustomStrategy.

private void parseCustomStrategy(ClusterConfigImpl clusterConfig, Node strategyNode) {
    String className = getAttribute(strategyNode, CLASS);
    try {
        ShardStrategy strategy = instancingCustomShardStrategy(clusterConfig, className);
        parseShardStrategy(clusterConfig, strategyNode, strategy);
    } catch (Throwable t) {
        if (!clusterConfig.getCustomizedOption().isIgnoreShardingResourceNotFound()) {
            throw new ClusterRuntimeException("invalid custom strategy impl class", t);
        }
    }
}
Also used : ShardStrategy(com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy) ModShardStrategy(com.ctrip.framework.dal.cluster.client.sharding.strategy.ModShardStrategy) ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)

Aggregations

ShardStrategy (com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy)2 ClusterRuntimeException (com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)1 ModShardStrategy (com.ctrip.framework.dal.cluster.client.sharding.strategy.ModShardStrategy)1