Class GroomRuns

java.lang.Object
org.apache.juneau.petstore.console.ops.GroomRuns
All Implemented Interfaces:
AutoCloseable

public final class GroomRuns extends Object implements AutoCloseable
The groom-pet demo runs behind the Jobs page's terminal cards.

A run writes about 60 ANSI-styled lines to a MemoryTerminalSource, one step per tick: INFO and FINE lines (FINE is dim), a WARNING, check/cross marks, a progress strip of coloured blocks, a multi-line SEVERE entry, bold marker lines, and a canned ANSI transcript written as-is. Each tick also appends one ANSI line to a temp file, read through one FileTerminalSource per run. A verbose run first writes 8000 FINE lines.

Run ids are random 128-bit hex strings, so a terminal can be read only by someone who was given its id.

Example:

try (var runs = new GroomRuns(650)) { var run = runs.start("Rex", false, null); var source = runs.source(run.id()).orElseThrow(); }

  • Field Details

  • Constructor Details

    • GroomRuns

      public GroomRuns(long periodMs)
      Constructor.
      Parameters:
      periodMs - Milliseconds between steps, at least 1.
  • Method Details

    • seeded

      public static GroomRuns seeded(long periodMs)
      Creates the runs and starts one verbose run, so the Jobs page always has a log to show.
      Parameters:
      periodMs - Milliseconds between steps.
      Returns:
      The runs.
    • start

      public GroomRuns.Run start(String pet, boolean verbose, String idempotencyKey) throws IOException
      Starts a run, or returns the run already started with the same idempotency key.
      Parameters:
      pet - The pet name; blank means "Rex".
      verbose - Whether to write 8000 FINE lines first.
      idempotencyKey - The client's key, or null.
      Returns:
      The run.
      Throws:
      IOException - If the temp file cannot be created.
    • get

      Parameters:
      id - A run id, or null.
      Returns:
      The run.
    • latest

      Returns:
      The newest run, or null after close().
    • list

      public List<GroomRuns.Run> list()
      Returns:
      The runs, newest first.
    • source

      public Optional<TerminalSource> source(String terminalId)
      Resolves a terminal id: <runId> is the in-memory terminal, <runId>-file the file source.
      Parameters:
      terminalId - The terminal id from the URL.
      Returns:
      The source, or empty for an unknown id.
    • close

      public void close()
      Stops the ticker and deletes every run's file.
      Specified by:
      close in interface AutoCloseable