Changeset 9 for protocol/src


Ignore:
Timestamp:
11/28/19 14:40:48 (5 years ago)
Author:
bart
Message:

Release 1.1.0

Location:
protocol/src
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • protocol/src/main/java/geniusweb/protocol/NegoProtocol.java

    r1 r9  
    1010import geniusweb.events.CurrentState;
    1111import geniusweb.events.ProtocolEvent;
    12 import geniusweb.protocol.partyconnection.ConnectionWithPartyFactory;
     12import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    1313import geniusweb.protocol.session.SessionProtocol;
    1414import geniusweb.protocol.session.SessionSettings;
     
    7070         *
    7171         *
    72          * @param connectionfactory the {@link ConnectionWithPartyFactory} that allows
     72         * @param connectionfactory the {@link ProtocolToPartyConnFactory} that allows
    7373         *                          the protocol to connect with the {@link Reference}s
    7474         *                          in the settings
    7575         */
    76         void start(ConnectionWithPartyFactory connectionfactory);
     76        void start(ProtocolToPartyConnFactory connectionfactory);
    7777
    7878        /**
  • protocol/src/main/java/geniusweb/protocol/session/DefaultSessionState.java

    r1 r9  
    1010import geniusweb.progress.Progress;
    1111import geniusweb.protocol.ProtocolException;
    12 import geniusweb.protocol.partyconnection.ConnectionWithParties;
     12import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    1313import geniusweb.references.PartyWithProfile;
    1414
     
    1919        private final List<Action> actions;
    2020
    21         private final transient ConnectionWithParties connections;
     21        private final transient ProtocolToPartyConnections connections;
    2222
    2323        private final Progress progress;
     
    6060         */
    6161        public DefaultSessionState(List<Action> actions,
    62                         ConnectionWithParties conns, Progress progr,
     62                        ProtocolToPartyConnections conns, Progress progr,
    6363                        SessionSettings settings,
    6464                        Map<PartyId, PartyWithProfile> partyprofiles, ProtocolException e) {
     
    6767                }
    6868                if (conns == null) {
    69                         this.connections = new ConnectionWithParties(
     69                        this.connections = new ProtocolToPartyConnections(
    7070                                        Collections.EMPTY_LIST);
    7171                } else {
     
    9292         * @return existing connections.
    9393         */
    94         public ConnectionWithParties getConnections() {
     94        public ProtocolToPartyConnections getConnections() {
    9595                return connections;
    9696        }
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOP.java

    r8 r9  
    2323import geniusweb.protocol.CurrentNegoState;
    2424import geniusweb.protocol.ProtocolException;
    25 import geniusweb.protocol.partyconnection.ConnectionWithParty;
    26 import geniusweb.protocol.partyconnection.ConnectionWithPartyFactory;
     25import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
     26import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    2727import geniusweb.protocol.session.SessionProtocol;
    2828import geniusweb.protocol.session.SessionSettings;
     
    9595        @Override
    9696        public synchronized void start(
    97                         ConnectionWithPartyFactory connectionfactory) {
     97                        ProtocolToPartyConnFactory connectionfactory) {
    9898
    9999                try {
     
    151151         */
    152152        protected synchronized void connect(
    153                         ConnectionWithPartyFactory connectionfactory)
     153                        ProtocolToPartyConnFactory connectionfactory)
    154154                        throws InterruptedException, IOException {
    155155                List<PartyWithProfile> participants = state.getSettings()
     
    158158                                .map(parti -> (parti.getParty().getPartyRef()))
    159159                                .collect(Collectors.toList());
    160                 List<ConnectionWithParty> connections = null;
     160                List<ProtocolToPartyConn> connections = null;
    161161                log.log(Level.INFO, "SAOP connect " + parties);
    162162                while (connections == null) {
     
    218218         */
    219219        protected synchronized void setupParties() throws ProtocolException {
    220                 for (ConnectionWithParty conn : state.getConnections()) {
     220                for (ProtocolToPartyConn conn : state.getConnections()) {
    221221                        conn.addListener(action -> actionRequest(conn, action));
    222222                }
    223223
    224                 for (ConnectionWithParty connection : state.getConnections()) {
     224                for (ProtocolToPartyConn connection : state.getConnections()) {
    225225                        try {
    226226                                sendSettings(connection);
     
    239239         * @throws IOException if party got disconnected
    240240         */
    241         private synchronized void sendSettings(ConnectionWithParty connection)
     241        private synchronized void sendSettings(ProtocolToPartyConn connection)
    242242                        throws IOException {
    243243                PartyId partyid = connection.getParty();
     
    261261         */
    262262        protected synchronized void actionRequest(
    263                         final ConnectionWithParty partyconn, final Action action) {
     263                        final ProtocolToPartyConn partyconn, final Action action) {
    264264                if (action == null) {
    265                         handleError(partyconn
    266                                         + " did null action, breaching the protocol. Closing session",
    267                                         partyconn.getParty().getName(), null);
     265                        Throwable err = partyconn.getError();
     266                        if (err == null) {
     267                                err = new ProtocolException("Party sent a null action",
     268                                                partyconn.getParty().getName());
     269                        }
     270                        handleError(partyconn + "Protocol error",
     271                                        partyconn.getParty().getName(), err);
    268272                        return;
    269273                }
     
    348352                        return;
    349353                Inform finished = new Finished(state.getAgreement());
    350                 for (ConnectionWithParty conn : state.getConnections()) {
     354                for (ProtocolToPartyConn conn : state.getConnections()) {
    351355                        sendFinish(conn, finished);
    352356                }
    353                 notifyChange(new CurrentNegoState(state));
    354         }
    355 
    356         private void sendFinish(ConnectionWithParty connection, Inform finished) {
     357                notifyListeners(new CurrentNegoState(state));
     358        }
     359
     360        private void sendFinish(ProtocolToPartyConn connection, Inform finished) {
    357361                try {
    358362                        connection.send(finished);
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOPState.java

    r4 r9  
    1616import geniusweb.progress.ProgressRounds;
    1717import geniusweb.protocol.ProtocolException;
    18 import geniusweb.protocol.partyconnection.ConnectionWithParties;
    19 import geniusweb.protocol.partyconnection.ConnectionWithParty;
     18import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     19import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    2020import geniusweb.protocol.session.DefaultSessionState;
    2121import geniusweb.protocol.session.SessionSettings;
     
    4242         *                      occurred.
    4343         */
    44         public SAOPState(List<Action> actions, ConnectionWithParties conns,
     44        public SAOPState(List<Action> actions, ProtocolToPartyConnections conns,
    4545                        Progress progress, SessionSettings settings,
    4646                        Map<PartyId, PartyWithProfile> partyprofiles, ProtocolException e) {
     
    5555        public SAOPState(SAOPSettings settings) {
    5656                this(Collections.emptyList(),
    57                                 new ConnectionWithParties(Collections.emptyList()), null,
     57                                new ProtocolToPartyConnections(Collections.emptyList()), null,
    5858                                settings, null, null);
    5959
     
    8282        /**
    8383         *
    84          * @param connection   the new {@link ConnectionWithParty}
     84         * @param connection   the new {@link ProtocolToPartyConn}
    8585         * @param partyprofile the {@link PartyWithProfile} that is associated with
    8686         *                     this state
     
    9191         *         state currently indicate if that already happened or not.
    9292         */
    93         public SAOPState with(ConnectionWithParty connection,
     93        public SAOPState with(ProtocolToPartyConn connection,
    9494                        PartyWithProfile partyprofile) {
    9595                // Only called from the SAOP initialization phase.
    96                 ConnectionWithParties newconns = getConnections().with(connection);
     96                ProtocolToPartyConnections newconns = getConnections().with(connection);
    9797                Map<PartyId, PartyWithProfile> newprofiles = new HashMap<>(
    9898                                getPartyProfiles());
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocol.java

    r1 r9  
    77import geniusweb.protocol.CurrentNegoState;
    88import geniusweb.protocol.SessionResult;
    9 import geniusweb.protocol.partyconnection.ConnectionWithPartyFactory;
     9import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    1010import geniusweb.protocol.session.SessionProtocol;
    1111import geniusweb.protocol.session.SessionSettings;
     
    2929        private final transient Reporter log;
    3030
    31         private ConnectionWithPartyFactory connectionFactory; // FINAL
     31        private ProtocolToPartyConnFactory connectionFactory; // FINAL
    3232        private AllPermutationsState state; // MUTABLE
    3333
     
    4545
    4646        @Override
    47         public void start(ConnectionWithPartyFactory connectionfactory) {
     47        public void start(ProtocolToPartyConnFactory connectionfactory) {
    4848                this.connectionFactory = connectionfactory;
    49                 notifyChange(new TournamentStarted(state.getSize().longValue()));
     49                notifyListeners(new TournamentStarted(state.getSize().longValue()));
    5050                startNextSession();
    5151        }
     
    8585                                                sessionstate.getAgreement(), sessionstate.getError());
    8686                                state = state.with(result);
    87                                 notifyChange(new CurrentNegoState(state));
     87                                notifyListeners(new CurrentNegoState(state));
    8888                                if (!state.isFinal(now)) {
    8989                                        startNextSession();
  • protocol/src/test/java/geniusweb/protocol/session/ConnectionWithPartiesTest.java

    r1 r9  
    1414
    1515import geniusweb.actions.PartyId;
    16 import geniusweb.protocol.partyconnection.ConnectionWithParties;
    17 import geniusweb.protocol.partyconnection.ConnectionWithParty;
     16import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     17import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    1818import tudelft.utilities.junit.GeneralTests;
    1919
    2020public class ConnectionWithPartiesTest
    21                 extends GeneralTests<ConnectionWithParties> {
     21                extends GeneralTests<ProtocolToPartyConnections> {
    2222        PartyId party1 = new PartyId("party1");
    2323        PartyId party2 = new PartyId("party2");
    2424        PartyId party3 = new PartyId("party3");
    2525
    26         private ConnectionWithParty con1 = mock(ConnectionWithParty.class);
    27         private ConnectionWithParty con2 = mock(ConnectionWithParty.class);
    28         private ConnectionWithParty con3 = mock(ConnectionWithParty.class);
     26        private ProtocolToPartyConn con1 = mock(ProtocolToPartyConn.class);
     27        private ProtocolToPartyConn con2 = mock(ProtocolToPartyConn.class);
     28        private ProtocolToPartyConn con3 = mock(ProtocolToPartyConn.class);
    2929
    30         private ConnectionWithParties conns1 = new ConnectionWithParties(
     30        private ProtocolToPartyConnections conns1 = new ProtocolToPartyConnections(
    3131                        Arrays.asList(con1, con2));
    32         private ConnectionWithParties conns1a = new ConnectionWithParties(
     32        private ProtocolToPartyConnections conns1a = new ProtocolToPartyConnections(
    3333                        Arrays.asList(con1, con2));
    34         private ConnectionWithParties conns2 = new ConnectionWithParties(
     34        private ProtocolToPartyConnections conns2 = new ProtocolToPartyConnections(
    3535                        Arrays.asList(con1, con3));
    36         private ConnectionWithParties conns3 = new ConnectionWithParties(
     36        private ProtocolToPartyConnections conns3 = new ProtocolToPartyConnections(
    3737                        Arrays.asList(con2, con1));
    38         private ConnectionWithParties conns4 = new ConnectionWithParties(
     38        private ProtocolToPartyConnections conns4 = new ProtocolToPartyConnections(
    3939                        Arrays.asList(con2, con1, con3));
    40         private ConnectionWithParties conns5 = new ConnectionWithParties(
     40        private ProtocolToPartyConnections conns5 = new ProtocolToPartyConnections(
    4141                        Arrays.asList(con2, con1, con3, con1));
    4242
     
    5454
    5555        @Override
    56         public List<List<ConnectionWithParties>> getGeneralTestData() {
     56        public List<List<ProtocolToPartyConnections>> getGeneralTestData() {
    5757                return Arrays.asList(Arrays.asList(conns1, conns1a),
    5858                                Arrays.asList(conns2), Arrays.asList(conns3),
     
    9898        @Test
    9999        public void withPartyTest() {
    100                 ConnectionWithParties conns = conns3.with(con3);
     100                ProtocolToPartyConnections conns = conns3.with(con3);
    101101                assertEquals(2, conns3.size());
    102102                assertEquals(3, conns.size());
  • protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java

    r8 r9  
    2727import geniusweb.progress.ProgressTime;
    2828import geniusweb.protocol.ProtocolException;
    29 import geniusweb.protocol.partyconnection.ConnectionWithParties;
     29import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    3030import geniusweb.protocol.session.saop.SAOPSettings;
    3131import geniusweb.references.Parameters;
     
    4848                PartyId party1 = new PartyId("party1");
    4949                actions.add(new EndNegotiation(party1));
    50                 ConnectionWithParties conns = new ConnectionWithParties(
     50                ProtocolToPartyConnections conns = new ProtocolToPartyConnections(
    5151                                Collections.EMPTY_LIST);
    5252                DeadlineTime deadline = new DeadlineTime(1000);
     
    126126
    127127        public DefaultSessionState1(List<Action> actions,
    128                         ConnectionWithParties conns, Progress progr,
     128                        ProtocolToPartyConnections conns, Progress progr,
    129129                        SessionSettings settings,
    130130                        Map<PartyId, PartyWithProfile> partyprofiles, ProtocolException e) {
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java

    r4 r9  
    2727import geniusweb.progress.ProgressTime;
    2828import geniusweb.protocol.ProtocolException;
    29 import geniusweb.protocol.partyconnection.ConnectionWithParties;
    30 import geniusweb.protocol.partyconnection.ConnectionWithParty;
     29import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     30import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    3131import geniusweb.protocol.session.SessionSettings;
    3232import tudelft.utilities.junit.GeneralTests;
     
    4242        private List<Action> actions2 = Arrays.asList(action);
    4343
    44         private ConnectionWithParty party1conn = mock(ConnectionWithParty.class);
    45         private ConnectionWithParty party2conn = mock(ConnectionWithParty.class);
    46         private ConnectionWithParty party3conn = mock(ConnectionWithParty.class);
    47 
    48         private ConnectionWithParties connections = new ConnectionWithParties(
     44        private ProtocolToPartyConn party1conn = mock(ProtocolToPartyConn.class);
     45        private ProtocolToPartyConn party2conn = mock(ProtocolToPartyConn.class);
     46        private ProtocolToPartyConn party3conn = mock(ProtocolToPartyConn.class);
     47
     48        private ProtocolToPartyConnections connections = new ProtocolToPartyConnections(
    4949                        Arrays.asList(party1conn, party2conn));
    50         private ConnectionWithParties connections2 = new ConnectionWithParties(
     50        private ProtocolToPartyConnections connections2 = new ProtocolToPartyConnections(
    5151                        Arrays.asList(party1conn, party3conn));
    52         private ConnectionWithParties connections3 = new ConnectionWithParties(
     52        private ProtocolToPartyConnections connections3 = new ProtocolToPartyConnections(
    5353                        Arrays.asList(party1conn, party2conn, party3conn));
    5454
     
    114114        @Test
    115115        public void constructWith0Connection() {
    116                 new SAOPState(actions, new ConnectionWithParties(Arrays.asList()),
     116                new SAOPState(actions, new ProtocolToPartyConnections(Arrays.asList()),
    117117                                progresstime, settings, null, null);
    118118        }
     
    132132        @Test
    133133        public void testNextActor2() {
    134                 ConnectionWithParties conns = new ConnectionWithParties(
     134                ProtocolToPartyConnections conns = new ProtocolToPartyConnections(
    135135                                Arrays.asList(party2conn, party3conn));
    136136                SAOPState state = new SAOPState(actions, conns, progresstime, settings,
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java

    r8 r9  
    3939import geniusweb.progress.Progress;
    4040import geniusweb.protocol.ProtocolException;
    41 import geniusweb.protocol.partyconnection.ConnectionWithParties;
    42 import geniusweb.protocol.partyconnection.ConnectionWithParty;
    43 import geniusweb.protocol.partyconnection.ConnectionWithPartyFactory;
     41import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     42import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
     43import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    4444import geniusweb.references.Parameters;
    4545import geniusweb.references.PartyRef;
     
    7676        private final PartyWithProfile party2 = mock(PartyWithProfile.class);
    7777        private SAOP saop;
    78         private ConnectionWithPartyFactory factory;
     78        private ProtocolToPartyConnFactory factory;
    7979        private List connections;
    80         private ConnectionWithParty conn1 = mock(ConnectionWithParty.class),
    81                         conn2 = mock(ConnectionWithParty.class);
     80        private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class),
     81                        conn2 = mock(ProtocolToPartyConn.class);
    8282        private Map<PartyId, PartyWithProfile> partyprofiles;
    8383        private Progress progress = mock(Progress.class);
    8484        private ProfileRef profile1;
    8585        private ProfileRef profile2;
    86         private ConnectionWithParties connectionswithparties = mock(
    87                         ConnectionWithParties.class);;
     86        private ProtocolToPartyConnections connectionswithparties = mock(
     87                        ProtocolToPartyConnections.class);;
    8888        @SuppressWarnings("unchecked")
    8989        private final Listener<ProtocolEvent> testlistener = mock(Listener.class);
     
    116116                when(settings.getDeadline()).thenReturn(deadlinetime);
    117117
    118                 factory = mock(ConnectionWithPartyFactory.class);
     118                factory = mock(ProtocolToPartyConnFactory.class);
    119119                connections = mock(List.class);
    120120                when(factory.connect(any(List.class))).thenReturn(connections);
     
    159159                when(state.getPartyProfiles()).thenReturn(partyprofiles);
    160160                when(state.getProgress()).thenReturn(progress);
    161                 when(state.with(any(ConnectionWithParty.class),
     161                when(state.with(any(ProtocolToPartyConn.class),
    162162                                any(PartyWithProfile.class))).thenReturn(connectedstate);
    163163                when(state.getNextActor()).thenReturn(PARTY1ID);
  • protocol/src/test/java/geniusweb/protocol/tournament/AllPermutationsProtocolTest.java

    r1 r9  
    2424import geniusweb.protocol.NegoState;
    2525import geniusweb.protocol.SessionResult;
    26 import geniusweb.protocol.partyconnection.ConnectionWithPartyFactory;
     26import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    2727import geniusweb.protocol.session.SessionProtocol;
    2828import geniusweb.protocol.session.SessionSettings;
     
    4242        private final AllPermutationsProtocol app = new AllPermutationsProtocol(
    4343                        state, log);
    44         private final ConnectionWithPartyFactory factory = mock(
    45                         ConnectionWithPartyFactory.class);
     44        private final ProtocolToPartyConnFactory factory = mock(
     45                        ProtocolToPartyConnFactory.class);
    4646        private final SessionSettings settings = mock(SessionSettings.class);
    4747        private final SessionState finalsessionstate = mock(SessionState.class);
     
    140140
    141141        @Override
    142         public void start(ConnectionWithPartyFactory connectionfactory) {
     142        public void start(ProtocolToPartyConnFactory connectionfactory) {
    143143
    144144        }
Note: See TracChangeset for help on using the changeset viewer.