Class TerminalViewLog

java.lang.Object
org.apache.juneau.console.views.TerminalViewLog
All Implemented Interfaces:
TerminalViewSource

public final class TerminalViewLog extends Object implements TerminalViewSource
A thread-safe, in-memory TerminalViewSource that a producer appends to directly.

Tokens are <epoch>.<n>, where epoch is six characters of [0-9a-z] regenerated by reset() and n is the last seq the client has. A page returns the events with seq > n.

A done event does not close the log by itself; close() is explicit, so an adopter may still append a late note. A host that pushes events over its own transport (for example server-sent events) forwards the numbered event returned by append(TerminalEvent).

  • Field Details

  • Method Details

    • create

      public static TerminalViewLog create()
      Creates a log with the default capacity.
      Returns:
      A new log.
    • create

      public static TerminalViewLog create(int maxEvents)
      Creates a log with a given capacity.
      Parameters:
      maxEvents - The maximum number of events, at least 1.
      Returns:
      A new log.
    • append

      Appends an event, assigning seq = size + 1.
      Parameters:
      event - The event.
      Returns:
      The numbered copy that was stored.
      Throws:
      IllegalStateException - If the log is closed or full.
      IllegalArgumentException - If the event is too large.
    • appendAll

      Appends events atomically, numbering them consecutively.
      Parameters:
      batch - The events.
      Returns:
      The numbered copies, in order.
      Throws:
      IllegalStateException - If the log is closed or the batch does not fit.
      IllegalArgumentException - If an event is too large.
    • close

      public void close()
      Marks the log terminal: no further events will be appended.
    • isTerminal

      public boolean isTerminal()
      Returns whether close() has been called.
      Returns:
      true if the log is closed.
    • reset

      public void reset()
      Clears the log, reopens it, and bumps the epoch so that tokens issued before the reset answer 410 Gone.
    • page

      public TerminalViewPage page(String after, int max)
      Description copied from interface: TerminalViewSource
      Returns a forward page of events with a seq greater than the token's position.
      Specified by:
      page in interface TerminalViewSource
      Parameters:
      after - The next token of the previous page, or null for the start.
      max - The maximum number of events.
      Returns:
      A forward page.