Class AppInstance

java.lang.Object
vaadinx.AppInstance

public final class AppInstance extends Object
Storage whose lifetime is one running app instance — the home for what a desktop Swing app kept in static fields (M1D_former_singletons). A migrated app's holder is one line over it:
public static FormerSingletons get() {
    return AppInstance.get(FormerSingletons.class, FormerSingletons::new);
}

Values are created on first touch, shared by everything that app does, reachable from everywhere that app runs — its WINDOW_CLOSING cleanup included — and gone when the app is. They survive an F5 and die with the browser tab.

UI-thread-confined, with one exception: get(Class, Supplier) also resolves on the request-less teardown threads, where a session is current but no UI is.

The store is TabScope, kept private so it can change: "one running app instance" maps 1:1 onto a browser tab only while SB-Emulators runs one app per session (D_active_ui_pointer). Not inlined to TabScope.getCurrent().getValues() at the call site, tempting as that looks — getCurrent() needs a current UI, which D_shutdown_lifecycle shutdown does not have, so the inlined form throws in exactly the handler that flushes caches and saves preferences. That is not an upstream oversight to wait out: a session may hold several tab scopes and the library cannot know which is the app. AppTab does, which is why resolution lands here.

  • Method Details

    • get

      public static <T> T get(Class<T> type, Supplier<T> factory)
      The app instance's value of the given type, created by factory on first touch and returned as-is afterwards.
      Parameters:
      type - identity of the value within the app instance
      factory - invoked at most once per app instance; must not return null
      Returns:
      never null
      Throws:
      IllegalStateException - from a background thread ( SwingWorker.doInBackground, a raw Thread), or before the app's tab scope is ready — a static initializer, or an app that never wired SwingBridgeEmulatorsBootstrap. The message names the likely cause.