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

cschneider pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git


The following commit(s) were added to refs/heads/master by this push:
     new 26204b4  SLING-9259 - Create separate class for imported event
26204b4 is described below

commit 26204b487b45c42fb3462cd594ec617cfdf4a27b
Author: Christian Schneider <[email protected]>
AuthorDate: Mon Jun 22 17:11:21 2020 +0200

    SLING-9259 - Create separate class for imported event
---
 .../journal/impl/event/DistributionEvent.java      |  6 ---
 .../journal/impl/subscriber/BookKeeper.java        |  3 +-
 .../journal/impl/subscriber/ImportedEvent.java     | 59 ++++++++++++++++++++++
 3 files changed, 60 insertions(+), 8 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/event/DistributionEvent.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/event/DistributionEvent.java
index a22e724..fa96451 100644
--- 
a/src/main/java/org/apache/sling/distribution/journal/impl/event/DistributionEvent.java
+++ 
b/src/main/java/org/apache/sling/distribution/journal/impl/event/DistributionEvent.java
@@ -25,7 +25,6 @@ import static 
org.apache.sling.distribution.event.DistributionEventProperties.DI
 import static 
org.apache.sling.distribution.event.DistributionEventTopics.AGENT_PACKAGE_CREATED;
 import static 
org.apache.sling.distribution.event.DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED;
 import static 
org.apache.sling.distribution.event.DistributionEventTopics.AGENT_PACKAGE_QUEUED;
-import static 
org.apache.sling.distribution.event.DistributionEventTopics.IMPORTER_PACKAGE_IMPORTED;
 import static 
org.apache.sling.distribution.packaging.DistributionPackageInfo.PROPERTY_REQUEST_PATHS;
 import static 
org.apache.sling.distribution.packaging.DistributionPackageInfo.PROPERTY_REQUEST_TYPE;
 
@@ -44,15 +43,10 @@ public class DistributionEvent {
 
     public static final String PACKAGE_ID = "distribution.package.id";
     private static final String KIND_AGENT = "agent";
-    private static final String KIND_IMPORTER = "importer";
 
     private DistributionEvent() {
     }
     
-    public static Event eventImporterImported(PackageMessage pkgMsg, String 
agentName) {
-        return buildEvent(IMPORTER_PACKAGE_IMPORTED, KIND_IMPORTER, agentName, 
pkgMsg);
-    }
-
     public static Event eventPackageCreated(PackageMessage pkgMsg, String 
agentName) {
         return buildEvent(AGENT_PACKAGE_CREATED, KIND_AGENT, agentName, 
pkgMsg);
     }
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/BookKeeper.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/BookKeeper.java
index 59d9687..4ec2fc0 100644
--- 
a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/BookKeeper.java
+++ 
b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/BookKeeper.java
@@ -38,7 +38,6 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.commons.metrics.Timer;
 import org.apache.sling.distribution.common.DistributionException;
-import org.apache.sling.distribution.journal.impl.event.DistributionEvent;
 import org.apache.sling.distribution.journal.impl.queue.impl.PackageRetries;
 import 
org.apache.sling.distribution.journal.impl.shared.DistributionMetricsService;
 import 
org.apache.sling.distribution.journal.impl.shared.DistributionMetricsService.GaugeService;
@@ -155,7 +154,7 @@ public class BookKeeper implements Closeable {
             
distributionMetricsService.getImportedPackageSize().update(pkgMsg.getPkgLength());
             
distributionMetricsService.getPackageDistributedDuration().update((currentTimeMillis()
 - createdTime), TimeUnit.MILLISECONDS);
             packageRetries.clear(pkgMsg.getPubAgentName());
-            Event event = DistributionEvent.eventImporterImported(pkgMsg, 
subAgentName);
+            Event event = new ImportedEvent(pkgMsg, subAgentName).toEvent();
             eventAdmin.postEvent(event);
         } catch (DistributionException | LoginException | IOException | 
RuntimeException e) {
             failure(pkgMsg, offset, e);
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/ImportedEvent.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/ImportedEvent.java
new file mode 100644
index 0000000..e0ffaaa
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/ImportedEvent.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.impl.subscriber;
+
+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 ImportedEvent {
+
+    public static final String PACKAGE_ID = "distribution.package.id";
+    private static final String KIND_IMPORTER = "importer";
+    private PackageMessage pkgMsg;
+    private String agentName;
+
+    ImportedEvent(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_IMPORTED, 
props);
+    }
+
+}

Reply via email to