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

Tries harder to kill parties after deadline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/geniusweb/partiesserver/RunningPartiesUpdater.java

    r4 r16  
    1212 *
    1313 * This object keeps the {@link RunningPartiesRepo} up to date. Main job is to
    14  * remove parties that have been timed out. When a party times out,
    15  * it calls {@link Party#terminate()} but that might fail to stop a party.
    16  * In the end, the protocol should close the connection after the deadline. Start and run only once.
     14 * remove parties that have been timed out. When a party times out, it calls
     15 * {@link Party#terminate()} but that might fail to stop a party. In the end,
     16 * the protocol should close the connection after the deadline. Start and run
     17 * only once.
    1718 */
    1819public class RunningPartiesUpdater implements Runnable {
     
    2324         * when a negotiation runs out of time, the protocol may want to inform all
    2425         * parties about the failed session. If the parties are all killed at that
    25          * moment, this is impossible. Therefore we wait KILL_DELAY extra time before
    26          * really killing the parties.
     26         * moment, this is impossible. Therefore we wait KILL_DELAY extra time
     27         * before really killing the parties.
    2728         */
    2829        private static final long KILL_DELAY = 2000;
     
    3132         * @param repo   the {@link RunningPartiesRepo} that must be updated
    3233         *               automatically
    33          * @param period the period with which to check time-out (ms). Recommended 1000.
    34          *               After constructing you can run this in separate thread or just
    35          *               call {@link #run()}
     34         * @param period the period with which to check time-out (ms). Recommended
     35         *               1000. After constructing you can run this in separate
     36         *               thread or just call {@link #run()}
    3637         *
    3738         */
     
    5354                        }
    5455                } catch (InterruptedException e) {
    55                         System.err.println("ERROR:  RunningPartiesUpdater was interrupted!");
     56                        System.err
     57                                        .println("ERROR:  RunningPartiesUpdater was interrupted!");
    5658                }
    5759        }
    5860
    5961        /**
    60          * Called when some file that may be relevant has changed. Synchronized to avoid
    61          * weird states if filesystem changes rapidly. We ignore everything but jar
    62          * files.
     62         * Removes parties when they ran out of time. Called when some file that may
     63         * be relevant has changed, and periodically every {@link #period}.
     64         * Synchronized to avoid weird states if filesystem changes rapidly. We
     65         * ignore everything but jar files.
    6366         */
    6467        void update() {
     
    6669                        long now = System.currentTimeMillis();
    6770                        if (now >= party.getEndDate().getTime() + KILL_DELAY) {
     71                                log.log(Level.WARNING,
     72                                                "party " + party.getID() + " still running "
     73                                                                + KILL_DELAY / 1000
     74                                                                + "s after deadline. Removed now.");
    6875                                running.remove(party.getID());
    69                                 log.log(Level.WARNING, "party " + party.getID() + " still running 2s after deadline. Removed now.");
     76                                try {
     77                                        Thread.sleep(20);
     78                                } catch (InterruptedException e) {
     79                                }
    7080                        }
    7181                }
Note: See TracChangeset for help on using the changeset viewer.