Class FileTerminalViewSource

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

public final class FileTerminalViewSource extends Object implements TerminalViewSource
A TerminalViewSource over one growing JSON Lines file, one event per line, paged through a FileLineIndex.

Path safety. The application supplies the Path when it builds the source; nothing in a request ever becomes a path. An application that derives paths from ids must resolve them against a fixed root, normalize() the result, and require result.startsWith(root).

Numbering. seq is the 1-based line number. A seq member in the file is ignored and overwritten, so the producer writes events without one. A line that is not valid JSON, is not a known event, or is too long is skipped: it consumes its line number, so a gap appears in seq. The first such line a source meets is logged once as a WARNING, with its line number; later ones are skipped without a log record, so a corrupt file polled every second does not flood the log. Blank lines are not counted as malformed.

Tokens are <epoch>.<n>: the epoch of the file generation and the last line number consumed. A stale epoch (the file was truncated, replaced or rewritten) or an n beyond the indexed lines throws UnknownTokenException. This includes a token issued while the file did not exist yet, once the file has been created.

Only complete lines are read, so a partially written last line never appears. Keep one instance per file; a new instance re-indexes the file from byte 0.

Example:

FileTerminalViewSource src = FileTerminalViewSource.create(root.resolve("run-42.jsonl")) .terminal(() -> run.isFinished()) .build();

  • Method Details

    • create

      Creates a builder.
      Parameters:
      file - The file, supplied by the application.
      Returns:
      A new builder.
    • 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.