tmaret commented on a change in pull request #24: SLING-9075 - Support multiple
agents with one StagingPrecondition
URL:
https://github.com/apache/sling-org-apache-sling-distribution-journal/pull/24#discussion_r380651535
##########
File path:
src/main/java/org/apache/sling/distribution/journal/impl/subscriber/StagingPrecondition.java
##########
@@ -54,65 +55,51 @@
private volatile PackageStatusWatcher watcher;
private volatile boolean running = true;
-
-
+
@Activate
- public void activate(Configuration config) {
- String subAgentName = config.subAgentName();
- watcher = new PackageStatusWatcher(messagingProvider, topics,
subAgentName);
- LOG.info("Activated Staging Precondition for subAgentName {}",
subAgentName);
+ public void activate() {
+ watcher = new PackageStatusWatcher(messagingProvider, topics);
+ LOG.info("Activated Staging Precondition");
}
@Deactivate
- public void deactivate() {
+ public synchronized void deactivate() {
IOUtils.closeQuietly(watcher);
running = false;
}
-
@Override
- public boolean canProcess(long pkgOffset, int timeoutSeconds) {
-
+ public boolean canProcess(String subAgentName, long pkgOffset, int
timeoutSeconds) throws InterruptedException {
if (timeoutSeconds < 1) {
throw new IllegalArgumentException();
}
- // clear all offsets less than the required one as they are not needed
anymore.
- // this works OK only if pkgOffset are always queried in increasing
order.
- watcher.clear(pkgOffset);
-
// try to get the status for timeoutSeconds and then throw
- for(int i=0; running && i < timeoutSeconds; i++) {
- Status status = watcher.getStatus(pkgOffset);
+ for(int i=0; i < timeoutSeconds * 10; i++) {
+ Status status = getStatus(subAgentName, pkgOffset);
if (status != null) {
return status == Status.IMPORTED;
} else {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new IllegalStateException("Precondition evaluation
has been interrupted");
- }
+ Thread.sleep(100);
+ }
+
+ if (!running) {
+ throw new InterruptedException("Staging precondition is
shutting down");
}
}
throw new IllegalStateException("Timeout waiting for package offset "
+ pkgOffset + " on status topic.");
Review comment:
As we are throwing checked exceptions, we could go a step further. How about
throwing `TimeoutException` instead of `IllegalStateException` when the timeout
elapse?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services