source: protocol/src/main/java/geniusweb/protocol/session/mopac/phase/Phase.java@ 21

Last change on this file since 21 was 21, checked in by bart, 4 years ago

Version 1.5.

File size: 3.0 KB
Line 
1package geniusweb.protocol.session.mopac.phase;
2
3import java.util.Set;
4
5import geniusweb.actions.Action;
6import geniusweb.actions.PartyId;
7import geniusweb.inform.Inform;
8import geniusweb.protocol.ProtocolException;
9import geniusweb.protocol.session.mopac.PartyStates;
10import geniusweb.voting.VotingEvaluator;
11
12/**
13 * A Phase is a part of the round structure. In each round parties have to take
14 * multiple actions. Each action is part of a phase.
15 *
16 */
17public interface Phase {
18 public static final Long PHASE_MAXTIME = 30000l; // 30sec
19 public static final Long PHASE_MINTIME = 100l; // 100 millisec
20
21 /**
22 * Handle an actor's action. If a {@link ProtocolException} occurs, this is
23 * handled by updating the PartyStates
24 *
25 * @param prevPhases the list of all previous phases
26 * @param actor the real actor
27 * @param action the action submitted by actor, which this phase can
28 * really handle.
29 * @param now the current time
30 * @return new VotingPhase
31 */
32 public Phase with(PartyId actor, Action action, long now);
33
34 /**
35 *
36 * @param e a {@link ProtocolException}
37 * @return new Phase with a party disabled because it violated a protocol eg
38 * breaking a websocket link.
39 */
40 public Phase with(ProtocolException e);
41
42 /**
43 *
44 * @return the inform object to send to all parties at start of phase.
45 */
46 public Inform getInform();
47
48 /**
49 *
50 * @param now the current time
51 * @return true iff past deadline or no more actions are allowed anyway.
52 * (which usually means, all parties have done exactly one act).
53 * Notice, this is the main reason that it is desirable to require
54 * all parties to act exactly once in each phase. Without such a
55 * rule, the protocol will always have to wait till the deadline.
56 */
57 public boolean isFinal(long now);
58
59 /**
60 *
61 * @return finished state. That means, all parties that did not act have
62 * been kicked, new agreements have been computed, etc.
63 */
64 public Phase finish();
65
66 /**
67 * Determines the next phase. Resets the actions field. Can only be called
68 * after {@link #finish()}
69 *
70 * @param now the curren time
71 * @param duration the max duration of the next phase. Must be between
72 * {@link #PHASE_MINTIME} and {@link #PHASE_MAXTIME}. Also
73 * make sure that now+duration is at most at the total
74 * negotiation deadline.
75 * @return the next phase, or null if negotiation is complete.
76 */
77 public Phase next(long now, long duration);
78
79 /**
80 * Get the voting evaluator
81 *
82 * @return
83 */
84 public VotingEvaluator getEvaluator();
85
86 /**
87 *
88 * @return time (ms since 1970) at which phase ends. The phase may end
89 * before, but never after this.
90 */
91 public long getDeadline();
92
93 /**
94 * @param now the current time
95 *
96 * @return the party states. Notice that someone must call
97 * {@link PartyStates#finish(Set)} if passed the deadline.
98 */
99 public PartyStates getPartyStates();
100
101}
Note: See TracBrowser for help on using the repository browser.