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_r380647468
 
 

 ##########
 File path: 
src/main/java/org/apache/sling/distribution/journal/impl/subscriber/PackageStatusWatcher.java
 ##########
 @@ -54,61 +50,28 @@ public PackageStatusWatcher(MessagingProvider 
messagingProvider, Topics topics,
         );
     }
 
-
     /**
      * Gets the status that confirms the package at offset pkgOffset
      * @param pkgOffset the offset of the package
      * @return the status confirming the package; or null if it has not been 
confirmed yet
      */
-    public PackageStatusMessage.Status getStatus(long pkgOffset) {
-        FullMessage<PackageStatusMessage> msg = cache.get(pkgOffset);
-
-        return msg != null ? msg.getMessage().getStatus() : null;
-    }
-
-    /**
-     * Gets the status offset that confirms the packages at offset pkgOffset
-     * @param pkgOffset the offset of the package
-     * @return the offset of the confirming package; or null if has not been 
confirmed yet
-     */
-    public Long getStatusOffset(long pkgOffset) {
-        FullMessage<PackageStatusMessage> msg = cache.get(pkgOffset);
-
-        return msg != null ? msg.getInfo().getOffset() : null;
+    public PackageStatusMessage.Status getStatus(String subAgentName, long 
pkgOffset) {
+        Map<Long, Status> statusPerAgent = getAgentStatus(subAgentName);
+        return statusPerAgent.get(pkgOffset);
     }
 
-    /**
-     * Clear all offsets in the cache smaller to the given pkgOffset.
-     * @param pkgOffset package offset
-     */
-    public void clear(long pkgOffset) {
-        NavigableMap<Long, FullMessage<PackageStatusMessage>> removed = 
cache.headMap(pkgOffset, false);
-        if (! removed.isEmpty()) {
-            LOG.info("Remove package offsets {} from status cache", 
removed.keySet());
-        }
-        removed.clear();
+    private Map<Long, Status> getAgentStatus(String subAgentName) {
+        return pkgStatusPerSubAgent.computeIfAbsent(subAgentName, offset -> 
new HashMap<Long, Messages.PackageStatusMessage.Status>());
 
 Review comment:
   Same here, we should `s/HashMap/ConcurrentMap` as the map is read and 
written by different threads.

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

Reply via email to