Class AbstractServiceWithBackgroundCheck

java.lang.Object
org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck
Direct Known Subclasses:
IdMapService, OakBacklogClusterSyncService, SyncTokenService

public abstract class AbstractServiceWithBackgroundCheck extends Object
Base class which implements the concept of a 'BackgroundCheck', a thread that periodically executes a check until that one succeeds.

  • Field Details

    • logger

      protected final org.slf4j.Logger logger
    • slingId

      protected String slingId
    • backgroundCheckRunnable

      protected org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck.BackgroundCheckRunnable backgroundCheckRunnable
  • Constructor Details

    • AbstractServiceWithBackgroundCheck

      public AbstractServiceWithBackgroundCheck()
  • Method Details

    • cancelPreviousBackgroundCheck

      protected void cancelPreviousBackgroundCheck()
      Cancel the currently ongoing background check if there is any ongoing.
    • startBackgroundCheck

      protected void startBackgroundCheck(String threadName, org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck.BackgroundCheck check, Runnable callback, long timeoutMillis, long waitMillis)
      Start a new BackgroundCheck in a separate thread, that periodically calls BackgroundCheck.check and upon completion calls the provided callback.run()
      Parameters:
      threadName - the name of the thread (to allow identifying the thread)
      check - the BackgroundCheck to periodically invoke with check()
      callback - the Runnable to invoke upon a successful check()
      timeoutMillis - a timeout at which point the BackgroundCheck is terminated and no callback is invoked. Note that this happens unnoticed at the moment, ie there is no feedback about whether a background check was successfully termianted (ie callback was invoked) or whether the timeout has hit (that's left as a TODO if needed).
    • triggerBackgroundCheck

      protected void triggerBackgroundCheck()
      for testing only!