Class BookKeeper
java.lang.Object
org.apache.sling.distribution.journal.bookkeeper.BookKeeper
- All Implemented Interfaces:
Closeable,AutoCloseable
public class BookKeeper extends Object implements Closeable
Keeps track of offset and processed status and manages
coordinates the import/retry handling.
The offset store is identified by the agentName only.
With non clustered publish instances deployment, each
instance stores the offset in its own node store, thus
avoiding mix ups. Moreover, when cloning an instance
from a node store, the cloned instance will implicitly
recover the offsets and start from the last processed
offset.
With clustered publish instances deployment, only one
Subscriber agent must run on the cluster in order to
avoid mix ups.
The clustered and non clustered publish instances use
cases can be supported by only running the Subscriber
agent on the leader instance.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBookKeeper.PackageStatus -
Field Summary
Fields Modifier and Type Field Description static intCOMMIT_AFTER_NUM_SKIPPEDstatic StringKEY_OFFSETstatic StringSTORE_TYPE_STATUS -
Constructor Summary
Constructors Constructor Description BookKeeper(org.apache.sling.api.resource.ResourceResolverFactory resolverFactory, DistributionMetricsService distributionMetricsService, org.apache.sling.distribution.journal.bookkeeper.PackageHandler packageHandler, org.osgi.service.event.EventAdmin eventAdmin, Consumer<org.apache.sling.distribution.journal.messages.PackageStatusMessage> sender, Consumer<org.apache.sling.distribution.journal.messages.LogMessage> logSender, BookKeeperConfig config)BookKeeper(org.apache.sling.api.resource.ResourceResolverFactory resolverFactory, DistributionMetricsService distributionMetricsService, org.apache.sling.distribution.journal.bookkeeper.PackageHandler packageHandler, org.osgi.service.event.EventAdmin eventAdmin, Consumer<org.apache.sling.distribution.journal.messages.PackageStatusMessage> sender, Consumer<org.apache.sling.distribution.journal.messages.LogMessage> logSender, BookKeeperConfig config, org.apache.sling.distribution.ImportPostProcessor importPostProcessor) -
Method Summary
Modifier and Type Method Description voidclose()PackageRetriesgetPackageRetries()intgetRetries(String pubAgentName)voidimportPackage(org.apache.sling.distribution.journal.messages.PackageMessage pkgMsg, long offset, long createdTime)We aim at processing the packages exactly once.longloadOffset()voidmarkStatusSent()voidremovePackage(org.apache.sling.distribution.journal.messages.PackageMessage pkgMsg, long offset)booleansendStoredStatus(int retry)booleanshouldCommitSkipped()voidskipPackage(long offset)
-
Field Details
-
STORE_TYPE_STATUS
- See Also:
- Constant Field Values
-
KEY_OFFSET
- See Also:
- Constant Field Values
-
COMMIT_AFTER_NUM_SKIPPED
public static final int COMMIT_AFTER_NUM_SKIPPED- See Also:
- Constant Field Values
-
-
Constructor Details
-
BookKeeper
public BookKeeper(org.apache.sling.api.resource.ResourceResolverFactory resolverFactory, DistributionMetricsService distributionMetricsService, org.apache.sling.distribution.journal.bookkeeper.PackageHandler packageHandler, org.osgi.service.event.EventAdmin eventAdmin, Consumer<org.apache.sling.distribution.journal.messages.PackageStatusMessage> sender, Consumer<org.apache.sling.distribution.journal.messages.LogMessage> logSender, BookKeeperConfig config) -
BookKeeper
public BookKeeper(org.apache.sling.api.resource.ResourceResolverFactory resolverFactory, DistributionMetricsService distributionMetricsService, org.apache.sling.distribution.journal.bookkeeper.PackageHandler packageHandler, org.osgi.service.event.EventAdmin eventAdmin, Consumer<org.apache.sling.distribution.journal.messages.PackageStatusMessage> sender, Consumer<org.apache.sling.distribution.journal.messages.LogMessage> logSender, BookKeeperConfig config, org.apache.sling.distribution.ImportPostProcessor importPostProcessor)
-
-
Method Details
-
importPackage
public void importPackage(org.apache.sling.distribution.journal.messages.PackageMessage pkgMsg, long offset, long createdTime) throws org.apache.sling.distribution.common.DistributionExceptionWe aim at processing the packages exactly once. Processing the packages exactly once is possible with the following conditions I. The package importer is configured to disable auto-committing changes. II. A single commit aggregates three content updates C1. install the package C2. store the processing status C3. store the offset processed Some package importers require auto-saving or issue partial commits before failing. For those packages importers, we aim at processing packages at least once, thanks to the order in which the content updates are applied.- Throws:
org.apache.sling.distribution.common.DistributionException
-
removePackage
public void removePackage(org.apache.sling.distribution.journal.messages.PackageMessage pkgMsg, long offset) throws org.apache.sling.api.resource.LoginException, org.apache.sling.api.resource.PersistenceException- Throws:
org.apache.sling.api.resource.LoginExceptionorg.apache.sling.api.resource.PersistenceException
-
skipPackage
public void skipPackage(long offset) throws org.apache.sling.api.resource.LoginException, org.apache.sling.api.resource.PersistenceException- Throws:
org.apache.sling.api.resource.LoginExceptionorg.apache.sling.api.resource.PersistenceException
-
shouldCommitSkipped
public boolean shouldCommitSkipped() -
sendStoredStatus
public boolean sendStoredStatus(int retry)- Returns:
trueif the status has been sent ;falseotherwise.
-
markStatusSent
public void markStatusSent() -
loadOffset
public long loadOffset() -
getRetries
-
getPackageRetries
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-