Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

class libtmux-java latest

EventSubscription

Pulls events volunteered by one control client.

Source and package
Qualified name
io.github.libtmux.control.EventSubscription
Package
io.github.libtmux.control
Distribution
io.github.libtmux:libtmux
Source
libtmux/src/main/java/io/github/libtmux/control/EventSubscription.java
class io.github.libtmux.control.EventSubscription

Description#

Each subscription owns a fixed-capacity buffer. When that buffer is full, the next event replaces its oldest event. The read that follows is a Delivery.Gap naming how many were discarded since the previous read, and only then the events that remain. #droppedCount() is the total across the subscription's life. Another subscription has its own buffer and its own gaps. The control protocol reader only offers values to these buffers, and never runs subscriber code beyond a readiness callback.

One reader at a time. Public operations are thread-safe, and reads from different threads one after another are fine — a coroutine or a fiber moves between threads — but a read that overlaps another, or any read once #stream() or #publisher() has taken the subscription, is refused with IllegalStateException: two readers would split one sequence and its gaps between them. For a second reader, subscribe again; each subscription gets every event.

#next() blocks. #poll() never does, and #onReady(Runnable) arms a one-shot wakeup for when there is something to poll, so an event loop or a coroutine can read without holding a thread while nothing arrives.

A subscription does not reconnect. When it ends, #next() returns empty. #cause() is empty when the caller closed it, and set when the control client ended it. Attach again from the captured session and read a snapshot; nothing already missed is replayed.

Ending is terminal and wakes threads blocked in #next(). A caller's #close() discards buffered events: the caller has chosen not to read them, so they are not overflow and do not increment the loss count. When the control client ends a subscription, what it had already delivered stays readable, a pending gap first, and only then does a read return empty with #cause() set.

Type parameters
  • T #

    the event type

Members19#

Common operations4#

  • next method Waits until the next step arrives or this subscription closes.
  • onReady method Arms a one-shot wakeup for when this subscription has something to read, or has ended.
  • poll method Returns the next step if one is waiting, without blocking.
  • stream method The steps still to come, in order, each read by the thread consuming the stream.

Other members15#

  • cause method Why this subscription ended, when the control client ended it.
  • clearReady method Disarms the readiness callback, if one is armed. For a reader that stopped waiting.
  • close method Discards buffered events, removes this subscriber, and wakes every waiting reader.
  • droppedBytes method Unescaped payload bytes discarded by the event or byte limit; excludes intentional close.
  • droppedCount method Returns the exact number of events discarded because this subscription's buffer was full.
  • end method Ends this subscription as the control client saw it end, recording why. Unlike #close(), events already delivered stay readable.
  • EndReason enum What was observed when the subscription ended; a control exit does not prove daemon death.
  • EventSubscription method
  • finish method Ends this subscription as a producer with nothing more to send: not a failure, and nothing is discarded.
  • isClosed method Whether this subscription has reached its terminal state.
  • offer method
  • publisher method A Flow.Publisher view of this subscription's steps, delivered as demand allows.
  • retainedBytes method Unescaped payload bytes still queued, excluding JVM object overhead; zero for unweighted events.
  • termination method The first recorded terminal classification, empty while the subscription is open.
  • Termination class The first observed end and its original failure, if any.
Esc

Type to search.

Reference previewOpen reference