@Override
public void handleEvent(SocialEvent e, Object... args) {
logger.debug("Updating for Initiator, "+e);
if (eventIsProposal(e)) {
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 (eventIsRefusal(e)) {
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.");
proposals.clear();
}