Changeset 21 for protocol/src/main
- Timestamp:
- 09/22/20 08:52:04 (4 years ago)
- Location:
- protocol/src/main/java/geniusweb/protocol
- Files:
-
- 17 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/main/java/geniusweb/protocol/NegoProtocol.java
r9 r21 8 8 9 9 import geniusweb.connection.ConnectionFactory; 10 import geniusweb.deadline.Deadline; 10 11 import geniusweb.events.CurrentState; 11 12 import geniusweb.events.ProtocolEvent; … … 26 27 * {@link #getDescription()}. A protocol reports the progress through its 27 28 * {@link Listenable} interface. <br> 28 * < p>29 * <h2>General information</h2> 29 30 * 30 31 * A protocol is mutable because the incoming connections cause state changes. … … 33 34 * Because a protocol contains an internal state, it can be used only once. 34 35 * <p> 35 * The protocol also needs to keep an eye on the deadline and take appropriate36 * 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 36 * <p> 41 37 * The protocol can emit a {@link CurrentState} event at any time. It should do … … 48 44 * {@link #start(SessionSettings, ConnectionFactory)}. 49 45 * 46 * <h2>Ensure time deadline</h2> 47 * 48 * The protocol also needs to keep an eye on the deadline and take appropriate 49 * actions when the deadline is reached. <br> 50 * A protocol should emit a {@link SessionEnded} or {@link TournamentEnded} 51 * event when it is finished. 52 * <p> 53 * All protocol implementations must ensure that the deadline is kept and that 54 * the session ends at the agreed time {@link Deadline#getDuration()}. This is 55 * to ensure that the negotiation ends and resources are freed up at or before 56 * some known time. 57 * 50 58 */ 51 59 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE) 52 60 @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) 53 @JsonSubTypes({ @Type(value = SessionProtocol.class), @Type(value = TournamentProtocol.class) }) 61 @JsonSubTypes({ @Type(value = SessionProtocol.class), 62 @Type(value = TournamentProtocol.class) }) 54 63 55 64 public interface NegoProtocol extends Listenable<ProtocolEvent> { … … 64 73 * <p> 65 74 * 66 * All errors are to be handled through {@link SessionState#getError()} except67 * for plain {@link IllegalArgumentException}s. <br>68 * The protocol usually uses the incoming connections to keep running. It does69 * not need to run in a separate thread or so.75 * All errors are to be handled through {@link SessionState#getError()} 76 * except for plain {@link IllegalArgumentException}s. <br> 77 * The protocol usually uses the incoming connections to keep running. It 78 * does not need to run in a separate thread or so. 70 79 * 71 80 * 72 * @param connectionfactory the {@link ProtocolToPartyConnFactory} that allows73 * the protocol to connect with the {@link Reference}s74 * in the settings81 * @param connectionfactory the {@link ProtocolToPartyConnFactory} that 82 * allows the protocol to connect with the 83 * {@link Reference}s in the settings 75 84 */ 76 85 void start(ProtocolToPartyConnFactory connectionfactory); … … 78 87 /** 79 88 * 80 * @return a complete description of how this protocol behaves. Presented to the81 * end users who should know negotiation basics but not all technical82 * te rms.89 * @return a complete description of how this protocol behaves. Presented to 90 * the end users who should know negotiation basics but not all 91 * technical terms. 83 92 */ 84 93 String getDescription(); … … 86 95 /** 87 96 * @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.97 * continue from that point. Changes over time as the session 98 * proceeds. Errors are also stored in the state. 90 99 */ 91 100 NegoState getState(); … … 98 107 99 108 /** 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. 109 * Add a party after the protocol has started. Only some protocols can 110 * handle this call. Usual protocols take the settings with their 111 * constructor. 102 112 * 103 113 * @param party the {@link PartyWithProfile} to be added. -
protocol/src/main/java/geniusweb/protocol/NegoState.java
r1 r21 5 5 import com.fasterxml.jackson.annotation.JsonSubTypes; 6 6 import com.fasterxml.jackson.annotation.JsonSubTypes.Type; 7 import com.fasterxml.jackson.annotation.JsonTypeInfo; 7 8 8 9 import geniusweb.protocol.session.SessionState; 9 10 import geniusweb.protocol.tournament.TournamentState; 10 11 11 import com.fasterxml.jackson.annotation.JsonTypeInfo;12 13 12 /** 14 * The current state of the tournament. Must be serializabl;e so that it can be15 * restarted if a crash occurs.13 * The current state of the session/tournament. Must be serializabl;e so that it 14 * can be restarted if a crash occurs. 16 15 */ 17 16 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE) … … 36 35 boolean isFinal(long currentTimeMs); 37 36 38 /**39 *40 * @return a fatal error occured during the tournament. returns null if no41 * errors occured.42 */43 ProtocolException getError();44 37 } -
protocol/src/main/java/geniusweb/protocol/ProtocolException.java
r4 r21 2 2 3 3 import geniusweb.actions.PartyId; 4 import geniusweb.party.Party;5 4 import geniusweb.references.PartyRef; 6 5 … … 10 9 */ 11 10 public class ProtocolException extends Exception { 12 private String party; // the failing party 11 private static final long serialVersionUID = 4618901784366523980L; 12 private PartyId party; // the failing party 13 13 14 14 /** … … 17 17 * {@link PartyRef} 18 18 */ 19 public ProtocolException(String message, Stringparty) {19 public ProtocolException(String message, PartyId party) { 20 20 this(message, party, null); 21 21 } … … 30 30 * 31 31 * @param message the error message 32 * @param party offending party, either the {@link PartyId} or a 33 * {@link PartyRef} 32 * @param party offending {@link PartyId} 34 33 * @param e the cause of the error 35 34 */ 36 public ProtocolException(String message, Stringparty, Throwable e) {35 public ProtocolException(String message, PartyId party, Throwable e) { 37 36 super(party + ":" + message, e, true, false); 38 37 this.party = party; … … 43 42 * @return offending party, either the {@link PartyId} or a {@link PartyRef} 44 43 */ 45 public StringgetParty() {44 public PartyId getParty() { 46 45 return party; 47 46 } -
protocol/src/main/java/geniusweb/protocol/partyconnection/ProtocolToPartyConn.java
r9 r21 4 4 import geniusweb.actions.PartyId; 5 5 import geniusweb.connection.ConnectionEnd; 6 import geniusweb. party.inform.Inform;6 import geniusweb.inform.Inform; 7 7 8 8 /** … … 14 14 /** 15 15 * 16 * @return the partyId of the party that this connects to 16 * @return the partyId of the party that this connects to. 17 17 */ 18 18 PartyId getParty(); -
protocol/src/main/java/geniusweb/protocol/partyconnection/ProtocolToPartyConnFactory.java
r9 r21 6 6 import geniusweb.actions.Action; 7 7 import geniusweb.connection.ConnectionFactory; 8 import geniusweb. party.inform.Inform;8 import geniusweb.inform.Inform; 9 9 import geniusweb.references.Reference; 10 10 import tudelft.utilities.repository.NoResourcesNowException; -
protocol/src/main/java/geniusweb/protocol/partyconnection/ProtocolToPartyConnections.java
r9 r21 9 9 10 10 import geniusweb.actions.PartyId; 11 import geniusweb. party.inform.Inform;11 import geniusweb.inform.Inform; 12 12 13 13 /** 14 14 * Contains all parties with their connections. immutable 15 15 */ 16 public class ProtocolToPartyConnections implements Iterable<ProtocolToPartyConn> { 16 public class ProtocolToPartyConnections 17 implements Iterable<ProtocolToPartyConn> { 17 18 private List<ProtocolToPartyConn> connections; 18 19 -
protocol/src/main/java/geniusweb/protocol/session/DefaultSessionState.java
r10 r21 57 57 * {@link ProtocolException}s. All errors in our own 58 58 * code are bugs (not ProtocolExceptions) and should 59 * result in a throw .59 * result in a throw and terminate the session. 60 60 */ 61 61 public DefaultSessionState(List<Action> actions, … … 130 130 } 131 131 132 @Override133 132 public ProtocolException getError() { 134 133 return error; -
protocol/src/main/java/geniusweb/protocol/session/SessionResult.java
r20 r21 10 10 import com.fasterxml.jackson.annotation.JsonTypeInfo; 11 11 12 import geniusweb.i ssuevalue.Bid;12 import geniusweb.inform.Agreements; 13 13 import geniusweb.references.PartyWithProfile; 14 14 … … 20 20 public class SessionResult { 21 21 private final List<PartyWithProfile> participants; 22 private final Bid agreement;22 private final Agreements agreements; 23 23 private final List<Double> penalties; 24 24 … … 33 33 * never be null. Some of them may have entered later of 34 34 * left early. This list should contain them all. 35 * @param agreement the final agreement {@link Bid} of the session. Null 36 * if no agreement was reached. 35 * @param agreements the final Agreements. 37 36 * @param penalties the penalties in [0,1] for each participant, same 38 37 * order as the participants list. … … 48 47 public SessionResult( 49 48 @JsonProperty("participants") List<PartyWithProfile> participants, 50 @JsonProperty("agreement ") Bid agreement,49 @JsonProperty("agreements") Agreements agreements, 51 50 @JsonProperty("penalties") List<Double> penalties, 52 51 @JsonProperty("error") Throwable error) { 53 52 this.participants = participants; 54 this.agreement = agreement;53 this.agreements = agreements; 55 54 this.penalties = penalties; 56 55 this.error = error; … … 69 68 70 69 /** 71 * 8return the final agreement {@link Bid} of the session. Null if no72 * agreement was reached.70 * 8return the final {@link Agreements} of the session. May be empty, not 71 * null 73 72 */ 74 public Bid getAgreement() {75 return agreement ;73 public Agreements getAgreements() { 74 return agreements; 76 75 }; 77 76 … … 99 98 @Override 100 99 public String toString() { 101 return "SessionResult[" + participants + "," + agreement + ","100 return "SessionResult[" + participants + "," + agreements + "," 102 101 + penalties + "," + error + "]"; 103 102 } … … 108 107 int result = 1; 109 108 result = prime * result 110 + ((agreement == null) ? 0 : agreement.hashCode());109 + ((agreements == null) ? 0 : agreements.hashCode()); 111 110 result = prime * result + ((error == null) ? 0 : error.hashCode()); 112 111 result = prime * result … … 126 125 return false; 127 126 SessionResult other = (SessionResult) obj; 128 if (agreement == null) {129 if (other.agreement != null)127 if (agreements == null) { 128 if (other.agreements != null) 130 129 return false; 131 } else if (!agreement .equals(other.agreement))130 } else if (!agreements.equals(other.agreements)) 132 131 return false; 133 132 if (error == null) { -
protocol/src/main/java/geniusweb/protocol/session/SessionSettings.java
r10 r21 6 6 7 7 import geniusweb.protocol.NegoSettings; 8 import geniusweb.protocol.session.amop.AMOPSettings; 9 import geniusweb.protocol.session.mopac.MOPACSettings; 8 10 import geniusweb.protocol.session.saop.SAOPSettings; 9 11 import geniusweb.protocol.session.shaop.SHAOPSettings; … … 15 17 */ 16 18 @JsonSubTypes({ @JsonSubTypes.Type(value = SAOPSettings.class), 17 @JsonSubTypes.Type(value = SHAOPSettings.class) }) 19 @JsonSubTypes.Type(value = SHAOPSettings.class), 20 @JsonSubTypes.Type(value = AMOPSettings.class), 21 @JsonSubTypes.Type(value = MOPACSettings.class) }) 18 22 public interface SessionSettings extends NegoSettings { 19 23 -
protocol/src/main/java/geniusweb/protocol/session/SessionState.java
r20 r21 6 6 7 7 import geniusweb.actions.Action; 8 import geniusweb.i ssuevalue.Bid;8 import geniusweb.inform.Agreements; 9 9 import geniusweb.progress.Progress; 10 10 import geniusweb.protocol.NegoState; 11 import geniusweb.protocol.session.amop.AMOPState; 12 import geniusweb.protocol.session.mopac.MOPACState; 11 13 import geniusweb.protocol.session.saop.SAOPState; 12 14 import geniusweb.protocol.session.shaop.SHAOPState; … … 35 37 */ 36 38 @JsonSubTypes({ @JsonSubTypes.Type(value = SAOPState.class), 37 @JsonSubTypes.Type(value = SHAOPState.class) }) 38 39 @JsonSubTypes.Type(value = SHAOPState.class), 40 @JsonSubTypes.Type(value = AMOPState.class), 41 @JsonSubTypes.Type(value = MOPACState.class) }) 39 42 public interface SessionState extends NegoState { 40 43 … … 45 48 * 46 49 * @return unmodifyable list of actions done so far, in the order in which 47 * they arrived. 50 * they arrived. List of list allows implementations to add some 51 * extra structure to the actions, eg one list per phase 48 52 */ 49 53 List<Action> getActions(); … … 64 68 * {@link #isFinal()}. 65 69 */ 66 Bid getAgreement();70 Agreements getAgreements(); 67 71 68 72 /** -
protocol/src/main/java/geniusweb/protocol/session/TeamOfPartiesAndProfiles.java
r10 r21 7 7 import com.fasterxml.jackson.annotation.JsonSubTypes; 8 8 9 import geniusweb.protocol.session.saop.SaopPartyWithProfile;10 9 import geniusweb.protocol.session.shaop.ShaopTeam; 11 10 import geniusweb.references.PartyWithProfile; … … 23 22 // and do not (de)serialize individual TeamOfPartiesAndProfiles. 24 23 //@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) 25 @JsonSubTypes({ @JsonSubTypes.Type(value = SaopPartyWithProfile.class),24 @JsonSubTypes({ @JsonSubTypes.Type(value = OnePartyTeam.class), 26 25 @JsonSubTypes.Type(value = ShaopTeam.class) }) 27 26 public interface TeamOfPartiesAndProfiles { -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOP.java
r10 r21 15 15 import geniusweb.deadline.Deadline; 16 16 import geniusweb.events.ProtocolEvent; 17 import geniusweb. party.inform.ActionDone;18 import geniusweb. party.inform.Finished;19 import geniusweb. party.inform.Inform;20 import geniusweb. party.inform.Settings;21 import geniusweb. party.inform.YourTurn;17 import geniusweb.inform.ActionDone; 18 import geniusweb.inform.Finished; 19 import geniusweb.inform.Inform; 20 import geniusweb.inform.Settings; 21 import geniusweb.inform.YourTurn; 22 22 import geniusweb.progress.ProgressFactory; 23 23 import geniusweb.protocol.CurrentNegoState; … … 227 227 } catch (IOException e) { 228 228 throw new ProtocolException("Failed to initialize", 229 connection.getParty() .getName(), e);229 connection.getParty(), e); 230 230 } 231 231 } … … 257 257 * Synchronized so that we always handle only 1 action at a time. 258 258 * 259 * @param partyconn the connection on which the action came in 259 * @param partyconn the connection on which the action came in. 260 260 * @param action the {@link Action} taken by some party 261 261 */ … … 266 266 if (err == null) { 267 267 err = new ProtocolException("Party sent a null action", 268 partyconn.getParty() .getName());269 } 270 handleError(partyconn + "Protocol error", 271 partyconn.getParty().getName(),err);268 partyconn.getParty()); 269 } 270 handleError(partyconn + "Protocol error", partyconn.getParty(), 271 err); 272 272 return; 273 273 } … … 278 278 throw new ProtocolException( 279 279 "Party acts without having the turn", 280 partyconn.getParty() .getName());280 partyconn.getParty()); 281 281 } 282 282 state.getConnections().broadcast(new ActionDone(action)); … … 286 286 } catch (Throwable e) { 287 287 handleError("failed to handle action " + action, 288 partyconn.getParty() .getName(), e);288 partyconn.getParty(), e); 289 289 } 290 290 … … 301 301 state.getConnections().get(party).send(new YourTurn()); 302 302 } catch (IOException e) { 303 handleError("failed to send YourTurn", party .getName(), e);303 handleError("failed to send YourTurn", party, e); 304 304 } 305 305 } … … 313 313 */ 314 314 private synchronized void handleError(final String message, 315 final Stringparty, final Throwable e) {315 final PartyId party, final Throwable e) { 316 316 if (e instanceof ProtocolException) { 317 317 setState(state.with((ProtocolException) e)); … … 353 353 if (!isFinishedInfoSent.compareAndSet(false, true)) 354 354 return; 355 Inform finished = new Finished(state.getAgreement ());355 Inform finished = new Finished(state.getAgreements()); 356 356 for (ProtocolToPartyConn conn : state.getConnections()) { 357 357 sendFinish(conn, finished); -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOPSettings.java
r10 r21 10 10 11 11 import geniusweb.deadline.Deadline; 12 import geniusweb.protocol.session.OnePartyTeam; 12 13 import geniusweb.protocol.session.SessionProtocol; 13 14 import geniusweb.protocol.session.SessionSettings; … … 17 18 18 19 public class SAOPSettings implements SessionSettings { 19 private final List< SaopPartyWithProfile> participants;20 private final List<OnePartyTeam> participants; 20 21 private final Deadline deadline; 21 22 … … 30 31 @JsonCreator 31 32 public SAOPSettings( 32 @JsonProperty("participants") List< SaopPartyWithProfile> participants,33 @JsonProperty("participants") List<OnePartyTeam> participants, 33 34 @JsonProperty("deadline") Deadline deadline) { 34 35 this.participants = participants; … … 111 112 @Override 112 113 public SessionSettings with(TeamOfPartiesAndProfiles party) { 113 if (!(party instanceof SaopPartyWithProfile))114 if (!(party instanceof OnePartyTeam)) 114 115 throw new IllegalArgumentException( 115 "Added party must be SaopPartyWithProfile but got " 116 + party); 117 List<SaopPartyWithProfile> newparts = new LinkedList<>(participants); 118 newparts.add((SaopPartyWithProfile) party); 116 "Added party must be OnePartyTeam but got " + party); 117 List<OnePartyTeam> newparts = new LinkedList<>(participants); 118 newparts.add((OnePartyTeam) party); 119 119 return new SAOPSettings(newparts, deadline); 120 120 } -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOPState.java
r20 r21 6 6 import java.util.List; 7 7 import java.util.Map; 8 import java.util.Set; 9 import java.util.stream.Collectors; 8 10 9 11 import geniusweb.actions.Accept; … … 12 14 import geniusweb.actions.Offer; 13 15 import geniusweb.actions.PartyId; 16 import geniusweb.inform.Agreements; 14 17 import geniusweb.issuevalue.Bid; 15 18 import geniusweb.progress.Progress; … … 113 116 114 117 @Override 115 public Bid getAgreement() { 118 public Agreements getAgreements() { 119 Agreements agree = new Agreements(); 116 120 List<Action> acts = getActions(); 117 121 int nparticipants = getConnections().size(); 118 122 if (nparticipants < 2 || acts.size() < nparticipants) { 119 return null;123 return agree; 120 124 } 121 125 Action offer = acts.get(acts.size() - nparticipants); 122 126 if (!(offer instanceof Offer)) 123 return null;127 return agree; 124 128 Bid bid = ((Offer) offer).getBid(); 125 129 … … 128 132 .allMatch(act -> act instanceof Accept 129 133 && bid.equals(((Accept) act).getBid())); 130 return allaccept ? bid : null; 134 if (allaccept) 135 agree = agree.with(bid, getParties()); 136 return agree; 137 } 138 139 /** 140 * 141 * @return all currently connected parties. 142 */ 143 private Set<PartyId> getParties() { 144 return getConnections().stream().map(conn -> conn.getParty()) 145 .collect(Collectors.toSet()); 131 146 } 132 147 … … 134 149 public boolean isFinal(long currentTimeMs) { 135 150 List<Action> acts = getActions(); 136 return super.isFinal(currentTimeMs) || getAgreement() != null137 || (!acts.isEmpty()151 return super.isFinal(currentTimeMs) 152 || !getAgreements().getMap().isEmpty() || (!acts.isEmpty() 138 153 && acts.get(acts.size() - 1) instanceof EndNegotiation); 139 154 } … … 254 269 for (int n = 0; n < getConnections().size(); n++) 255 270 emptylist.add(0d); 256 return new SessionResult(getSettings().getAllParties(), getAgreement (),271 return new SessionResult(getSettings().getAllParties(), getAgreements(), 257 272 emptylist, getError()); 258 273 } -
protocol/src/main/java/geniusweb/protocol/session/shaop/BareSHAOPState.java
r20 r21 158 158 } 159 159 160 @Override161 160 public ProtocolException getError() { 162 161 return error; … … 182 181 penalties[partyNumbers.get(party)] = spent; 183 182 } 184 return new SessionResult(getSettings().getAllParties(), getAgreement (),183 return new SessionResult(getSettings().getAllParties(), getAgreements(), 185 184 Arrays.asList(penalties), getError()); 186 185 -
protocol/src/main/java/geniusweb/protocol/session/shaop/SHAOP.java
r18 r21 21 21 import geniusweb.deadline.Deadline; 22 22 import geniusweb.events.ProtocolEvent; 23 import geniusweb. party.inform.ActionDone;24 import geniusweb. party.inform.Finished;25 import geniusweb. party.inform.Inform;26 import geniusweb. party.inform.Settings;27 import geniusweb. party.inform.YourTurn;23 import geniusweb.inform.ActionDone; 24 import geniusweb.inform.Finished; 25 import geniusweb.inform.Inform; 26 import geniusweb.inform.Settings; 27 import geniusweb.inform.YourTurn; 28 28 import geniusweb.progress.ProgressFactory; 29 29 import geniusweb.protocol.CurrentNegoState; … … 238 238 } catch (IOException e) { 239 239 throw new ProtocolException("Failed to initialize", 240 connection.getParty() .getName(), e);240 connection.getParty(), e); 241 241 } 242 242 } … … 276 276 } catch (Throwable e) { 277 277 handleError("failed to handle action " + action, 278 partyconn.getParty() .getName(), e);278 partyconn.getParty(), e); 279 279 } 280 280 } … … 289 289 290 290 if (action == null) 291 throw new ProtocolException("Party sent a null action", 292 partyid.getName()); 291 throw new ProtocolException("Party sent a null action", partyid); 293 292 294 293 // check if action allowed … … 296 295 if (!ALLOWED_ACTIONS.contains(action.getClass())) { 297 296 throw new ProtocolException( 298 "Illegal action for SHAOP Party:" + action, 299 partyid.getName()); 297 "Illegal action for SHAOP Party:" + action, partyid); 300 298 } 301 299 } else { 302 300 if (!(action instanceof Comparison)) 303 301 throw new ProtocolException( 304 "Illegal action for COB Party:" + action, 305 partyid.getName()); 302 "Illegal action for COB Party:" + action, partyid); 306 303 } 307 304 … … 316 313 if (!partyconn.getParty().equals(state.getCurrentTeam())) 317 314 throw new ProtocolException( 318 "Party acts without having the turn", 319 partyid.getName()); 315 "Party acts without having the turn", partyid); 320 316 setState(state.with(partyconn.getParty(), action)); 321 317 state.connections.broadcast(new ActionDone(action)); … … 336 332 state.getConnections().get(party).send(new YourTurn()); 337 333 } catch (IOException e) { 338 handleError("failed to send YourTurn", party .getName(), e);334 handleError("failed to send YourTurn", party, e); 339 335 } 340 336 } … … 348 344 */ 349 345 private synchronized void handleError(final String message, 350 final Stringparty, final Throwable e) {346 final PartyId party, final Throwable e) { 351 347 log.log(Level.WARNING, "SHAOP protocol intercepted error due to party " 352 348 + party + ": " + message, e); … … 388 384 if (!isFinishedInfoSent.compareAndSet(false, true)) 389 385 return; 390 Inform finished = new Finished(state.getAgreement ());386 Inform finished = new Finished(state.getAgreements()); 391 387 state.connections.stream().forEach(conn -> sendFinish(conn, finished)); 392 388 notifyListeners(new CurrentNegoState(state)); -
protocol/src/main/java/geniusweb/protocol/session/shaop/SHAOPState.java
r18 r21 6 6 import java.util.List; 7 7 import java.util.Map; 8 import java.util.Set; 9 import java.util.stream.Collectors; 8 10 9 11 import com.fasterxml.jackson.annotation.JsonCreator; … … 17 19 import geniusweb.actions.Offer; 18 20 import geniusweb.actions.PartyId; 21 import geniusweb.inform.Agreements; 19 22 import geniusweb.issuevalue.Bid; 20 23 import geniusweb.progress.Progress; … … 78 81 /** 79 82 * 83 * @return the team leader {@link PartyId}s. 84 */ 85 private Set<PartyId> getLeaders() { 86 return partyNumbers.keySet().stream().filter(id -> isShaopParty(id)) 87 .collect(Collectors.toSet()); 88 } 89 90 /** 91 * 80 92 * @param party a Party Id 81 93 * @return the PartyId of the party (COB and SHAOP are partners) … … 88 100 public boolean isFinal(long currentTimeMs) { 89 101 List<Action> acts = getActions(); 90 return super.isFinal(currentTimeMs) || getAgreement() != null91 || (!acts.isEmpty()102 return super.isFinal(currentTimeMs) 103 || !getAgreements().getMap().isEmpty() || (!acts.isEmpty() 92 104 && acts.get(acts.size() - 1) instanceof EndNegotiation); 93 105 } … … 166 178 167 179 @Override 168 public Bid getAgreement() { 180 public Agreements getAgreements() { 181 Agreements agrees = new Agreements(); 169 182 List<Action> acts = getActions(); 170 183 if (acts.isEmpty()) 171 return null;184 return agrees; 172 185 173 186 int requiredaccepts = getSettings().getTeams().size() - 1; … … 179 192 continue; 180 193 if (requiredaccepts == 0 && act instanceof Offer) 181 return ((Offer) act).getBid();194 return agrees.with(((Offer) act).getBid(), getLeaders()); 182 195 if (!(act instanceof Accept)) 183 return null;196 return agrees; 184 197 requiredaccepts--; 185 198 } 186 return null;199 return agrees; 187 200 } 188 201 -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettings.java
r18 r21 9 9 import com.fasterxml.jackson.annotation.JsonProperty; 10 10 11 import geniusweb.protocol.session.OnePartyTeam; 11 12 import geniusweb.protocol.session.SessionSettings; 12 13 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; 14 import geniusweb.protocol.session.amop.AMOPSettings; 15 import geniusweb.protocol.session.mopac.MOPACSettings; 13 16 import geniusweb.protocol.session.saop.SAOPSettings; 14 import geniusweb.protocol.session.saop.SaopPartyWithProfile;15 17 import geniusweb.protocol.session.shaop.SHAOPSettings; 16 18 import geniusweb.protocol.session.shaop.ShaopTeam; … … 106 108 throw new IllegalArgumentException("nTournaments must be >0"); 107 109 int teamsize; 108 if (sesettings instanceof SAOPSettings) 110 if (sesettings instanceof SAOPSettings 111 || sesettings instanceof MOPACSettings 112 || sesettings instanceof AMOPSettings) 109 113 teamsize = 1; 110 114 else if (sesettings instanceof SHAOPSettings) … … 283 287 public TeamOfPartiesAndProfiles apply(Team team, 284 288 ProfileList profilelist) { 285 if (sessionsettings instanceof SAOPSettings) 286 return new SaopPartyWithProfile(team.getParties().get(0), 289 if (sessionsettings instanceof SAOPSettings 290 || sessionsettings instanceof AMOPSettings 291 || sessionsettings instanceof MOPACSettings) 292 return new OnePartyTeam(team.getParties().get(0), 287 293 profilelist.getProfiles().get(0)); 288 294 else if (sessionsettings instanceof SHAOPSettings) { -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java
r20 r21 5 5 import java.util.List; 6 6 7 import geniusweb.protocol.ProtocolException;8 7 import geniusweb.protocol.session.SessionResult; 9 8 import geniusweb.protocol.session.SessionSettings; … … 65 64 } 66 65 67 @Override68 public ProtocolException getError() {69 return null;70 }71 72 66 /** 73 67 *
Note:
See TracChangeset
for help on using the changeset viewer.