Finish DutchAuctionResponder.java (if everything works ok)
Esse commit está contido em:
@@ -15,6 +15,8 @@ public class DutchAuctionResponder extends SSResponder {
|
||||
public static final String RECEIVE_INFORM_START_OF_AUCTION = "Receive-Inform-Start-Of-Auction";
|
||||
public static final String RECEIVE_CFP = "Receive-Cfp";
|
||||
public static final String HANDLE_CFP = "Handle-Cfp";
|
||||
public static final String HANDLE_ACCEPT_PROPOSAL = "Handle-Accept-Proposal";
|
||||
public static final String HANDLE_REJECT_PROPOSAL = "Handle-Reject-Proposal";
|
||||
|
||||
public DutchAuctionResponder(Agent a) {
|
||||
this(a, null, new DataStore(), true);
|
||||
@@ -41,24 +43,43 @@ public class DutchAuctionResponder extends SSResponder {
|
||||
registerFirstState(b, HANDLE_CFP);
|
||||
b.setDataStore(getDataStore());
|
||||
registerTransition(HANDLE_CFP, SEND_REPLY, CfpHandler.CFP_ACCEPTED);
|
||||
registerDefaultTransition(HANDLE_CFP, SEND_REPLY);
|
||||
registerDefaultTransition(HANDLE_CFP, RECEIVE_CFP);
|
||||
|
||||
/* handle SEND_REPLY */
|
||||
deregisterDefaultTransition(SEND_REPLY);
|
||||
registerTransition(SEND_REPLY, RECEIVE_NEXT, ACLMessage.PROPOSE);
|
||||
|
||||
/* handle RECEIVE_NEXT & CHECK_IN_SEQ */
|
||||
/* TODO: handleAcceptProposal and handleRejectProposal */
|
||||
registerTransition(RECEIVE_NEXT, HANDLE_REJECT_PROPOSAL, MsgReceiver.TIMEOUT_EXPIRED);
|
||||
registerTransition(CHECK_IN_SEQ, HANDLE_ACCEPT_PROPOSAL, ACLMessage.ACCEPT_PROPOSAL, new String[]{SEND_REPLY});
|
||||
registerTransition(CHECK_IN_SEQ, HANDLE_REJECT_PROPOSAL, ACLMessage.REJECT_PROPOSAL);
|
||||
registerDefaultTransition(HANDLE_ACCEPT_PROPOSAL, SEND_REPLY);
|
||||
registerDefaultTransition(HANDLE_REJECT_PROPOSAL, DUMMY_FINAL);
|
||||
|
||||
/* handle HANDLE_ACCEPT_PROPOSAL */
|
||||
b = new AcceptHandler(myAgent);
|
||||
registerDSState(b, HANDLE_ACCEPT_PROPOSAL);
|
||||
|
||||
/* handle HANDLE_REJECT_PROPOSAL */
|
||||
b = new RejectHandler(myAgent);
|
||||
registerDSState(b, HANDLE_REJECT_PROPOSAL);
|
||||
}
|
||||
|
||||
protected boolean handleCfp(ACLMessage cfp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Object handleAcceptProposal(ACLMessage cfp, ACLMessage accept) throws FailureException {
|
||||
protected Object handleAcceptProposal() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void handleRejectProposal(ACLMessage cfp, ACLMessage propose, ACLMessage reject) {
|
||||
protected void handleRejectProposal() {
|
||||
}
|
||||
|
||||
private static class CfpHandler extends OneShotBehaviour {
|
||||
public static final int CFP_ACCEPTED = -4242;
|
||||
public static final int CFP_DENIED = -4243;
|
||||
private int ret;
|
||||
|
||||
public CfpHandler(Agent a) {
|
||||
@@ -69,6 +90,8 @@ public class DutchAuctionResponder extends SSResponder {
|
||||
DutchAuctionResponder parent = (DutchAuctionResponder) getParent();
|
||||
if (parent.handleCfp((ACLMessage) getDataStore().get(parent.CFP_KEY))) {
|
||||
ret = CFP_ACCEPTED;
|
||||
} else {
|
||||
ret = CFP_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,4 +99,30 @@ public class DutchAuctionResponder extends SSResponder {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AcceptHandler extends OneShotBehaviour {
|
||||
public AcceptHandler(Agent a) {
|
||||
super(a);
|
||||
}
|
||||
|
||||
public void action() {
|
||||
DutchAuctionResponder parent = (DutchAuctionResponder) getParent();
|
||||
parent.handleAcceptProposal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Inner class RejectHandler
|
||||
*/
|
||||
private static class RejectHandler extends OneShotBehaviour {
|
||||
public RejectHandler(Agent a) {
|
||||
super(a);
|
||||
}
|
||||
|
||||
public void action() {
|
||||
DutchAuctionResponder parent = (DutchAuctionResponder) getParent();
|
||||
parent.handleRejectProposal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário