Class SyncTokenService
java.lang.Object
org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck
org.apache.sling.discovery.commons.providers.spi.base.SyncTokenService
- All Implemented Interfaces:
ClusterSyncService
public class SyncTokenService
extends AbstractServiceWithBackgroundCheck
implements ClusterSyncService
Implements the syncToken idea: each instance stores a key-value
pair with key=stringId and value=discoveryLiteSequenceNumber
under /var/discovery/oak/syncTokens - and then waits until it
sees the same token from all other instances in the cluster.
This way, once the syncToken is received the local instance
knows that all instances in the cluster are now in TOPOLOGY_CHANGING state
(thus all topology-dependent activity is now stalled and waiting)
and are aware of the new discoveryLite view.
-
Field Summary
Modifier and TypeFieldDescriptionprotected ClusterSyncHistory
protected DiscoveryLiteConfig
protected ResourceResolverFactory
protected SlingSettingsService
Fields inherited from class org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck
backgroundCheckRunnable, logger, slingId
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate()
void
protected ResourceResolver
Get or create a ResourceResolvervoid
setConsistencyHistory
(ClusterSyncHistory consistencyHistory) void
sync
(BaseTopologyView view, Runnable callback) Starts the synchronization process and calls the provided callback upon completion.protected void
syncToken
(BaseTopologyView view, Runnable callback) static SyncTokenService
testConstructor
(DiscoveryLiteConfig commonsConfig, ResourceResolverFactory resourceResolverFactory, SlingSettingsService settingsService) static SyncTokenService
testConstructorAndActivate
(DiscoveryLiteConfig commonsConfig, ResourceResolverFactory resourceResolverFactory, SlingSettingsService settingsService) Methods inherited from class org.apache.sling.discovery.commons.providers.spi.base.AbstractServiceWithBackgroundCheck
cancelPreviousBackgroundCheck, startBackgroundCheck, triggerBackgroundCheck
-
Field Details
-
commonsConfig
-
resourceResolverFactory
-
settingsService
-
clusterSyncHistory
-
-
Constructor Details
-
SyncTokenService
public SyncTokenService()
-
-
Method Details
-
testConstructorAndActivate
public static SyncTokenService testConstructorAndActivate(DiscoveryLiteConfig commonsConfig, ResourceResolverFactory resourceResolverFactory, SlingSettingsService settingsService) -
testConstructor
public static SyncTokenService testConstructor(DiscoveryLiteConfig commonsConfig, ResourceResolverFactory resourceResolverFactory, SlingSettingsService settingsService) -
activate
protected void activate() -
setConsistencyHistory
-
getClusterSyncHistory
-
getResourceResolver
Get or create a ResourceResolver- Throws:
LoginException
-
cancelSync
public void cancelSync()- Specified by:
cancelSync
in interfaceClusterSyncService
-
sync
Description copied from interface:ClusterSyncService
Starts the synchronization process and calls the provided callback upon completion.sync() is not thread-safe and should not be invoked concurrently.
If sync() gets called before a previous invocation finished, that previous invocation will be discarded, ie the callback of the previous invocation will no longer be called.
The synchronization process consists of making sure that the repository has processed any potential backlog of instances that are no longer part of the provided, new view. Plus it writes a 'sync-token' to a well-defined location, with all peers doing the same, and upon seeing all other sync-tokens declares successful completion - at which point it calls the callback.run().
- Specified by:
sync
in interfaceClusterSyncService
- Parameters:
view
- the view which all instances in the local cluster should agree on having seencallback
- the runnable which should be called after successful syncing
-
syncToken
-