Ignore:
Timestamp:
2018-08-12T13:08:27+02:00 (6 years ago)
Author:
Don-vip
Message:

see #15229 - move Main* termination methods to lifecycle SPI + new class MainTermination

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/spi/lifecycle/Lifecycle.java

    r14139 r14140  
    99import java.util.concurrent.Future;
    1010
     11import org.openstreetmap.josm.tools.JosmRuntimeException;
    1112import org.openstreetmap.josm.tools.Logging;
    1213import org.openstreetmap.josm.tools.Utils;
     
    2021
    2122    private static volatile InitStatusListener initStatusListener;
     23
     24    private static volatile Runnable shutdownSequence;
    2225
    2326    private Lifecycle() {
     
    3942    public static void setInitStatusListener(InitStatusListener listener) {
    4043        initStatusListener = Objects.requireNonNull(listener);
     44    }
     45
     46    /**
     47     * Gets shutdown sequence.
     48     * @return shutdown sequence
     49     * @since 14140
     50     */
     51    public static Runnable getShutdownSequence() {
     52        return shutdownSequence;
     53    }
     54
     55    /**
     56     * Sets shutdown sequence.
     57     * @param sequence shutdown sequence. Must not be null
     58     * @since 14140
     59     */
     60    public static void setShutdownSequence(Runnable sequence) {
     61        shutdownSequence = Objects.requireNonNull(sequence);
    4162    }
    4263
     
    6687            }
    6788        } catch (InterruptedException | ExecutionException ex) {
    68             throw new RuntimeException(ex);
     89            throw new JosmRuntimeException(ex);
    6990        }
    7091
     
    7798            try {
    7899                task.call();
    79             } catch (RuntimeException e) {
     100            } catch (JosmRuntimeException e) {
    80101                // Can happen if the current projection needs NTV2 grid which is not available
    81102                // In this case we want the user be able to change his projection
     
    84105        }
    85106    }
     107
     108    /**
     109     * Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
     110     * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code.
     111     * @param exitCode The return code
     112     * @return {@code true}
     113     * @since 14140
     114     */
     115    public static boolean exitJosm(boolean exit, int exitCode) {
     116        if (shutdownSequence != null) {
     117            shutdownSequence.run();
     118        }
     119
     120        if (exit) {
     121            System.exit(exitCode);
     122        }
     123        return true;
     124    }
    86125}
Note: See TracChangeset for help on using the changeset viewer.