refactor
This commit is contained in:
coderfengyun 2014-07-19 10:08:04 +08:00
parent da70ff117b
commit bd25e36f72
1 changed files with 14 additions and 20 deletions

View File

@ -49,29 +49,23 @@ public class AgentService {
}
public boolean addAgentToPool(Agent agentWithoutId) {
/* synchronized (this.getAgentRepository().getAddDeleteLock()) {*/
if (!this.getAgentRepository().attach(
Agent.createAgentWithoutId(agentWithoutId))) {
return false;
}
Agent agent = this.getAgentRepository().getAgentBy(
agentWithoutId.getHostName());
if (agent == null) {
return false;
}
this.getHighAvailablePool().add(agent);
return true;
// }
if (!this.getAgentRepository().attach(
Agent.createAgentWithoutId(agentWithoutId))) {
return false;
}
Agent agent = this.getAgentRepository().getAgentBy(
agentWithoutId.getHostName());
if (agent == null) {
return false;
}
this.getHighAvailablePool().add(agent);
return true;
}
public boolean removeAgentFromPool(int agentId) {
// TODO: check if the agent is idle
// synchronized (this.getAgentRepository().getAddDeleteLock()) {
this.getHighAvailablePool().remove(
getAgentRepository().getEntity(agentId));
return this.getAgentRepository().detach(agentId);
// }
this.getHighAvailablePool().remove(
getAgentRepository().getEntity(agentId));
return this.getAgentRepository().detach(agentId);
}
public List<Agent> loadAgentPoolFromDB() {