/** Start agent scheduler thread. Should be called once at init time. */ public synchronized void startThread() { if (agentThread == null) { agentThread = new AgentThread(getName()); agentThread.start(); // causes the run method to execute in the AgentThread below } else { agentThread.interrupt(); // don't worry about this for now } }
/* (non-Javadoc) * @see flap.messaging.IMessageQueue#addMessage(flap.messaging.Message) */ @Override public synchronized void addMessage(Message messaggio) { if (messaggio == null) return; // skip null messages // store the message into the right queue depending on its // priority logger.debug("[MessageQueue] Storing the message into the right queue"); deliverMessageIntoTheRightQueue(messaggio); // get a thread to handle this message logger.debug("[MessageQueue] Asking a thread for processing the message"); AgentThread thread = AgentThread.getThread(); thread.handleMessage(this, ownerProxy.getMyOwningAgent()); }
// In this implementation, nothing calls stopThread(). // When we have a user interface to agents, this can be called. public void stopThread() { if (agentThread != null) { agentThread.stopAgent(); agentThread = null; } }