# io.github.libtmux.Server.Server

- **Module:** io.github.libtmux.Server
- **Package:** io.github.libtmux:libtmux
- **Language:** Java
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-java/blob/842228310449e879ebcaa3f910597757c9dbffd6/libtmux/src/main/java/io/github/libtmux/Server.java#L51
- **Page:** https://libtmux.org/en/java/latest/reference/io-github-libtmux-server-server/

One tmux server, reached over one transport.

Ownership is decided at construction and never inferred. {@link #open} creates a transport this
server closes exactly once; {@link #using} borrows one the caller keeps, so several servers can
share a transport and closing one leaves the others working.

Closing a server closes a client, not a tmux. It never kills the server process: sessions
outlive the program that made them, which is the entire point of tmux.

Close it anyway. A server that owns its transport holds the threads that drain tmux's output,
and those are not daemons, so that a reply being read when a program ends is finished rather than
truncated. They do let go once they have been idle, so forgetting to close delays a JVM's exit by
seconds instead of preventing it — but only closing releases them at once.

**Threads.** Share one freely. A server holds nothing a call changes, its transport
is thread-safe by contract, and the record of what was typed into each pane is concurrent; calls
from several threads run side by side, bounded by the transport's own admission. The same goes
for every {@link Session}, {@link Window} and {@link Pane} it hands out: each is an immutable view
of one capture, and a method that changes tmux changes tmux rather than the handle. Close it once,
after the last call on any thread.

## Members

- `echo` (method): What this library last typed into each of this server's panes.
- `newSession` (method): Creates a detached session and returns that exact session.
- `hasSession` (method): Whether a session with this name exists.
- `killSession` (method): Ends the session with this name, and everything in it.
- `isAlive` (method): Whether the server is running and answering.
- `requireAlive` (method): Requires a running tmux daemon that answers the liveness probe.
- `failed` (method): One sentence for a tmux command that did not succeed.
- `failure` (method)
- `serverAbsent` (method): Whether a failed command's stderr says the daemon itself is gone, rather than refusing the request.
- `killServer` (method): Ends the tmux server and every session on it.
- `batch` (method): Collects several commands to run in one tmux invocation.
- `chain` (method): Starts a chain of commands where each one acts on what the last one made.
- `expand` (method): Expands a tmux format against the server, and answers with what it came to.
- `runShell` (method): Runs a shell command through tmux, for its effect.
- `runShellCapturing` (method): Runs a shell command through tmux and answers with what it printed.
- `listCommands` (method): Every command this tmux knows, as it prints them.
- `ifShell` (method): Runs one tmux command or another, according to whether a shell command succeeds.
- `lock` (method): Locks every client attached to this server.
- `messages` (method): The server's own message log, newest last.
- `promptHistory` (method): What has been typed at tmux's command prompt, oldest first.
- `clearPromptHistory` (method): Forgets what has been typed at tmux's command prompt.
- `withoutStartingServer` (method)
- `channel` (method): One of this server's wait-for channels, which is where a signal is sent and waited for.
- `variables` (method): Reads only validated tmux variable names, never caller-authored format syntax.
- `paneFields` (method): Chosen fields for every pane on the server, from one listing.
- `setMouseEnabled` (method): Enables or disables mouse handling for sessions on this server.
- `awaitChannel` (method)
- `keys` (method): The server's key bindings: {@code prefix} when binding, every table when listing.
- `buffers` (method): The server's paste buffers, which every session shares.
- `sourceFile` (method): Runs a file of tmux commands, as a configuration file would be run.
- `options` (method): The server-wide options, the ones tmux keeps once per server.
- `globalOptions` (method): The global session options every session inherits unless it sets its own.
- `environment` (method): The server's environment, which every session inherits and every new process is given.
- `hooks` (method): The global hooks every session inherits.
- `version` (method): Which tmux this server is running.
- `identity` (method): Which server this is. Every handle taken from it is scoped by this.
- `requireSameServer` (method)
- `requireSameIncarnation` (method)
- `open` (method): A server over a transport it owns and closes.
- `using` (method): A server over a transport the caller owns. Closing this server never closes it.
- `within` (method): This server, with every command bounded by a deadline of the caller's choosing.
- `builder` (method): A builder holding the documented defaults.
- `config` (method): How this server was configured.
- `cmd` (method): Runs one tmux command against this server.
- `snapshot` (method): Captures the whole hierarchy in at most four listings, retrying once if the server is replaced.
- `sessions` (method): Every session, captured now.
- `windows` (method): Captures every winlink, preserving each session and index placement.
- `panes` (method): Captures every pane on the server.
- `session` (method): The session with this name, captured now.
- `pane` (method): The pane with this id, captured now.
- `window` (method): The winlink at this exact position, captured now.
- `clients` (method): Captures every attached client.
- `attachedSessions` (method): Captures every session a client is attached to.
- `run` (method): Runs a command that is expected to work, and raises when it did not.
- `runTogether` (method): Runs several commands in one invocation, so nothing of this caller's happens between them.
- `refresh` (method)
- `toBuilder` (method): A builder holding every configuration and ownership choice this server made.
- `close` (method): Releases an owned transport. Idempotent, and never kills tmux.
- `Builder` (class): Collects configuration and the ownership choice, then builds a server.
