Package voldemort.routing

Source Code of voldemort.routing.RoutingStrategyFactory

package voldemort.routing;

import voldemort.VoldemortException;
import voldemort.cluster.Cluster;
import voldemort.store.StoreDefinition;

/**
* A factory that gets the appropriate {@link RoutingStrategy} for a given
* {@link RoutingStrategyType}.
*
*
*/
public class RoutingStrategyFactory {

    public RoutingStrategyFactory() {}

    public RoutingStrategy updateRoutingStrategy(StoreDefinition storeDef, Cluster cluster) {
        if(RoutingStrategyType.CONSISTENT_STRATEGY.equals(storeDef.getRoutingStrategyType())) {
            return new ConsistentRoutingStrategy(cluster,
                                                 storeDef.getReplicationFactor());
        } else if(RoutingStrategyType.TO_ALL_STRATEGY.equals(storeDef.getRoutingStrategyType())) {
            return new RouteToAllStrategy(cluster.getNodes());
        } else if(RoutingStrategyType.ZONE_STRATEGY.equals(storeDef.getRoutingStrategyType())) {
            return new ZoneRoutingStrategy(cluster,
                                           storeDef.getZoneReplicationFactor(),
                                           storeDef.getReplicationFactor());
        } else if(RoutingStrategyType.TO_ALL_LOCAL_PREF_STRATEGY.equals(storeDef.getRoutingStrategyType())) {
            return new RouteToAllLocalPrefStrategy(cluster.getNodes());
        } else {
            throw new VoldemortException("RoutingStrategyType:" + storeDef.getRoutingStrategyType()
                                         + " not handled by " + this.getClass());
        }
    }
}
TOP

Related Classes of voldemort.routing.RoutingStrategyFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.