private void bornAgent( AID name, ContainerID cid, JADEPrincipal principal, Credentials credentials) throws NameClashException, NotFoundException { MainContainer impl = myContainer.getMain(); if (impl != null) { // Retrieve the ownership from the credentials String ownership = "NONE"; if (credentials != null) { JADEPrincipal ownerPr = credentials.getOwner(); if (ownerPr != null) { ownership = ownerPr.getName(); } } try { // If the name is already in the GADT, throws NameClashException impl.bornAgent(name, cid, principal, ownership, false); } catch (NameClashException nce) { // #CUSTOMJ2SE_EXCLUDE_BEGIN try { ContainerID oldCid = impl.getContainerID(name); if (oldCid != null) { Node n = impl.getContainerNode(oldCid).getNode(); // Perform a non-blocking ping to check... n.ping(false); // Ping succeeded: rethrow the NameClashException throw nce; } else { // The old agent is registered with the AMS, but does not live in the platform --> // cannot check if it still exists throw nce; } } catch (NameClashException nce2) { // This is the re-thrown NameClashException --> let it through throw nce2; } catch (Exception e) { // Either the old agent disappeared in the meanwhile or the Ping failed: forcibly // replace the old agent... impl.bornAgent(name, cid, principal, ownership, true); } // #CUSTOMJ2SE_EXCLUDE_END /*#CUSTOMJ2SE_INCLUDE_BEGIN try { //System.out.println("Replacing old agent "+name.getName()); if(myLogger.isLoggable(Logger.INFO)) myLogger.log(Logger.INFO,"Replacing old agent "+name.getName()); dyingAgents.add(name); ((jade.core.AgentManager) impl).kill(name, principal, credentials); waitUntilDead(name); impl.bornAgent(name, cid, principal, ownership, false); } catch (Exception e) { dyingAgents.remove(name); impl.bornAgent(name, cid, principal, ownership, true); } #CUSTOMJ2SE_INCLUDE_END*/ } } }