to perform certain actions (createAgent, killContainer) asynchronously
*/
private void sendFailureNotification(final Concept action, final Object key, final FIPAException fe) {
addBehaviour(new OneShotBehaviour(this) {
public void action() {
ACLMessage notification = null;
if (action instanceof CreateAgent) {
notification = (ACLMessage) pendingNewAgents.remove(key);
} else if (action instanceof KillContainer) {
notification = (ACLMessage) pendingRemovedContainers.remove(key);
}
if (notification != null) {
notification.setPerformative(ACLMessage.FAILURE);
// Compose the content
Action slAction = new Action(getAID(), action);
ContentElementList cel = new ContentElementList();
cel.add(slAction);
cel.add(fe);
try {
getContentManager().fillContent(notification, cel);
} catch (Exception e) {
// Should never happen
e.printStackTrace();
notification.setContent("(" + fe.getMessage() + ")");
}
send(notification);
}
}
});