Class RuntimeSession<R>

java.lang.Object
com.ultikits.ultitools.ui.runtime.RuntimeSession<R>
Type Parameters:
R - the intent's answer type
All Implemented Interfaces:
UiSession<R>
Direct Known Subclasses:
RuntimeGridSession

@Internal class RuntimeSession<R> extends Object implements UiSession<R>
Outcome selection is synchronous; screen cleanup and result delivery are ordered continuations. Existing screens close on the viewer lane (or the global pump after retirement), except owner unload, which closes them synchronously on the unloading thread. A show rejected during or after unload has neither a backend nor bindings and completes inline on its caller's thread, including an async caller. Future dependents run without the runtime lock.
  • Field Details

  • Constructor Details

  • Method Details

    • viewer

      public org.bukkit.entity.Player viewer()
      Description copied from interface: UiSession
      The viewer.
      Specified by:
      viewer in interface UiSession<R>
    • intent

      public UiIntent<R> intent()
      Description copied from interface: UiSession
      The originally submitted intent.
      Specified by:
      intent in interface UiSession<R>
    • result

      public CompletionStage<UiResult<R>> result()
      Description copied from interface: UiSession
      The outcome. Completes exactly once, with the outcome chosen first (see UiSession.isOpen()); a minimal stage, so callers cannot complete it.

      Thread: the stage is completed in a task of the viewer's entity context, or of the global context if the viewer has quit. The one exception is owner unload, which completes it on the unloading thread before the unload returns (on Paper the main thread, which owns every entity context), while the owner's services are still usable. Non-async dependents attached before completion run on the completing thread. Following CompletionStage rules, a non-async dependent attached after completion runs at once on the attaching thread, which may be an async thread. To touch the player from a dependent whatever thread attaches it, use an async variant with the scheduler: session.result().thenAcceptAsync(result -> ..., scheduler.entity(viewer)). If the viewer has quit by then, that executor rejects the task and the dependent stage completes exceptionally with RejectedExecutionException; use scheduler.global() for work that must run even then.

      Specified by:
      result in interface UiSession<R>
    • isOpen

      public boolean isOpen()
      Description copied from interface: UiSession
      Whether no outcome has been chosen yet. The outcome is chosen, at once and on whatever thread it happens, by the first of: a backend's answer or close report, UiSession.close(), the timeout, the viewer quitting, another intent opening for the viewer, the owner's unload. From then on this returns false, GridSession.update(Grid) does nothing and later reports are ignored; the screen is closed and UiSession.result() completed afterwards, as described there.
      Specified by:
      isOpen in interface UiSession<R>
    • isOpenLocked

      boolean isOpenLocked()
    • close

      public void close()
      Description copied from interface: UiSession
      Chooses Closed(CLOSED_BY_CODE) if no outcome has been chosen yet, at once and from any thread. The screen closes and the result completes later, in a task of the viewer's entity context, never inside this call, so calling it from a grid action or an event handler is safe. Idempotent.
      Specified by:
      close in interface UiSession<R>
    • requestClose

      final void requestClose(CloseReason reason)
    • dispatch

      final void dispatch(Runnable task)
    • requestChoose

      final void requestChoose(UiResult<R> result)
    • choose

      final boolean choose(UiResult<R> result)
    • closeAndComplete

      final void closeAndComplete()
    • openTask

      final void openTask(ShowOptions options)
      No supporting backend leaves the previous session untouched. Once a supporting backend is selected, replacement is committed before calling open: an open failure leaves the old session REPLACED and never restores its screen. Backends may select an outcome first (chests use INTERRUPTED for rejected opens); an otherwise unhandled open exception selects UNSUPPORTED.
    • takeBindings

      void takeBindings()
    • detachBindings

      void detachBindings()
    • clicked

      void clicked(GridSlot slot, ClickKind kind)
    • scheduleTimeout

      private void scheduleTimeout(ShowOptions options)
    • cancelTimeout

      private void cancelTimeout(TaskHandle handle)
    • callbacks

      private UiBackend.BackendCallbacks<R> callbacks()