Class Maintainer

  • All Implemented Interfaces:
    java.lang.Runnable

    public abstract class Maintainer
    extends java.lang.Object
    implements java.lang.Runnable
    The base class for maintainers. A maintainer is some job which runs at a fixed rate to perform maintenance tasks.
    Author:
    bratseth, mpolden, jonmv
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.logging.Logger log  
    • Constructor Summary

      Constructors 
      Constructor Description
      Maintainer​(java.lang.String name, java.time.Duration interval, java.time.Instant startedAt, JobControl jobControl, JobMetrics jobMetrics, java.util.List<java.lang.String> clusterHostnames, boolean ignoreCollision)  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected double asSuccessFactor​(int attempts, int failures)
      Convenience methods to convert attempts and failures into a success factor
      void awaitShutdown()
      Waits for shutdown to complete, calling shutdown() if this hasn't been done already.
      protected java.time.Duration interval()
      Returns the interval at which this job is set to run
      void lockAndMaintain​(boolean force)
      Run this while holding the job lock
      protected abstract double maintain()
      Called once each time this maintenance job should run.
      java.lang.String name()
      Returns the simple name of this job
      void run()  
      void shutdown()
      Starts shutdown of this, typically by shutting down executors.
      boolean shuttingDown()
      Returns whether this is being shut down
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • log

        protected final java.util.logging.Logger log
    • Constructor Detail

      • Maintainer

        public Maintainer​(java.lang.String name,
                          java.time.Duration interval,
                          java.time.Instant startedAt,
                          JobControl jobControl,
                          JobMetrics jobMetrics,
                          java.util.List<java.lang.String> clusterHostnames,
                          boolean ignoreCollision)
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • shutdown

        public void shutdown()
        Starts shutdown of this, typically by shutting down executors. awaitShutdown() waits for shutdown to complete.
      • awaitShutdown

        public void awaitShutdown()
        Waits for shutdown to complete, calling shutdown() if this hasn't been done already.
      • shuttingDown

        public final boolean shuttingDown()
        Returns whether this is being shut down
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • maintain

        protected abstract double maintain()
        Called once each time this maintenance job should run.
        Returns:
        the degree to which the run was successful - a number between 0 (no success), to 1 (complete success). Note that this indicates whether something is wrong, so e.g if the call did nothing because it should do nothing, 1.0 should be returned.
      • asSuccessFactor

        protected final double asSuccessFactor​(int attempts,
                                               int failures)
        Convenience methods to convert attempts and failures into a success factor
      • interval

        protected java.time.Duration interval()
        Returns the interval at which this job is set to run
      • lockAndMaintain

        public final void lockAndMaintain​(boolean force)
        Run this while holding the job lock
      • name

        public final java.lang.String name()
        Returns the simple name of this job