You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2021/05/21 09:59:55 UTC

[sling-org-apache-sling-distribution-journal] branch feature/SLING-10384-sync-actions-before-imported-event created (now 23357ee)

This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a change to branch feature/SLING-10384-sync-actions-before-imported-event
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git.


      at 23357ee  SLING-10384 send synchronous committedEvent before sending the imported event

This branch includes the following new commits:

     new 23357ee  SLING-10384 send synchronous committedEvent before sending the imported event

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-distribution-journal] 01/01: SLING-10384 send synchronous committedEvent before sending the imported event

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a commit to branch feature/SLING-10384-sync-actions-before-imported-event
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git

commit 23357eee06f474111687ae894de6b3f9de0f5110
Author: Joerg Hoh <jh...@adobe.com>
AuthorDate: Fri May 21 11:58:47 2021 +0200

    SLING-10384 send synchronous committedEvent before sending the imported event
---
 pom.xml                                            |  2 +-
 .../journal/bookkeeper/BookKeeper.java             |  8 ++-
 .../journal/bookkeeper/CommittedEvent.java         | 59 ++++++++++++++++++++++
 3 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 587b7fb..6104d2b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,7 +103,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.distribution.api</artifactId>
-            <version>0.3.0</version>
+            <version>0.4.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
diff --git a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
index c3aa6f8..974803e 100644
--- a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
+++ b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeper.java
@@ -149,11 +149,15 @@ public class BookKeeper implements Closeable {
             }
             storeOffset(importerResolver, offset);
             importerResolver.commit();
+
+            Event committedEvent = new CommittedEvent(pkgMsg, config.getSubAgentName()).toEvent();
+            eventAdmin.sendEvent(committedEvent);
+
             distributionMetricsService.getImportedPackageSize().update(pkgMsg.getPkgLength());
             distributionMetricsService.getPackageDistributedDuration().update((currentTimeMillis() - createdTime), TimeUnit.MILLISECONDS);
             packageRetries.clear(pkgMsg.getPubAgentName());
-            Event event = new ImportedEvent(pkgMsg, config.getSubAgentName()).toEvent();
-            eventAdmin.postEvent(event);
+            Event importedEvent = new ImportedEvent(pkgMsg, config.getSubAgentName()).toEvent();
+            eventAdmin.postEvent(importedEvent);
         } catch (DistributionException | LoginException | IOException | RuntimeException e) {
             failure(pkgMsg, offset, e);
         } finally {
diff --git a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/CommittedEvent.java b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/CommittedEvent.java
new file mode 100644
index 0000000..7576156
--- /dev/null
+++ b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/CommittedEvent.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.distribution.journal.bookkeeper;
+
+import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_COMPONENT_KIND;
+import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_COMPONENT_NAME;
+import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_PATHS;
+import static org.apache.sling.distribution.event.DistributionEventProperties.DISTRIBUTION_TYPE;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.apache.sling.distribution.event.DistributionEventTopics;
+import org.apache.sling.distribution.journal.messages.PackageMessage;
+import org.osgi.service.event.Event;
+
+@ParametersAreNonnullByDefault
+public class CommittedEvent {
+
+    public static final String PACKAGE_ID = "distribution.package.id";
+    private static final String KIND_IMPORTER = "importer";
+    private PackageMessage pkgMsg;
+    private String agentName;
+
+    CommittedEvent(PackageMessage pkgMsg, String agentName) {
+        this.pkgMsg = pkgMsg;
+        this.agentName = agentName;
+    }
+
+    Event toEvent() {
+        String[] paths = pkgMsg.getPaths().toArray(new String[0]);
+        Map<String, Object> props = new HashMap<>();
+        props.put(DISTRIBUTION_COMPONENT_KIND, KIND_IMPORTER);
+        props.put(DISTRIBUTION_COMPONENT_NAME, agentName);
+        props.put(DISTRIBUTION_TYPE, pkgMsg.getReqType().name());
+        props.put(DISTRIBUTION_PATHS, paths);
+        props.put(PACKAGE_ID, pkgMsg.getPkgId());
+        return new Event(DistributionEventTopics.IMPORTER_PACKAGE_COMMITTED, props);
+    }
+
+}