Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

See Class diagramm for HaActiveServiceResolver.

Pic#5 - Class diagramm 

See initial implementattion of HaActiveServiceResolver.

Code Block
languagejava
titleHaBaseStrategyHostMapper
linenumberstrue
public class HaActiveServiceResolver {
    private int currentServiceIndex;
    private Map<ServiceRole, List<String>> servicesMap = new HashMap<ServiceRole, List<String>>();
    private static HaActiveServiceResolver instance = new HaActiveServiceResolver();
    private FailoverStrategy strategy;
    private HaActiveServiceResolver(){
        //TODO: initialize services here with data from xml file
        servicesMap.put(ServiceRole.WEBHDFS, new ArrayList<String>());
        servicesMap.put(ServiceRole.NAMENODE, new ArrayList<String>());
        strategy = new HaBaseStrategy();
        currentServiceIndex = 0;
    }
    public  synchronized void resetStateToFailOver(ServiceRole serviceRole){
        currentServiceIndex = strategy.getActiveServiceIndex(instance.currentServiceIndex, instance.servicesMap.get(serviceRole));
    }
    public static HaActiveServiceResolver getInstance(){
        return instance;
    }
    public String getActiveService(ServiceRole serviceRole){
        return servicesMap.get(serviceRole).get(instance.currentServiceIndex);
    }
}

 

See initial implementattion HaBaseStrategy.

Code Block
languagejava
titleHaBaseStrategyHostMapper
linenumberstrue
public class HaBaseStrategy implements FailoverStrategy {
    @Override
    public int getActiveServiceIndex(int currentIndex, List<String> services) {
        int newIndex = currentIndex + 1;
        if(newIndex > services.size()){
            newIndex = 0;
        }
        return newIndex;
    }
}