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*/ } } }
public void notifyBecomeMaster(AID masterAid) throws IMTPException { GenericCommand cmd = new GenericCommand(H_NOTIFYBECOMEMASTER, AgentReplicationService.NAME, null); cmd.addParam(masterAid); try { Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Error accessing remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#resetEnvironmentInstanceNextParts() */ @Override public void resetEnvironmentInstanceNextParts() throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_RESET_ENVIRONMENT_NEXT_PARTS, SimulationService.NAME, null); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#setPauseSimulation(boolean) */ @Override public void setPauseSimulation(boolean pauseSimulation) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_PAUSE_SIMULATION, SimulationService.NAME, null); cmd.addParam(pauseSimulation); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
public void replicaCreationRequested(AID virtualAid, AID replicaAid) throws IMTPException { GenericCommand cmd = new GenericCommand(H_REPLICACREATIONREQUESTED, AgentReplicationService.NAME, null); cmd.addParam(virtualAid); cmd.addParam(replicaAid); try { Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Error accessing remote node", se); } }
@Override public void stopSimulationAgents() throws IMTPException { try { GenericCommand cmd = new GenericCommand(SERVICE_STOP_SIMULATION_AGENTS, SimulationService.NAME, null); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#setAgentMigration(java.util.Vector) */ @Override public void setAgentMigration(Vector<AID_Container> transferAgents) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SERVICE_SET_AGENT_MIGRATION, SimulationService.NAME, null); cmd.addParam(transferAgents); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
@Override public long getRemoteTime() throws IMTPException { try { GenericCommand cmd = new GenericCommand(SERVICE_SYNCH_GET_REMOTE_TIME, SimulationService.NAME, null); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } return (Long) result; } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#setManagerAgent(agentgui.simulationService.transaction.EnvironmentManagerDescription) */ @Override public void setManagerAgent(EnvironmentManagerDescription envManager) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_SET_MANAGER_AGENT, SimulationService.NAME, null); cmd.addParam(envManager); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#getEnvironmentInstanceNextParts() */ @SuppressWarnings("unchecked") @Override public Hashtable<AID, Object> getEnvironmentInstanceNextParts() throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_GET_ENVIRONMENT_NEXT_PARTS, SimulationService.NAME, null); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } Hashtable<AID, Object> nextParts = (Hashtable<AID, Object>) result; return nextParts; } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#notifyManagerPutAgentAnswers(java.util.Hashtable) */ @Override public void notifyManagerPutAgentAnswers(Hashtable<AID, Object> allAgentAnswers) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_NOTIFY_MANAGER_PUT_AGENT_ANSWERS, SimulationService.NAME, null); cmd.addParam(allAgentAnswers); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#setAnswersExpected(int) */ @Override public void setAnswersExpected(int answersExpected) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_SET_ANSWERS_EXPECTED, SimulationService.NAME, null); cmd.addParam(answersExpected); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
public ContainerID getAgentLocation(AID aid) throws IMTPException, NotFoundException { GenericCommand cmd = new GenericCommand(H_GETAGENTLOCATION, AgentReplicationService.NAME, null); cmd.addParam(aid); try { Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof NotFoundException) { throw (NotFoundException) result; } else if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } return (ContainerID) result; } catch (ServiceException se) { throw new IMTPException("Error accessing remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#notifyManager(agentgui.simulationService.transaction.EnvironmentNotification) */ @Override public boolean notifyManager(EnvironmentNotification notification) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_NOTIFY_MANAGER, SimulationService.NAME, null); cmd.addParam(notification); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } return (Boolean) result; } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
public void synchReplication(GlobalReplicationInfo info) throws IMTPException { GenericCommand cmd = new GenericCommand(H_SYNCHREPLICATION, AgentReplicationService.NAME, null); cmd.addParam(info.getVirtual()); cmd.addParam(info.getMaster()); cmd.addParam(info.getReplicationMode()); cmd.addParam(info.getAllReplicas()); try { Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Error accessing remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#setRemoteTimeDiff(long) */ @Override public void setRemoteTimeDiff(long timeDifference) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SERVICE_SYNCH_SET_TIME_DIFF, SimulationService.NAME, null); cmd.addParam(timeDifference); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#displayAgentNotification(agentgui.simulationService.transaction.EnvironmentNotification) */ @Override public void displayAgentNotification(EnvironmentNotification notification) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SERVICE_DISPLAY_AGENT_NOTIFICATION, SimulationService.NAME, null); cmd.addParam(notification); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }
public void notifyReplicaRemoved(AID masterAid, AID removedReplica, Location where) throws IMTPException { GenericCommand cmd = new GenericCommand(H_NOTIFYREPLICAREMOVED, AgentReplicationService.NAME, null); cmd.addParam(masterAid); cmd.addParam(removedReplica); cmd.addParam(where); try { Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Error accessing remote node", se); } }
public void invokeAgentMethod(AID aid, String methodName, Object[] arguments) throws IMTPException, ServiceException, NotFoundException { GenericCommand cmd = new GenericCommand(H_INVOKEAGENTMETHOD, AgentReplicationService.NAME, null); cmd.addParam(aid); cmd.addParam(methodName); cmd.addParam(arguments); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof NotFoundException) { throw (NotFoundException) result; } else if (result instanceof ServiceException) { throw (ServiceException) result; } else if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } }
/* (non-Javadoc) * @see agentgui.simulationService.SimulationServiceSlice#setEnvironmentModel(agentgui.simulationService.environment.EnvironmentModel) */ @Override public void setEnvironmentModel(EnvironmentModel envModel, boolean notifySensorAgents) throws IMTPException { try { GenericCommand cmd = new GenericCommand(SIM_SET_ENVIRONMENT_MODEL, SimulationService.NAME, null); cmd.addParam(envModel); cmd.addParam(notifySensorAgents); Node n = getNode(); Object result = n.accept(cmd); if ((result != null) && (result instanceof Throwable)) { if (result instanceof IMTPException) { throw (IMTPException) result; } else { throw new IMTPException("An undeclared exception was thrown", (Throwable) result); } } } catch (ServiceException se) { throw new IMTPException("Unable to access remote node", se); } }