1 | package geniusweb.protocol.session.mopac.phase;
|
---|
2 |
|
---|
3 | import java.util.Arrays;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
7 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
8 |
|
---|
9 | import geniusweb.actions.Action;
|
---|
10 | import geniusweb.actions.EndNegotiation;
|
---|
11 | import geniusweb.actions.Offer;
|
---|
12 | import geniusweb.actions.PartyId;
|
---|
13 | import geniusweb.inform.Inform;
|
---|
14 | import geniusweb.inform.YourTurn;
|
---|
15 | import geniusweb.protocol.ProtocolException;
|
---|
16 | import geniusweb.protocol.session.mopac.PartyStates;
|
---|
17 | import geniusweb.voting.VotingEvaluator;
|
---|
18 |
|
---|
19 | public class OfferPhase extends DefaultPhase {
|
---|
20 |
|
---|
21 | @JsonCreator
|
---|
22 | public OfferPhase(@JsonProperty("partyStates") PartyStates partyStates,
|
---|
23 | @JsonProperty("deadline") Long deadline,
|
---|
24 | @JsonProperty("evaluator") VotingEvaluator evaluator) {
|
---|
25 | super(partyStates, deadline, evaluator);
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public OfferPhase with(PartyId actor, Action action, long timems) {
|
---|
30 | try {
|
---|
31 | checkAction(actor, action, timems);
|
---|
32 | } catch (ProtocolException ex) {
|
---|
33 | return this.with(ex);
|
---|
34 | }
|
---|
35 | return new OfferPhase(partyStates.with(action), deadline, evaluator);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public Inform getInform() {
|
---|
40 | return new YourTurn();
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public OfferPhase with(ProtocolException e) {
|
---|
45 | System.out.println("Party kicked because of protocol exception:" + e);
|
---|
46 | return new OfferPhase(partyStates.with(e), deadline, evaluator);
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public Phase finish() {
|
---|
51 | return new OfferPhase(partyStates.finish(), deadline, evaluator);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public VotingPhase checkedNext(long deadln) {
|
---|
56 | return new VotingPhase(getOffers(), partyStates.flush(), deadln,
|
---|
57 | evaluator);
|
---|
58 | }
|
---|
59 |
|
---|
60 | protected List<Offer> getOffers() {
|
---|
61 | return partyStates.getActions(Offer.class);
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public List<Class<? extends Action>> getAllowedActions() {
|
---|
66 | return Arrays.asList(Offer.class, EndNegotiation.class);
|
---|
67 | }
|
---|
68 |
|
---|
69 | }
|
---|