Class ScenarioReader

java.lang.Object
org.acemq.workloads.scenario.ScenarioReader

public final class ScenarioReader extends Object
Reads a scenario file from disk.

This is what makes the studio worth using: what it exports, this reads, and the command line runs it. Without this the studio would be a drawing tool whose output somebody has to translate by hand — and a translation is a place for the two to diverge.

Both formats, because both exist for good reasons. The studio writes JSON because that is what its API speaks; a person editing a scenario in a repository writes YAML because comments matter more than machine-readability there.

  • Method Details

    • read

      public static ScenarioFile read(Path path)
      Parameters:
      path - a scenario file, .json or .yaml
      Returns:
      what it describes
      Throws:
      ScenarioReader.ScenarioFormatException - if it cannot be read
    • parse

      public static ScenarioFile parse(String text, String fileName)
      A scenario somebody handed over, rather than one read from disk.

      Used when the studio opens a file: the bytes arrive over HTTP and the format is decided by the name when there is one and by the first character when there is not.

      ${VAR} is left alone here. Resolving it would read the studio's own environment on behalf of whoever uploaded the file, and hand back the result — a broker URL containing ${AWS_SECRET_ACCESS_KEY} would come back with the value in it. The placeholder stays a placeholder, and is resolved by the command line at the point where the person running it owns the environment.

      Parameters:
      text - the file's contents
      fileName - what it was called, or null
      Returns:
      what it describes
      Throws:
      ScenarioReader.ScenarioFormatException - if it cannot be read
    • isScenario

      public static boolean isScenario(Path path)
      Whether a file is a scenario rather than a single-path workload.

      Decided by what is in it rather than by a flag somebody has to remember: a scenario describes exchanges, queues and producers, and a workload describes a topology with publishers and consumers. Two shapes, one -f.

      Parameters:
      path - the file
      Returns:
      whether it looks like a scenario
    • describe

      public static String describe(ScenarioFile file)
      Returns:
      what to say about a scenario before running it
    • redact

      public static String redact(String url)
      Parameters:
      url - a broker URL @return the same URL with the password taken out