Changeset 21 for protocol/src/main


Ignore:
Timestamp:
09/22/20 08:52:04 (4 years ago)
Author:
bart
Message:

Version 1.5.

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  
    88
    99import geniusweb.connection.ConnectionFactory;
     10import geniusweb.deadline.Deadline;
    1011import geniusweb.events.CurrentState;
    1112import geniusweb.events.ProtocolEvent;
     
    2627 * {@link #getDescription()}. A protocol reports the progress through its
    2728 * {@link Listenable} interface. <br>
    28  * <p>
     29 * <h2>General information</h2>
    2930 *
    3031 * A protocol is mutable because the incoming connections cause state changes.
     
    3334 * Because a protocol contains an internal state, it can be used only once.
    3435 * <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.
    4036 * <p>
    4137 * The protocol can emit a {@link CurrentState} event at any time. It should do
     
    4844 * {@link #start(SessionSettings, ConnectionFactory)}.
    4945 *
     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 *
    5058 */
    5159@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
    5260@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) })
    5463
    5564public interface NegoProtocol extends Listenable<ProtocolEvent> {
     
    6473         * <p>
    6574         *
    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.
     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.
    7079         *
    7180         *
    72          * @param connectionfactory the {@link ProtocolToPartyConnFactory} that allows
    73          *                          the protocol to connect with the {@link Reference}s
    74          *                          in the settings
     81         * @param connectionfactory the {@link ProtocolToPartyConnFactory} that
     82         *                          allows the protocol to connect with the
     83         *                          {@link Reference}s in the settings
    7584         */
    7685        void start(ProtocolToPartyConnFactory connectionfactory);
     
    7887        /**
    7988         *
    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.
     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.
    8392         */
    8493        String getDescription();
     
    8695        /**
    8796         * @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.
    9099         */
    91100        NegoState getState();
     
    98107
    99108        /**
    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.
    102112         *
    103113         * @param party the {@link PartyWithProfile} to be added.
  • protocol/src/main/java/geniusweb/protocol/NegoState.java

    r1 r21  
    55import com.fasterxml.jackson.annotation.JsonSubTypes;
    66import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
     7import com.fasterxml.jackson.annotation.JsonTypeInfo;
    78
    89import geniusweb.protocol.session.SessionState;
    910import geniusweb.protocol.tournament.TournamentState;
    1011
    11 import com.fasterxml.jackson.annotation.JsonTypeInfo;
    12 
    1312/**
    14  * The current state of the tournament. Must be serializabl;e so that it can be
    15  * 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.
    1615 */
    1716@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
     
    3635        boolean isFinal(long currentTimeMs);
    3736
    38         /**
    39          *
    40          * @return a fatal error occured during the tournament. returns null if no
    41          *         errors occured.
    42          */
    43         ProtocolException getError();
    4437}
  • protocol/src/main/java/geniusweb/protocol/ProtocolException.java

    r4 r21  
    22
    33import geniusweb.actions.PartyId;
    4 import geniusweb.party.Party;
    54import geniusweb.references.PartyRef;
    65
     
    109 */
    1110public 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
    1313
    1414        /**
     
    1717         *                {@link PartyRef}
    1818         */
    19         public ProtocolException(String message, String party) {
     19        public ProtocolException(String message, PartyId party) {
    2020                this(message, party, null);
    2121        }
     
    3030         *
    3131         * @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}
    3433         * @param e       the cause of the error
    3534         */
    36         public ProtocolException(String message, String party, Throwable e) {
     35        public ProtocolException(String message, PartyId party, Throwable e) {
    3736                super(party + ":" + message, e, true, false);
    3837                this.party = party;
     
    4342         * @return offending party, either the {@link PartyId} or a {@link PartyRef}
    4443         */
    45         public String getParty() {
     44        public PartyId getParty() {
    4645                return party;
    4746        }
  • protocol/src/main/java/geniusweb/protocol/partyconnection/ProtocolToPartyConn.java

    r9 r21  
    44import geniusweb.actions.PartyId;
    55import geniusweb.connection.ConnectionEnd;
    6 import geniusweb.party.inform.Inform;
     6import geniusweb.inform.Inform;
    77
    88/**
     
    1414        /**
    1515         *
    16          * @return the partyId of the party that this connects to
     16         * @return the partyId of the party that this connects to.
    1717         */
    1818        PartyId getParty();
  • protocol/src/main/java/geniusweb/protocol/partyconnection/ProtocolToPartyConnFactory.java

    r9 r21  
    66import geniusweb.actions.Action;
    77import geniusweb.connection.ConnectionFactory;
    8 import geniusweb.party.inform.Inform;
     8import geniusweb.inform.Inform;
    99import geniusweb.references.Reference;
    1010import tudelft.utilities.repository.NoResourcesNowException;
  • protocol/src/main/java/geniusweb/protocol/partyconnection/ProtocolToPartyConnections.java

    r9 r21  
    99
    1010import geniusweb.actions.PartyId;
    11 import geniusweb.party.inform.Inform;
     11import geniusweb.inform.Inform;
    1212
    1313/**
    1414 * Contains all parties with their connections. immutable
    1515 */
    16 public class ProtocolToPartyConnections implements Iterable<ProtocolToPartyConn> {
     16public class ProtocolToPartyConnections
     17                implements Iterable<ProtocolToPartyConn> {
    1718        private List<ProtocolToPartyConn> connections;
    1819
  • protocol/src/main/java/geniusweb/protocol/session/DefaultSessionState.java

    r10 r21  
    5757         *                      {@link ProtocolException}s. All errors in our own
    5858         *                      code are bugs (not ProtocolExceptions) and should
    59          *                      result in a throw.
     59         *                      result in a throw and terminate the session.
    6060         */
    6161        public DefaultSessionState(List<Action> actions,
     
    130130        }
    131131
    132         @Override
    133132        public ProtocolException getError() {
    134133                return error;
  • protocol/src/main/java/geniusweb/protocol/session/SessionResult.java

    r20 r21  
    1010import com.fasterxml.jackson.annotation.JsonTypeInfo;
    1111
    12 import geniusweb.issuevalue.Bid;
     12import geniusweb.inform.Agreements;
    1313import geniusweb.references.PartyWithProfile;
    1414
     
    2020public class SessionResult {
    2121        private final List<PartyWithProfile> participants;
    22         private final Bid agreement;
     22        private final Agreements agreements;
    2323        private final List<Double> penalties;
    2424
     
    3333         *                     never be null. Some of them may have entered later of
    3434         *                     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.
    3736         * @param penalties    the penalties in [0,1] for each participant, same
    3837         *                     order as the participants list.
     
    4847        public SessionResult(
    4948                        @JsonProperty("participants") List<PartyWithProfile> participants,
    50                         @JsonProperty("agreement") Bid agreement,
     49                        @JsonProperty("agreements") Agreements agreements,
    5150                        @JsonProperty("penalties") List<Double> penalties,
    5251                        @JsonProperty("error") Throwable error) {
    5352                this.participants = participants;
    54                 this.agreement = agreement;
     53                this.agreements = agreements;
    5554                this.penalties = penalties;
    5655                this.error = error;
     
    6968
    7069        /**
    71          * 8return the final agreement {@link Bid} of the session. Null if no
    72          * agreement was reached.
     70         * 8return the final {@link Agreements} of the session. May be empty, not
     71         * null
    7372         */
    74         public Bid getAgreement() {
    75                 return agreement;
     73        public Agreements getAgreements() {
     74                return agreements;
    7675        };
    7776
     
    9998        @Override
    10099        public String toString() {
    101                 return "SessionResult[" + participants + "," + agreement + ","
     100                return "SessionResult[" + participants + "," + agreements + ","
    102101                                + penalties + "," + error + "]";
    103102        }
     
    108107                int result = 1;
    109108                result = prime * result
    110                                 + ((agreement == null) ? 0 : agreement.hashCode());
     109                                + ((agreements == null) ? 0 : agreements.hashCode());
    111110                result = prime * result + ((error == null) ? 0 : error.hashCode());
    112111                result = prime * result
     
    126125                        return false;
    127126                SessionResult other = (SessionResult) obj;
    128                 if (agreement == null) {
    129                         if (other.agreement != null)
     127                if (agreements == null) {
     128                        if (other.agreements != null)
    130129                                return false;
    131                 } else if (!agreement.equals(other.agreement))
     130                } else if (!agreements.equals(other.agreements))
    132131                        return false;
    133132                if (error == null) {
  • protocol/src/main/java/geniusweb/protocol/session/SessionSettings.java

    r10 r21  
    66
    77import geniusweb.protocol.NegoSettings;
     8import geniusweb.protocol.session.amop.AMOPSettings;
     9import geniusweb.protocol.session.mopac.MOPACSettings;
    810import geniusweb.protocol.session.saop.SAOPSettings;
    911import geniusweb.protocol.session.shaop.SHAOPSettings;
     
    1517 */
    1618@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) })
    1822public interface SessionSettings extends NegoSettings {
    1923
  • protocol/src/main/java/geniusweb/protocol/session/SessionState.java

    r20 r21  
    66
    77import geniusweb.actions.Action;
    8 import geniusweb.issuevalue.Bid;
     8import geniusweb.inform.Agreements;
    99import geniusweb.progress.Progress;
    1010import geniusweb.protocol.NegoState;
     11import geniusweb.protocol.session.amop.AMOPState;
     12import geniusweb.protocol.session.mopac.MOPACState;
    1113import geniusweb.protocol.session.saop.SAOPState;
    1214import geniusweb.protocol.session.shaop.SHAOPState;
     
    3537 */
    3638@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) })
    3942public interface SessionState extends NegoState {
    4043
     
    4548         *
    4649         * @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
    4852         */
    4953        List<Action> getActions();
     
    6468         *         {@link #isFinal()}.
    6569         */
    66         Bid getAgreement();
     70        Agreements getAgreements();
    6771
    6872        /**
  • protocol/src/main/java/geniusweb/protocol/session/TeamOfPartiesAndProfiles.java

    r10 r21  
    77import com.fasterxml.jackson.annotation.JsonSubTypes;
    88
    9 import geniusweb.protocol.session.saop.SaopPartyWithProfile;
    109import geniusweb.protocol.session.shaop.ShaopTeam;
    1110import geniusweb.references.PartyWithProfile;
     
    2322// and do not (de)serialize individual TeamOfPartiesAndProfiles.
    2423//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
    25 @JsonSubTypes({ @JsonSubTypes.Type(value = SaopPartyWithProfile.class),
     24@JsonSubTypes({ @JsonSubTypes.Type(value = OnePartyTeam.class),
    2625                @JsonSubTypes.Type(value = ShaopTeam.class) })
    2726public interface TeamOfPartiesAndProfiles {
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOP.java

    r10 r21  
    1515import geniusweb.deadline.Deadline;
    1616import 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;
     17import geniusweb.inform.ActionDone;
     18import geniusweb.inform.Finished;
     19import geniusweb.inform.Inform;
     20import geniusweb.inform.Settings;
     21import geniusweb.inform.YourTurn;
    2222import geniusweb.progress.ProgressFactory;
    2323import geniusweb.protocol.CurrentNegoState;
     
    227227                        } catch (IOException e) {
    228228                                throw new ProtocolException("Failed to initialize",
    229                                                 connection.getParty().getName(), e);
     229                                                connection.getParty(), e);
    230230                        }
    231231                }
     
    257257         * Synchronized so that we always handle only 1 action at a time.
    258258         *
    259          * @param partyconn the connection on which the action came in
     259         * @param partyconn the connection on which the action came in.
    260260         * @param action    the {@link Action} taken by some party
    261261         */
     
    266266                        if (err == null) {
    267267                                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);
    272272                        return;
    273273                }
     
    278278                                throw new ProtocolException(
    279279                                                "Party acts without having the turn",
    280                                                 partyconn.getParty().getName());
     280                                                partyconn.getParty());
    281281                        }
    282282                        state.getConnections().broadcast(new ActionDone(action));
     
    286286                } catch (Throwable e) {
    287287                        handleError("failed to handle action " + action,
    288                                         partyconn.getParty().getName(), e);
     288                                        partyconn.getParty(), e);
    289289                }
    290290
     
    301301                        state.getConnections().get(party).send(new YourTurn());
    302302                } catch (IOException e) {
    303                         handleError("failed to send YourTurn", party.getName(), e);
     303                        handleError("failed to send YourTurn", party, e);
    304304                }
    305305        }
     
    313313         */
    314314        private synchronized void handleError(final String message,
    315                         final String party, final Throwable e) {
     315                        final PartyId party, final Throwable e) {
    316316                if (e instanceof ProtocolException) {
    317317                        setState(state.with((ProtocolException) e));
     
    353353                if (!isFinishedInfoSent.compareAndSet(false, true))
    354354                        return;
    355                 Inform finished = new Finished(state.getAgreement());
     355                Inform finished = new Finished(state.getAgreements());
    356356                for (ProtocolToPartyConn conn : state.getConnections()) {
    357357                        sendFinish(conn, finished);
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOPSettings.java

    r10 r21  
    1010
    1111import geniusweb.deadline.Deadline;
     12import geniusweb.protocol.session.OnePartyTeam;
    1213import geniusweb.protocol.session.SessionProtocol;
    1314import geniusweb.protocol.session.SessionSettings;
     
    1718
    1819public class SAOPSettings implements SessionSettings {
    19         private final List<SaopPartyWithProfile> participants;
     20        private final List<OnePartyTeam> participants;
    2021        private final Deadline deadline;
    2122
     
    3031        @JsonCreator
    3132        public SAOPSettings(
    32                         @JsonProperty("participants") List<SaopPartyWithProfile> participants,
     33                        @JsonProperty("participants") List<OnePartyTeam> participants,
    3334                        @JsonProperty("deadline") Deadline deadline) {
    3435                this.participants = participants;
     
    111112        @Override
    112113        public SessionSettings with(TeamOfPartiesAndProfiles party) {
    113                 if (!(party instanceof SaopPartyWithProfile))
     114                if (!(party instanceof OnePartyTeam))
    114115                        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);
    119119                return new SAOPSettings(newparts, deadline);
    120120        }
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOPState.java

    r20 r21  
    66import java.util.List;
    77import java.util.Map;
     8import java.util.Set;
     9import java.util.stream.Collectors;
    810
    911import geniusweb.actions.Accept;
     
    1214import geniusweb.actions.Offer;
    1315import geniusweb.actions.PartyId;
     16import geniusweb.inform.Agreements;
    1417import geniusweb.issuevalue.Bid;
    1518import geniusweb.progress.Progress;
     
    113116
    114117        @Override
    115         public Bid getAgreement() {
     118        public Agreements getAgreements() {
     119                Agreements agree = new Agreements();
    116120                List<Action> acts = getActions();
    117121                int nparticipants = getConnections().size();
    118122                if (nparticipants < 2 || acts.size() < nparticipants) {
    119                         return null;
     123                        return agree;
    120124                }
    121125                Action offer = acts.get(acts.size() - nparticipants);
    122126                if (!(offer instanceof Offer))
    123                         return null;
     127                        return agree;
    124128                Bid bid = ((Offer) offer).getBid();
    125129
     
    128132                                .allMatch(act -> act instanceof Accept
    129133                                                && 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());
    131146        }
    132147
     
    134149        public boolean isFinal(long currentTimeMs) {
    135150                List<Action> acts = getActions();
    136                 return super.isFinal(currentTimeMs) || getAgreement() != null
    137                                 || (!acts.isEmpty()
     151                return super.isFinal(currentTimeMs)
     152                                || !getAgreements().getMap().isEmpty() || (!acts.isEmpty()
    138153                                                && acts.get(acts.size() - 1) instanceof EndNegotiation);
    139154        }
     
    254269                for (int n = 0; n < getConnections().size(); n++)
    255270                        emptylist.add(0d);
    256                 return new SessionResult(getSettings().getAllParties(), getAgreement(),
     271                return new SessionResult(getSettings().getAllParties(), getAgreements(),
    257272                                emptylist, getError());
    258273        }
  • protocol/src/main/java/geniusweb/protocol/session/shaop/BareSHAOPState.java

    r20 r21  
    158158        }
    159159
    160         @Override
    161160        public ProtocolException getError() {
    162161                return error;
     
    182181                        penalties[partyNumbers.get(party)] = spent;
    183182                }
    184                 return new SessionResult(getSettings().getAllParties(), getAgreement(),
     183                return new SessionResult(getSettings().getAllParties(), getAgreements(),
    185184                                Arrays.asList(penalties), getError());
    186185
  • protocol/src/main/java/geniusweb/protocol/session/shaop/SHAOP.java

    r18 r21  
    2121import geniusweb.deadline.Deadline;
    2222import 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;
     23import geniusweb.inform.ActionDone;
     24import geniusweb.inform.Finished;
     25import geniusweb.inform.Inform;
     26import geniusweb.inform.Settings;
     27import geniusweb.inform.YourTurn;
    2828import geniusweb.progress.ProgressFactory;
    2929import geniusweb.protocol.CurrentNegoState;
     
    238238                        } catch (IOException e) {
    239239                                throw new ProtocolException("Failed to initialize",
    240                                                 connection.getParty().getName(), e);
     240                                                connection.getParty(), e);
    241241                        }
    242242                }
     
    276276                } catch (Throwable e) {
    277277                        handleError("failed to handle action " + action,
    278                                         partyconn.getParty().getName(), e);
     278                                        partyconn.getParty(), e);
    279279                }
    280280        }
     
    289289
    290290                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);
    293292
    294293                // check if action allowed
     
    296295                        if (!ALLOWED_ACTIONS.contains(action.getClass())) {
    297296                                throw new ProtocolException(
    298                                                 "Illegal action for SHAOP Party:" + action,
    299                                                 partyid.getName());
     297                                                "Illegal action for SHAOP Party:" + action, partyid);
    300298                        }
    301299                } else {
    302300                        if (!(action instanceof Comparison))
    303301                                throw new ProtocolException(
    304                                                 "Illegal action for COB Party:" + action,
    305                                                 partyid.getName());
     302                                                "Illegal action for COB Party:" + action, partyid);
    306303                }
    307304
     
    316313                        if (!partyconn.getParty().equals(state.getCurrentTeam()))
    317314                                throw new ProtocolException(
    318                                                 "Party acts without having the turn",
    319                                                 partyid.getName());
     315                                                "Party acts without having the turn", partyid);
    320316                        setState(state.with(partyconn.getParty(), action));
    321317                        state.connections.broadcast(new ActionDone(action));
     
    336332                        state.getConnections().get(party).send(new YourTurn());
    337333                } catch (IOException e) {
    338                         handleError("failed to send YourTurn", party.getName(), e);
     334                        handleError("failed to send YourTurn", party, e);
    339335                }
    340336        }
     
    348344         */
    349345        private synchronized void handleError(final String message,
    350                         final String party, final Throwable e) {
     346                        final PartyId party, final Throwable e) {
    351347                log.log(Level.WARNING, "SHAOP protocol intercepted error due to party "
    352348                                + party + ": " + message, e);
     
    388384                if (!isFinishedInfoSent.compareAndSet(false, true))
    389385                        return;
    390                 Inform finished = new Finished(state.getAgreement());
     386                Inform finished = new Finished(state.getAgreements());
    391387                state.connections.stream().forEach(conn -> sendFinish(conn, finished));
    392388                notifyListeners(new CurrentNegoState(state));
  • protocol/src/main/java/geniusweb/protocol/session/shaop/SHAOPState.java

    r18 r21  
    66import java.util.List;
    77import java.util.Map;
     8import java.util.Set;
     9import java.util.stream.Collectors;
    810
    911import com.fasterxml.jackson.annotation.JsonCreator;
     
    1719import geniusweb.actions.Offer;
    1820import geniusweb.actions.PartyId;
     21import geniusweb.inform.Agreements;
    1922import geniusweb.issuevalue.Bid;
    2023import geniusweb.progress.Progress;
     
    7881        /**
    7982         *
     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         *
    8092         * @param party a Party Id
    8193         * @return the PartyId of the party (COB and SHAOP are partners)
     
    88100        public boolean isFinal(long currentTimeMs) {
    89101                List<Action> acts = getActions();
    90                 return super.isFinal(currentTimeMs) || getAgreement() != null
    91                                 || (!acts.isEmpty()
     102                return super.isFinal(currentTimeMs)
     103                                || !getAgreements().getMap().isEmpty() || (!acts.isEmpty()
    92104                                                && acts.get(acts.size() - 1) instanceof EndNegotiation);
    93105        }
     
    166178
    167179        @Override
    168         public Bid getAgreement() {
     180        public Agreements getAgreements() {
     181                Agreements agrees = new Agreements();
    169182                List<Action> acts = getActions();
    170183                if (acts.isEmpty())
    171                         return null;
     184                        return agrees;
    172185
    173186                int requiredaccepts = getSettings().getTeams().size() - 1;
     
    179192                                continue;
    180193                        if (requiredaccepts == 0 && act instanceof Offer)
    181                                 return ((Offer) act).getBid();
     194                                return agrees.with(((Offer) act).getBid(), getLeaders());
    182195                        if (!(act instanceof Accept))
    183                                 return null;
     196                                return agrees;
    184197                        requiredaccepts--;
    185198                }
    186                 return null;
     199                return agrees;
    187200        }
    188201
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettings.java

    r18 r21  
    99import com.fasterxml.jackson.annotation.JsonProperty;
    1010
     11import geniusweb.protocol.session.OnePartyTeam;
    1112import geniusweb.protocol.session.SessionSettings;
    1213import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
     14import geniusweb.protocol.session.amop.AMOPSettings;
     15import geniusweb.protocol.session.mopac.MOPACSettings;
    1316import geniusweb.protocol.session.saop.SAOPSettings;
    14 import geniusweb.protocol.session.saop.SaopPartyWithProfile;
    1517import geniusweb.protocol.session.shaop.SHAOPSettings;
    1618import geniusweb.protocol.session.shaop.ShaopTeam;
     
    106108                        throw new IllegalArgumentException("nTournaments must be >0");
    107109                int teamsize;
    108                 if (sesettings instanceof SAOPSettings)
     110                if (sesettings instanceof SAOPSettings
     111                                || sesettings instanceof MOPACSettings
     112                                || sesettings instanceof AMOPSettings)
    109113                        teamsize = 1;
    110114                else if (sesettings instanceof SHAOPSettings)
     
    283287                        public TeamOfPartiesAndProfiles apply(Team team,
    284288                                        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),
    287293                                                        profilelist.getProfiles().get(0));
    288294                                else if (sessionsettings instanceof SHAOPSettings) {
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java

    r20 r21  
    55import java.util.List;
    66
    7 import geniusweb.protocol.ProtocolException;
    87import geniusweb.protocol.session.SessionResult;
    98import geniusweb.protocol.session.SessionSettings;
     
    6564        }
    6665
    67         @Override
    68         public ProtocolException getError() {
    69                 return null;
    70         }
    71 
    7266        /**
    7367         *
Note: See TracChangeset for help on using the changeset viewer.