1 | package geniusweb.protocol;
|
---|
2 |
|
---|
3 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
---|
4 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
---|
5 | import com.fasterxml.jackson.annotation.JsonSubTypes;
|
---|
6 | import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
---|
7 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
---|
8 |
|
---|
9 | import geniusweb.connection.ConnectionFactory;
|
---|
10 | import geniusweb.events.CurrentState;
|
---|
11 | import geniusweb.events.ProtocolEvent;
|
---|
12 | import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
|
---|
13 | import geniusweb.protocol.session.SessionProtocol;
|
---|
14 | import geniusweb.protocol.session.SessionSettings;
|
---|
15 | import geniusweb.protocol.session.SessionState;
|
---|
16 | import geniusweb.protocol.tournament.TournamentProtocol;
|
---|
17 | import geniusweb.references.PartyWithProfile;
|
---|
18 | import geniusweb.references.ProtocolRef;
|
---|
19 | import geniusweb.references.Reference;
|
---|
20 | import tudelft.utilities.listener.Listenable;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Abstract interface to all negotiation protocols, both single session and
|
---|
24 | * tournaments. Generally a protocol handles events on the provided connections
|
---|
25 | * according to the rules set by the protocol. The rules are explained by
|
---|
26 | * {@link #getDescription()}. A protocol reports the progress through its
|
---|
27 | * {@link Listenable} interface. <br>
|
---|
28 | * <p>
|
---|
29 | *
|
---|
30 | * A protocol is mutable because the incoming connections cause state changes.
|
---|
31 | * But it is recommended to push all changing properties into the state.
|
---|
32 | * <p>
|
---|
33 | * Because a protocol contains an internal state, it can be used only once.
|
---|
34 | * <p>
|
---|
35 | * The protocol also needs to keep an eye on the deadline and take appropriate
|
---|
36 | * actions when the deadline is reached. <br>
|
---|
37 | * <p>
|
---|
38 | * A protocol should emit a {@link SessionEnded} or {@link TournamentEnded}
|
---|
39 | * event when it is finished.
|
---|
40 | * <p>
|
---|
41 | * The protocol can emit a {@link CurrentState} event at any time. It should do
|
---|
42 | * so at least once, to log the final outcome of the nego.
|
---|
43 | * <p>
|
---|
44 | *
|
---|
45 | * Normally the constructor will receive a {@link ConnectionFactory} through
|
---|
46 | * which it can resolve received {@link Reference}s. <br>
|
---|
47 | * First call to instances <b>must be</b>
|
---|
48 | * {@link #start(SessionSettings, ConnectionFactory)}.
|
---|
49 | *
|
---|
50 | */
|
---|
51 | @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
|
---|
52 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
|
---|
53 | @JsonSubTypes({ @Type(value = SessionProtocol.class), @Type(value = TournamentProtocol.class) })
|
---|
54 |
|
---|
55 | public interface NegoProtocol extends Listenable<ProtocolEvent> {
|
---|
56 | /**
|
---|
57 | * Start the protocol: make connection with parties and follow the protocol.
|
---|
58 | * This must be called once and should be the first call after construction.
|
---|
59 | * <p>
|
---|
60 | *
|
---|
61 | * The protocol implementation should not start any real work (eg making
|
---|
62 | * connections) before this point. That also allows us to construct protocol
|
---|
63 | * instances just to fetch the description.
|
---|
64 | * <p>
|
---|
65 | *
|
---|
66 | * All errors are to be handled through {@link SessionState#getError()} except
|
---|
67 | * for plain {@link IllegalArgumentException}s. <br>
|
---|
68 | * The protocol usually uses the incoming connections to keep running. It does
|
---|
69 | * not need to run in a separate thread or so.
|
---|
70 | *
|
---|
71 | *
|
---|
72 | * @param connectionfactory the {@link ProtocolToPartyConnFactory} that allows
|
---|
73 | * the protocol to connect with the {@link Reference}s
|
---|
74 | * in the settings
|
---|
75 | */
|
---|
76 | void start(ProtocolToPartyConnFactory connectionfactory);
|
---|
77 |
|
---|
78 | /**
|
---|
79 | *
|
---|
80 | * @return a complete description of how this protocol behaves. Presented to the
|
---|
81 | * end users who should know negotiation basics but not all technical
|
---|
82 | * terms.
|
---|
83 | */
|
---|
84 | String getDescription();
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * @return current state: the results of all sessions run so far and how to
|
---|
88 | * continue from that point. Changes over time as the session proceeds.
|
---|
89 | * Errors are also stored in the state.
|
---|
90 | */
|
---|
91 | NegoState getState();
|
---|
92 |
|
---|
93 | /**
|
---|
94 | *
|
---|
95 | * @return the {@link ProtocolRef} for this protocol
|
---|
96 | */
|
---|
97 | ProtocolRef getRef();
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Add a party after the protocol has started. Only some protocols can handle
|
---|
101 | * this call. Usual protocols take the settings with their constructor.
|
---|
102 | *
|
---|
103 | * @param party the {@link PartyWithProfile} to be added.
|
---|
104 | */
|
---|
105 | void addParticipant(PartyWithProfile party);
|
---|
106 |
|
---|
107 | }
|
---|