> For the complete documentation index, see [llms.txt](https://docs.marioded.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.marioded.com/api-how-to-guides/availability.md).

# Availability and dispatch

Send an authorized viewer to a replay server and understand what dispatch completion means.

**Runtime:** lobby · **Entry point:** `ReverseLobby` · **Watch calls:** Bukkit main thread

## Prefer the high-level lobby service

If a player selects a replay in your lobby UI, call:

```java
ReverseLobby lobby = ReverseLobby.get().orElseThrow();
lobby.getDispatchService().watch(viewer, replayId)
    .whenComplete((result, failure) -> {
        if (failure != null) {
            plugin.getLogger().log(Level.WARNING, "Could not dispatch viewer", failure);
        } else {
            plugin.getLogger().info("Replay dispatch result: " + result);
        }
    });
```

Here `plugin` is our integration's JavaPlugin, `viewer` is the requesting player, and `replayId` is their selection. Invoke this from the main thread. The service performs the lobby-policy access check and handoff sequence; the callback above only logs the result.

Call on the main thread. The returned stage can complete on a backend thread. Handle an exceptional completion in addition to the result enum:

| Result            | Meaning                                                                      |
| ----------------- | ---------------------------------------------------------------------------- |
| `SUCCESS`         | Pending playback persisted and proxy transfer message sent.                  |
| `NOT_AUTHORIZED`  | Missing replay or actor not allowed to view it.                              |
| `NO_REPLAYER`     | No fresh player-node heartbeat.                                              |
| `TRANSFER_FAILED` | Request could not complete, including an overlapping request by that viewer. |

The service uses the lobby's current access policy and guards duplicate in-flight requests. Do not bypass that with raw pending-selection writes merely to hide an authorization failure.

{% hint style="info" %}
**Dispatch success means “handoff sent.”** It does not confirm that the proxy connected the viewer or playback started. Observe the target runtime's start event when you need that acknowledgment.
{% endhint %}

## What availability stores

`Availability` represents:

* `heartbeat(nodeId)` and `leave(nodeId)` for node liveness.
* `active()` for fresh nodes, ordered oldest heartbeat first.
* `pending(nodeId, viewerId, PendingPlayback)` to store a short-lived selection.
* `take(nodeId, viewerId)` to consume that selection once.

`PendingPlayback` contains the replay ID and origin server. Selections expire after five minutes. This contract does not expose reservations, queue position, capacity, match status, or playback progress.

## SQL and Redis

Factories supply concrete availability backends. `AvailabilityService` registers factories, opens the configured backend, manages node heartbeat/start lifecycle, and closes owned resources. Database availability depends on an opened SQL storage resource; Redis is independently configured and lazily loads its runtime libraries.

A facade may return null from `getAvailability()` when networking is disabled. Ordinary plugins should borrow that configured backend rather than closing it or starting a second heartbeat loop over the same runtime instance.

The public entry points do not automatically discover arbitrary external availability factories. Use the configured backend for normal lobby integrations; check the supported extension hooks before attempting to introduce a new backend.

## Transfer is not confirmation

The transfer implementation sends a `Connect` message over the BungeeCord channel. Dispatch success does not confirm arrival. The target player runtime consumes a selection when the viewer joins and then loads the replay. Expiry, proxy errors, disconnection, or storage failure can prevent playback after dispatch was accepted.

If your application needs a guaranteed “viewer is now watching” signal, observe `PlaybackStartEvent` on the target runtime and communicate it through your own application channel. Do not reinterpret `SUCCESS` as that acknowledgment.

## Integrating a custom lobby menu

Use the catalog to display accessible metadata and the dispatch service for Watch. The shared `MenuActionRegistry` lets you attach custom actions without importing Inventory Framework. Obtain it from `ReverseLobby`, not from a new registry instance that the real menu never uses.

For a purely local viewing integration, use `ReversePlayer` instead. Availability is unnecessary when no cross-server transfer is involved.

{% content-ref url="/pages/sw2rn3Xw68PPxoBh1DT1" %}
[Lobby and proxy setup](/use-reverse/network.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.marioded.com/api-how-to-guides/availability.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
