Class BackendRegistry

java.lang.Object
dev.xichil.mvui.BackendRegistry

public final class BackendRegistry extends Object
The backends a jar bundles, and which one serves a running game (TODO.md 5.3).

On each platform the backends are ordered by the first DataVersion they serve. Each one is selected from its first DataVersion up to the next one's start, which also covers snapshots and releases between the checked ranges; the newest is selected for every later version (future snapshots). Versions older than the oldest backend's start get none. The checked last of a descriptor doesn't limit selection; the build check (checkUiBackends) uses it.

For example, the Fabric backends start at DataVersions 1952 (1.14), 2566 (1.16), 3218 (1.19.3), 3463 (1.20) and 4786: a game at 3465 (1.20.1) gets the one starting at 3463, a future snapshot the one starting at 4786, and nothing is selected below 1952. Immutable. Part of the backend contract; mods don't need it.

  • Field Details

    • DESCRIPTORS

      public static final String DESCRIPTORS
      Folder of the descriptors in a platform jar; same as UI_BACKEND_DESCRIPTORS in buildSrc.
      See Also:
    • INDEX

      public static final String INDEX
      One backend id per line: the descriptors bundled next to it (a class loader can't list a folder).
      See Also:
  • Constructor Details

    • BackendRegistry

      public BackendRegistry(List<BackendDescriptor> backends)
      A registry of backends; usually made by load(ClassLoader).
      Parameters:
      backends - the backends; copied
      Throws:
      IllegalArgumentException - if two backends have the same id, or start at the same DataVersion on one platform (selection would be ambiguous)
  • Method Details

    • load

      public static BackendRegistry load(ClassLoader loader) throws IOException
      Reads the backends listed in INDEX. A jar without an index has no backends. Blank lines and lines starting with # in the index are skipped.
      Parameters:
      loader - the class loader whose resources hold the platform jar's descriptors
      Returns:
      the registry
      Throws:
      IOException - if the index names a descriptor that is missing or unreadable
      IllegalArgumentException - if a descriptor is malformed
    • all

      public List<BackendDescriptor> all()
      Every backend, sorted by id.
      Returns:
      an unmodifiable list
    • forPlatform

      public List<BackendDescriptor> forPlatform(UiPlatform platform)
      The backends serving platform, oldest first (by BackendDescriptor.first(UiPlatform)).
      Parameters:
      platform - a loader
      Returns:
      a new list, possibly empty
    • select

      public BackendDescriptor select(UiPlatform platform, int dataVersion)
      The backend for a game at dataVersion on platform: the one with the highest first DataVersion not above dataVersion.
      Parameters:
      platform - the running loader
      dataVersion - the running game's DataVersion
      Returns:
      the backend, or null if the version is older than every backend of that platform (or the platform has none)