Search in sources :

Example 1 with HostValidatorAware

use of com.ctrip.platform.dal.dao.datasource.cluster.strategy.multi.validator.HostValidatorAware in project dal by ctripcorp.

the class CompositeStrategyTransformer method visit.

@Override
public RouteStrategy visit(StrategyContext strategyContext) {
    try {
        if (strategyContext instanceof ZoneDividedStrategyContext) {
            ZoneDividedStrategyContext obStrategyContext = (ZoneDividedStrategyContext) strategyContext;
            CompositeRoundRobinStrategy localizedAccessStrategy = new CompositeRoundRobinStrategy();
            if (obStrategyContext.getZone() != null) {
                localizedAccessStrategy.setZone(obStrategyContext.getZone().toUpperCase());
            }
            for (Map.Entry<String, Set<HostSpec>> entry : obStrategyContext.entrySet()) {
                String zone = entry.getKey();
                Set<HostSpec> hostSpecSet = entry.getValue();
                RouteStrategy strategy = new ValidatorAwareRoundRobinStrategy();
                strategy.init(hostSpecSet, obStrategyContext.getStrategyProperties());
                if (strategy instanceof HostValidatorAware) {
                    ((HostValidatorAware) strategy).setHostValidator(obStrategyContext.getHostValidator());
                }
                localizedAccessStrategy.put(zone.toUpperCase(), strategy);
            }
            return localizedAccessStrategy;
        }
    } catch (Exception e) {
        throw new DalRuntimeException("generate error", e);
    }
    throw new DalRuntimeException("StrategyContext mismatch for " + strategyContext.getClass());
}
Also used : HostValidatorAware(com.ctrip.platform.dal.dao.datasource.cluster.strategy.multi.validator.HostValidatorAware) Set(java.util.Set) RouteStrategy(com.ctrip.platform.dal.dao.datasource.cluster.strategy.RouteStrategy) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) DalRuntimeException(com.ctrip.platform.dal.exceptions.DalRuntimeException) DalRuntimeException(com.ctrip.platform.dal.exceptions.DalRuntimeException) Map(java.util.Map)

Aggregations

HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)1 RouteStrategy (com.ctrip.platform.dal.dao.datasource.cluster.strategy.RouteStrategy)1 HostValidatorAware (com.ctrip.platform.dal.dao.datasource.cluster.strategy.multi.validator.HostValidatorAware)1 DalRuntimeException (com.ctrip.platform.dal.exceptions.DalRuntimeException)1 Map (java.util.Map)1 Set (java.util.Set)1