Object[] params = cmd.getParams();
String name = (String)params[0];
String className = (String)params[1];
Object[]args = (Object[])params[2];
ContainerID cid = (ContainerID)params[3];
JADEPrincipal owner = (JADEPrincipal) params[4];
Credentials initialCredentials = (Credentials) params[5];
if(myLogger.isLoggable(Logger.CONFIG))
myLogger.log(Logger.CONFIG,"Source Sink consuming command REQUEST_CREATE. Name is "+name);
MainContainer impl = myContainer.getMain();
if(impl != null) {
AID agentID = new AID(name, AID.ISLOCALNAME);
AgentManagementSlice targetSlice = (AgentManagementSlice)getSlice(cid.getName());
if (targetSlice != null) {
try {
targetSlice.createAgent(agentID, className, args, owner, initialCredentials, AgentManagementSlice.CREATE_AND_START, cmd);
}
catch(IMTPException imtpe) {
// Try to get a newer slice and repeat...
targetSlice = (AgentManagementSlice)getFreshSlice(cid.getName());
targetSlice.createAgent(agentID, className, args, owner, initialCredentials, AgentManagementSlice.CREATE_AND_START, cmd);
}
}
else {
throw new NotFoundException("Container "+cid.getName()+" not found");
}
}
else {
// Do nothing for now, but could also route the command to the main slice, thus enabling e.g. AMS replication
}