# io.github.libtmux.snapshot.ServerMirror

- **Module:** io.github.libtmux.snapshot
- **Package:** io.github.libtmux:libtmux
- **Language:** Java
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-java/blob/f56392b5d9bc7f1f9c1631842333fb90f3d82d40/libtmux/src/main/java/io/github/libtmux/snapshot/ServerMirror.java#L41
- **Page:** https://libtmux.org/en/java/latest/reference/io-github-libtmux-snapshot-servermirror-servermirror/

A live copy of one tmux server's sessions, windows, panes and clients, rebuilt whenever tmux announces a change.

A control client attached through an anchor session hears what tmux announces. Any
announcement, or a {@link Delivery.Gap} in them, starts a fresh {@link Server#snapshot()} — never
a patch of the last one, since an announcement says that something changed, not everything that
did. Announcements that arrive while a snapshot is being taken collapse into one more rebuild, and
a rebuild that finds nothing different publishes nothing. Each published {@link View} carries an
epoch one above the last, counted by this mirror; it is not a number tmux keeps.

tmux keeps no history of what it announced. When the control client ends, the mirror finds
the anchor session again by its id and attaches through it with a fresh snapshot; if the session
has gone, the mirror ends with {@link TargetGoneException}, and if the server has, with the
failure that said so. A change tmux does not announce to this client, such as a pane retitled in
another session, is seen at the next rebuild, or within {@code refreshEvery} when one is given.

Thread-safe. One virtual thread per mirror listens and rebuilds; {@link #close()} ends it and
the control client with it.

## Members

### Other members

- `awaitNewer` (method): Waits for a view newer than {@code epoch}.
- `cause` (method): Why this mirror ended, when something other than {@link #close()} ended it.
- `clearNewer` (method): Disarms the callback {@link #onNewer} armed, if one is armed.
- `close` (method): Stops listening and detaches the control client. The last view stays readable. Idempotent.
- `current` (method): The latest published view.
- `isEnded` (method): Whether this mirror has stopped publishing, because it was closed or its anchor has gone.
- `onNewer` (method): Arms a one-shot wakeup for when a view newer than {@code epoch} is published or the mirror ends.
- `open` (method): Mirrors the server {@code anchor} belongs to, listening through a control client attached to {@code anchor}.
- `View` (struct): One published state of the server.
