You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cs...@apache.org on 2020/04/01 16:01:58 UTC

[sling-org-apache-sling-distribution-journal] branch master updated: SLING-9321 - Use contructor injection

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 3b1886c  SLING-9321 - Use contructor injection
3b1886c is described below

commit 3b1886c435304d76d6a8054def0e71ba9a142d00
Author: Christian Schneider <cs...@adobe.com>
AuthorDate: Wed Apr 1 18:01:42 2020 +0200

    SLING-9321 - Use contructor injection
---
 .../service/subscriber/BookKeeperFactory.java      | 30 +++++++++-------------
 .../journal/impl/subscriber/SubscriberTest.java    |  3 +--
 2 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/apache/sling/distribution/journal/service/subscriber/BookKeeperFactory.java b/src/main/java/org/apache/sling/distribution/journal/service/subscriber/BookKeeperFactory.java
index b0cdbcb..152f12d 100644
--- a/src/main/java/org/apache/sling/distribution/journal/service/subscriber/BookKeeperFactory.java
+++ b/src/main/java/org/apache/sling/distribution/journal/service/subscriber/BookKeeperFactory.java
@@ -28,43 +28,37 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.distribution.journal.messages.Messages.PackageStatusMessage;
 import org.apache.sling.distribution.packaging.DistributionPackageBuilder;
 import org.osgi.framework.BundleContext;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.event.EventAdmin;
 
 @Component(service = BookKeeperFactory.class, immediate = true)
 public class BookKeeperFactory {
-    
-
 
-    @Reference
-    private ResourceResolverFactory resolverFactory;
+    private final ResourceResolverFactory resolverFactory;
     
-    @Reference
-    private EventAdmin eventAdmin;
+    private final EventAdmin eventAdmin;
     
-    @Reference
-    private SubscriberMetrics subscriberMetrics;
+    private final SubscriberMetrics subscriberMetrics;
     
-    @Reference
-    private Packaging packaging;
+    private final Packaging packaging;
 
     private BundleContext context;
 
     private Integer idleMillies;
     
-    public BookKeeperFactory() {
-    }
-    
-    public BookKeeperFactory(ResourceResolverFactory resolverFactory,
-            EventAdmin eventAdmin, SubscriberMetrics subscriberMetrics, Packaging packaging) {
+    @Activate
+    public BookKeeperFactory(
+            @Reference ResourceResolverFactory resolverFactory,
+            @Reference EventAdmin eventAdmin, 
+            @Reference SubscriberMetrics subscriberMetrics, 
+            @Reference Packaging packaging,
+            BundleContext context, Map<String, Object> properties) {
         this.resolverFactory = resolverFactory;
         this.eventAdmin = eventAdmin;
         this.subscriberMetrics = subscriberMetrics;
         this.packaging = packaging;
-    }
-
-    public void activate(BundleContext context, Map<String, Object> properties) {
         this.context = context;
         this.idleMillies = (Integer) properties.getOrDefault("idleMillies", SubscriberIdle.DEFAULT_IDLE_TIME_MILLIS);
         requireNonNull(resolverFactory);
diff --git a/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberTest.java b/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberTest.java
index 4d0710c..99784f8 100644
--- a/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/impl/subscriber/SubscriberTest.java
@@ -189,9 +189,8 @@ public class SubscriberTest {
         Awaitility.setDefaultPollDelay(Duration.ZERO);
         Awaitility.setDefaultPollInterval(Duration.ONE_HUNDRED_MILLISECONDS);
         
-        bookKeeperFactory = new BookKeeperFactory(resolverFactory, eventAdmin, subscriberMetrics, packaging);
         Map<String, Object> props = new HashMap<String, Object>();
-        bookKeeperFactory.activate(context, props);
+        bookKeeperFactory = new BookKeeperFactory(resolverFactory, eventAdmin, subscriberMetrics, packaging, context, props);
         subscriber.bookKeeperFactory = bookKeeperFactory;
         when(packageBuilder.getType()).thenReturn("journal");
         when(slingSettings.getSlingId()).thenReturn(SUB1_SLING_ID);