private void shutdownAgent() { AgentServiceImpl oldAgentService = this.agentService; if (oldAgentService != null) { // Let the old agent be garbaged this.agentService = null; try { log.finer("stopping agent service"); oldAgentService.stopAgent(); } catch (Exception e) { log.log(Level.SEVERE, "could not stop old agent", e); } finally { exitSimulationLog(); } } }
public void run() { do { Message msg = null; try { msg = nextMessage(); Transportable content = msg.getContent(); if (content instanceof AdminContent) { handleAdminContent((AdminContent) content); } else if (content instanceof StartInfo) { // Setup a new agent instance and give it the simulation // start message. The new agent instance must be given // the address it has been assigned in this simulation. setupAgent(msg); } else if (content instanceof Alert) { handleAlert((Alert) content); } else if (agentService != null) { // If an agentService already is set up - send all messages // to it!! agentService.deliverToAgent(msg); if (content instanceof SimulationStatus) { SimulationStatus status = (SimulationStatus) content; if (status.isSimulationEnded()) { stopSimulation(agentService); } } } else { log.severe("No agent registered to receive " + msg); } } catch (ThreadDeath e) { log.log(Level.SEVERE, "message thread died", e); throw e; } catch (Throwable e) { log.log(Level.SEVERE, "could not handle message " + msg, e); } } while (true); }