try {
//#J2ME_EXCLUDE_BEGIN
//Register the clone in the Code Locator in the case its father is a jar agent
String containerName = myContainer.getID().getName();
Agent agent = myContainer.acquireLocalAgent(agentID);
String codeContainerName = getClassSite(agent);
myContainer.releaseLocalAgent(agentID);
//Check if the code is in the same container or in a remote one.
AgentManagementService amSrv = (AgentManagementService) myFinder.findService(AgentManagementService.NAME);
CodeLocator codeLocator = amSrv.getCodeLocator();
if (codeContainerName == null) codeContainerName = containerName;
if (containerName.equals(codeContainerName)) {
if (codeLocator.isRegistered(agentID)) {
if(myLogger.isLoggable(Logger.FINE)) {
myLogger.log(Logger.FINE," adding clone " + newName + " to code locator.");
}
codeLocator.cloneAgent(agentID, new AID(newName,AID.ISLOCALNAME));
}
} else {
//Send a CLONE_CODE_LOCATOR_ENTRY command to the container with the agent code.
AgentMobilitySlice codeSlice = (AgentMobilitySlice) getSlice(codeContainerName);
try {
codeSlice.cloneCodeLocatorEntry(agentID, new AID(newName,AID.ISLOCALNAME));
} catch (IMTPException imtpe) {
// Try to get a newer slice and repeat...
codeSlice = (AgentMobilitySlice) getSlice(codeContainerName);
codeSlice.cloneCodeLocatorEntry(agentID, new AID(newName,AID.ISLOCALNAME));
}
}
//#J2ME_EXCLUDE_END
//log("Cloning agent " + agentID + " on container " + where.getName(), 1);
if(myLogger.isLoggable(Logger.CONFIG))
myLogger.log(Logger.CONFIG,"Cloning agent " + agentID + " on container " + where.getName());
Agent a = myContainer.acquireLocalAgent(agentID);
if (a == null) {
//System.out.println("Internal error: handleClone() called with a wrong name (" + agentID + ") !!!");
if(myLogger.isLoggable(Logger.SEVERE))
myLogger.log(Logger.SEVERE,"Internal error: handleClone() called with a wrong name (" + agentID + ") !!!");
return;