@Override
public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification {
UnitConfig agentUnitConfig = entry.getMessage();
if (!agentUnitConfig.hasPlacementConfig()) {
throw new NotAvailableException("agent.placementConfig");
}
if (!agentUnitConfig.getPlacementConfig().hasLocationId() || agentUnitConfig.getPlacementConfig().getLocationId().isEmpty()) {
throw new NotAvailableException("agent.placementConfig.locationId");
}
if (!agentUnitConfig.getAgentConfig().hasAgentClassId() || agentUnitConfig.getAgentConfig().getAgentClassId().isEmpty()) {
throw new NotAvailableException("agent.agentClassId");
}
Scope newScope = ScopeGenerator.generateAgentScope(agentUnitConfig, agentClassRegistry.get(agentUnitConfig.getAgentConfig().getAgentClassId()).getMessage(), locationRegistry.getMessage(agentUnitConfig.getPlacementConfig().getLocationId()));
if (!ScopeGenerator.generateStringRep(agentUnitConfig.getScope()).equals(ScopeGenerator.generateStringRep(newScope))) {
if (agentMap.containsKey(ScopeGenerator.generateStringRep(newScope))) {
throw new InvalidStateException("Two agents [" + agentUnitConfig + "][" + agentMap.get(ScopeGenerator.generateStringRep(newScope)) + "] are registered with the same label and location");
} else {
agentMap.put(ScopeGenerator.generateStringRep(newScope), agentUnitConfig);
entry.setMessage(agentUnitConfig.toBuilder().setScope(newScope));
throw new EntryModification(entry, this);
}
}
}