Search in sources :

Example 1 with ReadStrategy

use of com.ctrip.platform.dal.dao.datasource.cluster.strategy.ReadStrategy in project dal by ctripcorp.

the class ReadSlavesFirstStrategy method dalHintsRoute.

protected HostSpec dalHintsRoute(DalHints dalHints) {
    RouteStrategyEnum strategyEnum = dalHints.getRouteStrategy();
    dalHints.cleanRouteStrategy();
    if (routeStrategies.get(strategyEnum) == null) {
        synchronized (routeStrategies) {
            if (routeStrategies.get(strategyEnum) == null) {
                try {
                    ReadStrategy tempRouteStrategy = (ReadStrategy) Class.forName(strategyEnum.getClazz()).newInstance();
                    tempRouteStrategy.init(hostSpecs, strategyProperties);
                    routeStrategies.put(strategyEnum, tempRouteStrategy);
                } catch (Throwable e) {
                }
            }
        }
    }
    return routeStrategies.get(strategyEnum).pickRead(dalHints);
}
Also used : ReadStrategy(com.ctrip.platform.dal.dao.datasource.cluster.strategy.ReadStrategy) RouteStrategyEnum(com.ctrip.framework.dal.cluster.client.cluster.RouteStrategyEnum)

Aggregations

RouteStrategyEnum (com.ctrip.framework.dal.cluster.client.cluster.RouteStrategyEnum)1 ReadStrategy (com.ctrip.platform.dal.dao.datasource.cluster.strategy.ReadStrategy)1