Package org.apache.sling.discovery.commons.providers.spi.base

# 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 Summary

Fields
Modifier and Type
Field
Description
`protected org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck.BackgroundCheckRunnable`
`backgroundCheckRunnable`
`protected final org.slf4j.Logger`
`logger`
`protected String`
`slingId`

## Constructor Summary

Constructors
Constructor
Description
`AbstractServiceWithBackgroundCheck()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`cancelPreviousBackgroundCheck()`
Cancel the currently ongoing background check if there is any ongoing.
`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()
`protected void`
`triggerBackgroundCheck()`
for testing only!

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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!