/** * Adds one vote to a candidate in the elect */ public void vote(ServerResource agent, CollectionSettingName name, Serializable value) { vote(agent, new CollectionSettingGroup(name, value, agent)); }
@Override public String toString() { return getServer() + ": " + getPlugins(); } }
/** * Add a global CollectionSettingGroup, which will use the global prefix */ public void addGlobalCollectionSettings(CollectionSettingGroup group) { String key = GLOBAL_SCOPE_PREFIX + "." + COLLECTION_SETTING_PREFIX + "." + group.getName().getKey(); configuration.put(key, group.getCandidate().getValue()); }
/** * Get the settings which are either shared by all agents, or added specifically to * the global group */ public List<CollectionSettingGroup> getGlobalResults() { if (globalSettings == null || localSettings == null) { tally(); } return new LinkedList<CollectionSettingGroup>(globalSettings); }
@Override protected boolean isEquivalent (CollectionSettingCandidate o) { if (!super.isEquivalent(o)) { return false; } // we know we can cast since equals calls us CollectionSettingGroup other = (CollectionSettingGroup) o; return ListUtil.compareCollections(getInternalAgents(), other.getInternalAgents()); }
@Override public int hashCode() { return super.hashCode() + ListUtil.size(getInternalAgents()) // using size since order may vary ; } }
@Autowired public PluginRepo(PluginSet dashboardPluginSet, AgentRepo agentRepo) { this.agentRepo = agentRepo; this.dashPlugins = dashboardPluginSet; me = dashboardPluginSet.getServer(); }
private void vote(ServerResource agent, CollectionSettingGroup vote) { CollectionSettingCandidate candidate = vote.getCandidate(); CollectionSettingGroup current = elect.get(candidate); CollectionSettingGroup result; if (current != null) { result = current.merge(vote); } else { result = vote; } uniqueAgents.add(agent); elect.put(candidate, result); }
public CollectionSettingCandidate getCandidate() { return new CollectionSettingCandidate(name, value); }
public List<ServerResource> getAgents() { return new LinkedList<ServerResource>(getInternalAgents()); }
/** * Rig the election by forcing a number of settings into the global group */ public void forceGlobalSettings(Map<CollectionSettingName, Serializable> settings) { for (CollectionSettingName name : settings.keySet()) { forceGlobalSetting(name, settings.get(name)); } }
@Override public boolean equals(Object o) { if (o == null) return false; if (this == o) return true; if (getClass() != o.getClass()) return false; return isEquivalent((CollectionSettingCandidate) o); }
/** * Add a CollectionSettingGroup to this configuration object, scoped by agent. Each setting * will be prefixed with the agent name to which the setting applies. */ public void addAgentCollectionSettings(CollectionSettingGroup group) { for (ServerResource agent : group.getAgents()) { addAgentCollectionSettings(group, agent); } }
@Override public int hashCode() { // do not use plugins hash code since it may vary according to order of plugins rather than content return ObjectUtil.hashCode(getServer()) + ListUtil.size(getPlugins()) ; }
/** * Get the settings which are unique to some subset of agents */ public List<CollectionSettingGroup> getLocalResults() { if (localSettings == null || globalSettings == null) { tally(); } return new LinkedList<CollectionSettingGroup>(localSettings); } }
/** * Rig the election by forcing a setting into the global group */ public void forceGlobalSetting(CollectionSettingName name, Serializable value) { forcedGlobal.add(new CollectionSettingCandidate(name, value)); }