@Override
public void handleEvent(SocialEvent e, Object... args) {
logger.debug("Updating for Initiator, " + e);
if (e.getElementChanged().getElType() == SocialStateElementType.LOGICAL_EXPRESSION
&& e.getElementChanged().toString().contains("propose")) {
CAMessage cfp = initiator.receive(ACLMessage.PROPOSE);
Proposal prop = (Proposal) (cfp.getContents());
if (!maximumReached) {
proposals.add(prop);
logger.debug("Added Proposal, proposals size: "
+ proposals.size());
if (proposals.size() >= maximumProposals) {
maximumReached = true;
// ho raccolto un numero di richieste sufficiente
// criterio di scelta, reasoning
// per semplicit�, scelgo la prima
initiator.accept(proposals.get(0));
for (int i = 1; i < proposals.size(); i++) {
initiator.reject(proposals.get(i));
}
}
} else {
logger.debug("No more proposal allowed, sending reject.");
initiator.reject(prop);
}
} else if (e.getElementChanged().getElType() == SocialStateElementType.LOGICAL_EXPRESSION
&& e.getElementChanged().toString().contains("refuse")) {
logger.debug("Refusal received.");
} else if (eventIsDone(e)) {
CAMessage done = initiator.receive(ACLMessage.INFORM);
t = (Task) (done.getContents());
logger.debug("INTERACTION SUCCESSFUL, " + t.getResult());
} else if (eventIsFailure(e)) {
CAMessage failure = initiator.receive(ACLMessage.FAILURE);
logger.debug("Received failure.");
}
}