SessionState is shared by all Terramenta based applications

Issue #43 resolved
Bruce Schubert created an issue

The WorldWindManager sessionState is written to a folder shared by all Terramenta based applications. This is a problem when the map set used by one application is different than another.

I suggest the SessionState be stored in the application's userdir. E.g.,

sessionState = new SessionState( "." + NbBundle.getBranding())

Comments (7)

  1. Chris Heidt

    I cannot duplicate your issue. I've tested this on two separate systems and the World Wind session state gets saved in the users directory alongside the users Terramenta session.

    {user}\AppData\Roaming\ .terramenta {user}\AppData\Roaming\com.terramenta.globe.WorldWindManager

    Is your environment restricting writes? It attempts to write to the user directory first but falls back to the local install directory if it can't.

  2. Bruce Schubert reporter

    I don't think I explained the problem sufficiently. In my case, Terramenta.exe and WMT.exe are seem to be sharing the same session state, as defined by the common key: com.terramenta.globe.WorldWindManager

    C:\Users\bds_000\AppData\Roaming\com.terramenta.globe.WorldWindManager

  3. Bruce Schubert reporter

    BTW: I have a workaround in WMT, so this is not a big issue for me right now.

    @ServiceProvider(service = WorldWindManager.class, position = 1, supersedes = "com.terramenta.globe.WorldWindManager")
    public class EmxsysWorldWindManager extends WorldWindManager {
    
        public static final String EMXSYS_CONFIG = "modules/worldwind-overrides.xml";
        private static final Preferences prefs = NbPreferences.forModule(GlobeOptions.class);
        private final SessionState sessionState = new SessionState("." + NbBundle.getBranding());
        private static final Logger logger = Logger.getLogger(EmxsysWorldWindManager.class.getName());
    
        /**
         * Override WorldWind Configuration Settings with our application defaults while preserving the
         * user option to set the configuration. Assumes this static block is called *after* the base
         * class static block.
         */
        static {
            String config = prefs.get("options.globe.worldwindConfig", "");
            if (config.isEmpty()) {
                File file = InstalledFileLocator.getDefault().locate(EMXSYS_CONFIG, "com.emxsys.wmt.globe", false);
                if (file != null) {
                    System.setProperty("gov.nasa.worldwind.app.config.document", file.getPath());
                }
            }
        }
    
        public EmxsysWorldWindManager() {
            super();
        }
    
        @Override
        public void saveSessionState() {
            logger.log(Level.INFO, "Saving Session ({0})...", sessionState.getSessionKey());
            try {
                sessionState.saveSessionState(getWorldWindow());
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Failed to save session state!", e);
                return;
            }
            logger.info("Session has been saved.");
        }
    
        @Override
        public void restoreSessionState() {
            logger.info("Restoring Session...");
            try {
                sessionState.restoreSessionState(getWorldWindow());
                getWorldWindow().redraw();
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Failed to restore session state!", e);
                return;
            }
            logger.info("Session has been restored.");
        }
    
    }
    
  4. Log in to comment