}
}
for (Map.Entry<String, AgentInfo> each : agentInDBMap.entrySet()) {
String agentKey = each.getKey();
AgentInfo agentInfo = each.getValue();
AgentControllerIdentityImplementation agentIdentity = attachedAgentMap.remove(agentKey);
if (agentIdentity == null) {
// this agent is not attached to controller
agentInfo.setState(AgentControllerState.INACTIVE);
stateUpdatedAgents.add(agentInfo);
} else if (!hasSameInfo(agentInfo, agentIdentity)) {
agentInfo.setRegion(agentIdentity.getRegion());
agentInfo.setPort(agentManager.getAgentConnectingPort(agentIdentity));
agentInfo.setVersion(agentManager.getAgentVersion(agentIdentity));
updatedAgents.add(agentInfo);
} else if (!hasSameState(agentInfo, agentIdentity)) {
agentInfo.setState(agentManager.getAgentState(agentIdentity));
stateUpdatedAgents.add(agentInfo);
}
}
// step2. check all attached agents, whether they are new, and not saved
// in DB.
for (AgentControllerIdentityImplementation agentIdentity : attachedAgentMap.values()) {
final AgentInfo agentInfo = fillUp(new AgentInfo(), agentIdentity);
newAgents.add(agentInfo);
}
cachedLocalAgentService.updateAgents(newAgents, updatedAgents, stateUpdatedAgents, removedAgents);
if (!newAgents.isEmpty() || !removedAgents.isEmpty()) {
expireLocalCache();