try {
agentManager.updateAgent(agentByName);
} catch (Exception e) {
log.warn("Could not update the agent in database", e);
throw new AgentRegistrationException(new WrappedRemotingException(e));
}
// if agent is re-registering in order to change its remote endpoint, destroy our old client.
if (!oldAddress.equals(request.getAddress()) || oldPort != request.getPort()
|| !oldRemoteEndpoint.equals(request.getRemoteEndpoint())) {
try {
final Agent oldAgent = new Agent();
oldAgent.setName(agentByName.getName());
oldAgent.setAddress(oldAddress);
oldAgent.setPort(oldPort);
oldAgent.setRemoteEndpoint(oldRemoteEndpoint);
agentManager.destroyAgentClient(oldAgent);
} catch (Exception e) {
log.warn("Could not destroy the agent client - will continue but agent comm may be broken", e);
}
}
} else {
log.info("Got agent registration request for new agent: " + request.getName() + "[" + request.getAddress()
+ ":" + request.getPort() + "][" + request.getAgentVersion() + "]");
// the agent does not yet exist, we need to create it
try {
agentByName = new Agent(request.getName(), request.getAddress(), request.getPort(),
request.getRemoteEndpoint(), generateAgentToken());
agentByName.setServer(registeringServer);
agentManager.createAgent(agentByName);
} catch (Exception e) {
log.warn("Failed to create agent in database", e);
throw new AgentRegistrationException(new WrappedRemotingException(e));
}
}
// get existing or generate new server list for the registering agent
FailoverListComposite failoverList = getPartitionEventManager().agentPartitionEvent(