Class AltsRuntime<H>

java.lang.Object
lol.trq.alts.AltsRuntime<H>
Type Parameters:
H - the host's opaque texture-handle type (for example a NanoVG image handle)
All Implemented Interfaces:
AutoCloseable

public final class AltsRuntime<H> extends Object implements AutoCloseable
Central wiring object for the consumer-agnostic account library. The host supplies its platform seams through AltsRuntime.Builder; the library exposes an AltLoginService, a generic SkinAvatarCache, and the runtime's own AccountStore and HostSecrets.

Build it during host initialization, before any alt screen opens. Each runtime owns its stores: two runtimes in one process, on two directories, never see each other's accounts or secrets. Two runtimes cannot share a store file; the second one's AltsRuntime.Builder.build() fails.

A runtime holds a lock on each store file for as long as it is open, so a host closes it when done with it, ideally with try-with-resources. close() writes what is still waiting and releases the files. A host that never closes it loses nothing on a normal exit: a shutdown hook flushes the stores.

Since:
0.1.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Accumulating builder that injects the host seams.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the account service, for validating or renewing a stored account without installing it as the live session.
    accountServices(String accessToken, String accountUuid)
    Returns the account-management surface for a bare access token, when the caller holds a token rather than a stored AltAccount.
    Returns the full account-management surface for one account — profile, entitlements, name, skin, cape — built over its access token.
    Returns the bulk surface, for running one operation over many accounts at a pace the service will tolerate.
    void
    Closes the runtime: writes both stores' pending changes, releases their file locks, and stops their background writers and the shutdown hooks that would otherwise flush them at exit; closes the transport's pooled proxy tunnels; and shuts down the executor if the library created it.
    gameStats(String serverId)
    Returns the lazy, cached game-stats lookup for one server, keyed by player UUID.
    Returns the login service callers use to authenticate accounts.
    Returns the public profile lookup — a player's name and UUID, by either — which needs no account and sends no token.
    Returns this runtime's host secrets: the per-user key/value secrets kept apart from the accounts.
    Returns the avatar cache, generic over this host's texture-handle type.
    Returns this runtime's account store: the saved accounts, the current account, and the encrypted file behind them.
    Returns the toast sink the host supplied, the one route for raising a notification.
    Returns the shared vault's way to AVP 0.5 hosts: it connects to a host on this runtime's transport (its proxy provider, timeouts and executor), by the host's key, and caches the hosts' bearer tokens for this runtime alone.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • store

      public AccountStore store()
      Returns this runtime's account store: the saved accounts, the current account, and the encrypted file behind them. It was loaded from disk by AltsRuntime.Builder.build().
      Returns:
      the account store
      Since:
      1.0.0
    • secrets

      public HostSecrets secrets()
      Returns this runtime's host secrets: the per-user key/value secrets kept apart from the accounts. They were loaded from disk by AltsRuntime.Builder.build().
      Returns:
      the host secrets
      Since:
      1.0.0
    • close

      public void close()
      Closes the runtime: writes both stores' pending changes, releases their file locks, and stops their background writers and the shutdown hooks that would otherwise flush them at exit; closes the transport's pooled proxy tunnels; and shuts down the executor if the library created it. An executor the host passed to AltsRuntime.Builder.executor(Executor) is left running. Idempotent; a second call does nothing. Once this returns, another runtime may open the same directory.

      Afterwards the stores write nothing. Their contents stay readable; a mutator still changes the store in memory but records "the store is closed" on saveError() instead of writing, and load() reads nothing. The transport refuses every request made from then on, and a library-created executor refuses new tasks while letting running ones finish, so a sign-in still in flight when the runtime closes resolves, as a failure if it still had a request to make, and what it would have saved is not saved.

      Whatever was waiting on the runtime ends here too: a bulk run paced between entries, a device-code sign-in between polls, a scheduled name claim, a browser sign-in waiting for its callback. Each such wait fails on the thread that calls close(), and so do the callbacks chained onto it: a bulk run's BulkProgress.finished and the completion of its report, and whatever a sign-in's future runs as it fails, including continuations the host attached to it. A host that calls close() from its main thread should expect that work there, and must not block in such a callback on something only close() would release.

      The vault's cached host tokens are dropped, and a vault operation still in flight fails with AltsFailure.Kind.CANCELLED at its next request.

      A wait that was due far in the future, such as a claim scheduled hours ahead, is failed at once, but the JDK keeps the small task that would have woken it queued in its own delay scheduler until its original time; that task then does nothing.

      Specified by:
      close in interface AutoCloseable
      Since:
      1.0.0
    • loginService

      public AltLoginService loginService()
      Returns the login service callers use to authenticate accounts.
      Returns:
      the login service
      Since:
      0.1.0
    • accountService

      public AltAccountService accountService()
      Returns the account service, for validating or renewing a stored account without installing it as the live session. A host sweeping every alt it holds wants this rather than AltLoginService.loginAccount(AltAccount), which would switch session once per account.
      Returns:
      the account service
      Since:
      0.8.0
    • accountServices

      public AccountServices accountServices(AltAccount account)
      Returns the full account-management surface for one account — profile, entitlements, name, skin, cape — built over its access token. For operating on an account you hold a live token for; nothing here installs a session.
      Parameters:
      account - the account to operate on
      Returns:
      the account services
      Since:
      0.11.0
    • accountServices

      public AccountServices accountServices(String accessToken, String accountUuid)
      Returns the account-management surface for a bare access token, when the caller holds a token rather than a stored AltAccount.
      Parameters:
      accessToken - the Minecraft access token
      accountUuid - the account UUID for request routing, or null
      Returns:
      the account services
      Since:
      0.11.0
    • profileLookup

      public ProfileLookupService profileLookup()
      Returns the public profile lookup — a player's name and UUID, by either — which needs no account and sends no token.
      Returns:
      the profile lookup service
      Since:
      0.12.0
    • bulk

      public BulkOperations bulk()
      Returns the bulk surface, for running one operation over many accounts at a pace the service will tolerate. Nothing it does installs a session.
      Returns:
      the bulk operations
      Since:
      0.9.0
    • skinCache

      public SkinAvatarCache<H> skinCache()
      Returns the avatar cache, generic over this host's texture-handle type. Keyed by UUID, so a renamed account keeps its head.
      Returns:
      the skin avatar cache
      Since:
      0.1.0
    • gameStats

      public AsyncCache<String, GameStats> gameStats(String serverId)
      Returns the lazy, cached game-stats lookup for one server, keyed by player UUID. If no source was registered for serverId, returns an empty cache that always yields null; a failed fetch likewise surfaces as null from AsyncCache.get(Object), so callers degrade cleanly.
      Parameters:
      serverId - the server whose stats to look up (matches a registered source's id)
      Returns:
      the per-server game-stats cache
      Since:
      0.3.0
    • toasts

      public ToastSink toasts()
      Returns the toast sink the host supplied, the one route for raising a notification. The library keeps no static sink of its own.
      Returns:
      the toast sink
      Since:
      0.1.0
    • vault

      public VaultHosts vault()
      Returns the shared vault's way to AVP 0.5 hosts: it connects to a host on this runtime's transport (its proxy provider, timeouts and executor), by the host's key, and caches the hosts' bearer tokens for this runtime alone. Open a repository on a connection with SharedVault.
      Returns:
      the vault entry
      Since:
      1.0.0