Class AutoFetch

java.lang.Object
io.github.jbastgen.stemma.app.git.AutoFetch

public final class AutoFetch extends Object
Feature 54: when the repositories are fetched by themselves. This class only decides when (a repository is due every N minutes, a failure makes it wait twice as long each time, up to an hour); MainView runs the fetches and RealRepoController.autoFetch(boolean, java.util.function.Consumer<io.github.jbastgen.stemma.app.git.AutoFetch.Outcome>) does the work. Free of JavaFX, so the rules can be tested with a fake clock.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    What one automatic fetch did, for the policy and for the single message to the user.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    due(String id, Instant now, Duration interval)
    Whether the repository is due now and no fetch of it is running.
    boolean
    failed(String id, Instant now, Duration interval)
    The fetch failed: the next try comes after twice the interval, then four times, … but never later than an hour (and never earlier than the interval itself, which can be longer than an hour).
    void
    Forgets a repository that was closed.
    static Duration
    interval(int minutes)
    The interval from the settings, kept inside what makes sense.
    void
    Asks for the repository to be fetched at the next opportunity (e.g. after the settings changed).
    void
    A fetch starts: no second one for the same repository until it is over.
    void
    succeeded(String id, Instant now, Duration interval)
    The fetch worked: back to the normal interval.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • AutoFetch

      public AutoFetch()
  • Method Details

    • interval

      public static Duration interval(int minutes)
      The interval from the settings, kept inside what makes sense.
    • due

      public boolean due(String id, Instant now, Duration interval)
      Whether the repository is due now and no fetch of it is running. The first call of a new repository starts its first wait.
    • started

      public void started(String id)
      A fetch starts: no second one for the same repository until it is over.
    • succeeded

      public void succeeded(String id, Instant now, Duration interval)
      The fetch worked: back to the normal interval.
    • failed

      public boolean failed(String id, Instant now, Duration interval)
      The fetch failed: the next try comes after twice the interval, then four times, … but never later than an hour (and never earlier than the interval itself, which can be longer than an hour).
      Returns:
      whether the user has not been told yet; true once per series of failures
    • forget

      public void forget(String id)
      Forgets a repository that was closed.
    • reset

      public void reset()
      Asks for the repository to be fetched at the next opportunity (e.g. after the settings changed).