import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.simantics.db.management.SingleSessionContextProviderSource;
import org.simantics.ui.SimanticsUI;
import org.simantics.utils.ui.BundleUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*/
public class SimanticsWorkbenchApplication implements IApplication, IExecutableExtension {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SimanticsWorkbenchApplication.class);
/**
* The name of the folder containing metadata information for the workspace.
*/
private static final String WORKSPACE_VERSION_VALUE = "1"; //$NON-NLS-1$
private static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$
+
+ private static final String PROP_SHUTDOWN_GRACE_PERIOD = "simantics.shutdownGracePeriod"; //$NON-NLS-1$
+ private static final long DEFAULT_SHUTDOWN_GRACE_PERIOD = 5000L;
/**
* A special return code that will be recognized by the launcher and used to
// PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench()
int returnCode = PlatformUI.createAndRunWorkbench(display,
createWorkbenchAdvisor(args, processor));
+
+ Long shutdownGracePeriodPropValue = Long.getLong(PROP_SHUTDOWN_GRACE_PERIOD);
+ long shutdownGracePeriod = shutdownGracePeriodPropValue == null
+ ? DEFAULT_SHUTDOWN_GRACE_PERIOD
+ : shutdownGracePeriodPropValue;
// the workbench doesn't support relaunch yet (bug 61809) so
// for now restart is used, and exit data properties are checked
// here to substitute in the relaunch return code if needed
if (returnCode != PlatformUI.RETURN_RESTART) {
+ delayedShutdown(EXIT_OK, shutdownGracePeriod);
return EXIT_OK;
}
// if the exit code property has been set to the relaunch code, then
// return that code now, otherwise this is a normal restart
- return EXIT_RELAUNCH.equals(Integer.getInteger(PROP_EXIT_CODE)) ? EXIT_RELAUNCH
+ int exitCode = EXIT_RELAUNCH.equals(Integer.getInteger(PROP_EXIT_CODE)) ? EXIT_RELAUNCH
: EXIT_RESTART;
+ delayedShutdown(exitCode, shutdownGracePeriod);
+ return exitCode;
} finally {
if (display != null) {
display.dispose();
}
}
+ private void delayedShutdown(int exitCode, long delayMs) {
+ LOGGER.info("Started delayed shutdown with delay {} ms.", delayMs);
+ Thread shutdownThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(delayMs);
+ LOGGER.warn("Delayed shutdown forced the application to exit with code {}.", exitCode);
+ System.exit(exitCode);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ shutdownThread.setDaemon(true);
+ shutdownThread.setName("delayed-shutdown");
+ shutdownThread.start();
+ }
+
/*************************************************************************/
private IArguments parseArguments(String[] args) {