Class Installed<T>

java.lang.Object
limn.backend.spi.Installed<T>
Type Parameters:
T - the service

public final class Installed<T> extends Object
The one slot a backend fills for a service the toolkit offers statically: the image decoder, the audio engine, the text ruler, the 3D provider, the crash handler, the UI runtime.

Nine classes kept this slot by hand and wrote the same four operations on it: install (never null), uninstall if it is still mine so that a late teardown cannot clear a newer one, is-installed, and require with a message saying which backend was not started. This is the slot once. What differs per service is what "nothing installed" is — null for most, a no-op ruler or a default crash handler for two — and what the message says.

Reads are volatile: a service is installed by the backend's thread and asked for from workers, and the slot is the one thing both touch.

  • Constructor Details

    • Installed

      public Installed(String missing)
      A slot whose empty state is null.
      Parameters:
      missing - what require() says when nothing is installed
    • Installed

      public Installed(@Nullable T absent, String missing)
      A slot whose empty state is a value of its own: a no-op ruler, a default handler.
      Parameters:
      absent - what the slot holds when nothing is installed; may be null
      missing - what require() says when nothing is installed
  • Method Details

    • install

      public void install(T value)
      Fills the slot, replacing whatever was there.
      Parameters:
      value - the service; never null
    • uninstall

      public void uninstall(T expected)
      Empties the slot if it still holds expected, so that a late teardown cannot clear a newer install.
      Parameters:
      expected - what the caller installed
    • isInstalled

      public boolean isInstalled()
      Returns:
      whether something other than the empty state is installed
    • current

      public @Nullable T current()
      Returns:
      what is installed, or the empty state
    • require

      public T require()
      Returns:
      what is installed
      Throws:
      IllegalStateException - with the message this slot was given, when nothing is