Ignore:
Timestamp:
06/22/20 16:08:10 (4 years ago)
Author:
bart
Message:

Tries harder to kill parties after deadline

Location:
src/main/java/geniusweb/partiesserver/websocket
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/geniusweb/partiesserver/websocket/PartySocket.java

    r9 r16  
    4444public class PartySocket implements ConnectionEnd<Inform, Action> {
    4545        private final static ObjectMapper jackson = new ObjectMapper();
     46        private static final int MAX_MESSAGE_SIZE = 20 * 1024 * 1024;
     47
    4648        private final Reporter log;
    4749        private final RunningPartiesRepo runningparties;
    4850        private final List<Listener<Inform>> listeners = new CopyOnWriteArrayList<Listener<Inform>>();
    49         private static final int MAX_MESSAGE_SIZE = 20 * 1024 * 1024;
     51        private final ActiveThreads threads;
    5052
    5153        // should all be final, except that we can only set them when start is
     
    6668                this.runningparties = parties;
    6769                this.log = reporter;
     70                this.threads = new ActiveThreads(log);
    6871        }
    6972
     
    128131                        throw new IllegalStateException("Unexpected change of session ID");
    129132                }
     133                if (!threads.isEmpty()) {
     134                        log.log(Level.WARNING, "Party " + partyID
     135                                        + " is still busy with previous message");
     136                }
    130137                Inform info = jackson.readValue(informmessage, Inform.class);
    131138                RunningParty party = runningparties.get(partyID);
     
    135142                        log.log(Level.FINE, "Inform " + partyID + ": " + info);
    136143                        try {
     144                                threads.add();
    137145                                party.inform(info);
     146                                threads.remove();
    138147                        } catch (Throwable e) {
    139                                 log.log(Level.WARNING, "Party failed on inform.", e);
    140                                 e.printStackTrace();
    141                                 // severe as someone wants to debug that. Not severe for us
    142                                 // we don't use jackson.writeValueAsString(e) here because
    143                                 // CloseReason has 123 char limit.
    144                                 // The error will be too large to fit and will be truncated
    145                                 // therefore we send a plain string and hope that enough
    146                                 // will arrive at the other side (the protocol)
     148                                threads.remove();
     149                                if (e instanceof ThreadDeath)
     150                                        /*
     151                                         * ThreadDeath always prints stacktrace anwyay, stacktrace
     152                                         * is useless because it contains the thrower's stacktrace
     153                                         * instead of a useful message.
     154                                         */
     155                                        log.log(Level.WARNING,
     156                                                        "Party was killed while handling inform.");
     157                                else
     158                                        log.log(Level.WARNING, "Party failed on inform.", e);
     159                                /*
     160                                 * severe as someone wants to debug that. Not severe for us we
     161                                 * don't use jackson.writeValueAsString(e) here because
     162                                 * CloseReason has 123 char limit. The error will be too large
     163                                 * to fit and will be truncated therefore we send a plain string
     164                                 * and hope that enough will arrive at the other side (the
     165                                 * protocol)
     166                                 */
    147167                                session.close(new CloseReason(
    148168                                                CloseReason.CloseCodes.CLOSED_ABNORMALLY,
     
    186206        public void onClose() throws IOException {
    187207                log.log(Level.INFO, "socket closed to " + partyID);
    188                 /*
    189                  * for now just kill the party. Maybe we can do something with reconnect
    190                  * but that will be complex.
    191                  */
     208                if (!threads.isEmpty()) {
     209                        log.log(Level.WARNING, "Party " + partyID
     210                                        + " failed to terminate. Trying to kill the remaining threads.");
     211                        threads.killall();
     212                }
    192213                runningparties.remove(partyID);
    193214                outstream.stop();
Note: See TracChangeset for help on using the changeset viewer.