//log("Transferring identity of agent "+agentID+" from "+src.getName()+" to "+dest.getName(), 2);
if(myLogger.isLoggable(Logger.FINE))
myLogger.log(Logger.FINE,"Transferring identity of agent "+agentID+" from "+src.getName()+" to "+dest.getName());
MainContainer impl = myContainer.getMain();
if(impl != null) {
AgentDescriptor ad = impl.acquireAgentDescriptor(agentID);
if (ad != null) {
try {
AgentMobilitySlice srcSlice = (AgentMobilitySlice)getSlice(src.getName());
AgentMobilitySlice destSlice = (AgentMobilitySlice)getSlice(dest.getName());
boolean srcReady = false;
boolean destReady = false;
try {
srcReady = srcSlice.prepare();
}
catch(IMTPException imtpe) {
srcSlice = (AgentMobilitySlice)getFreshSlice(src.getName());
srcReady = srcSlice.prepare();
}
//log("Source "+src.getName()+" "+srcReady, 2);
if(myLogger.isLoggable(Logger.FINE))
myLogger.log(Logger.FINE,"Source "+src.getName()+" "+srcReady);
try {
destReady = destSlice.prepare();
}
catch(IMTPException imtpe) {
destSlice = (AgentMobilitySlice)getFreshSlice(dest.getName());
destReady = destSlice.prepare();
}
//log("Destination "+dest.getName()+" "+destReady, 2);
if(myLogger.isLoggable(Logger.FINE))
myLogger.log(Logger.FINE,"Destination "+dest.getName()+" "+destReady);
if(srcReady && destReady) {
// FIXME: We should issue a TRANSFER_IDENTITY V-Command to allow migration tracing and prevention
// Commit transaction
movedAgent(agentID, (ContainerID)src, (ContainerID)dest);
replicationHandle.invokeReplicatedMethod("movedAgent", new Object[]{agentID, (ContainerID)src, (ContainerID)dest});
return true;
}
else {
// Problems on a participant slice: abort transaction
return false;
}
}
catch(Exception e) {
// Link failure: abort transaction
//log("Link failure!", 2);
if(myLogger.isLoggable(Logger.WARNING))
myLogger.log(Logger.WARNING,"Link failure!");
return false;
}
finally {
impl.releaseAgentDescriptor(agentID);
}
}
else {
throw new NotFoundException("Agent agentID not found");
}