Turn FileAkkaConfigurationReader into a component 75/91275/5
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 12 Jul 2020 07:55:19 +0000 (09:55 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 12 Jul 2020 12:14:57 +0000 (12:14 +0000)
This is a clearly standalone implementation of a common service,
turn it into a properly-injected component.

Change-Id: I521c3433093ab3aa911aa870c10b3d4e2bff8418
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/pom.xml
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/FileAkkaConfigurationReader.java
opendaylight/md-sal/sal-distributed-datastore/src/main/resources/OSGI-INF/blueprint/clustered-datastore.xml

index 26bfff67c67ada55f451a688f4ae93cd049aa379..c3f03074ca380a78e800888823999065929ebe84 100644 (file)
     <dependency>
       <groupId>com.typesafe.akka</groupId>
       <artifactId>akka-osgi_2.13</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>com.typesafe.akka</groupId>
       <groupId>io.dropwizard.metrics</groupId>
       <artifactId>metrics-jmx</artifactId>
     </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.kohsuke.metainf-services</groupId>
+      <artifactId>metainf-services</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+    </dependency>
 
     <!-- Google -->
     <dependency>
index 883dbd7210a97f320c12e29d2a6353d4a9b7467d..7951f5d3cc887113adaf8d5120e96415af251087 100644 (file)
@@ -5,22 +5,33 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.common.actor;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+
 import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import java.io.File;
+import javax.inject.Singleton;
+import org.kohsuke.MetaInfServices;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+@Component(immediate = true)
+@MetaInfServices
+@Singleton
 public class FileAkkaConfigurationReader implements AkkaConfigurationReader {
+    private static final Logger LOG = LoggerFactory.getLogger(FileAkkaConfigurationReader.class);
     private static final String CUSTOM_AKKA_CONF_PATH = "./configuration/initial/akka.conf";
     private static final String FACTORY_AKKA_CONF_PATH = "./configuration/factory/akka.conf";
 
     @Override
     public Config read() {
         File customConfigFile = new File(CUSTOM_AKKA_CONF_PATH);
-        Preconditions.checkState(customConfigFile.exists(), "%s is missing", customConfigFile);
+        checkState(customConfigFile.exists(), "%s is missing", customConfigFile);
 
         File factoryConfigFile = new File(FACTORY_AKKA_CONF_PATH);
         if (factoryConfigFile.exists()) {
@@ -29,4 +40,14 @@ public class FileAkkaConfigurationReader implements AkkaConfigurationReader {
 
         return ConfigFactory.parseFile(customConfigFile);
     }
+
+    @Activate
+    void activate() {
+        LOG.info("File-based Akka configuration reader enabled");
+    }
+
+    @Deactivate
+    void deactivate() {
+        LOG.info("File-based Akka configuration reader disabled");
+    }
 }
index 182a1b40858ee2c010d02d6a5065372a965a6e03..d6fadcbb37bb0aa710857be1495f0da7b1c59c20 100644 (file)
@@ -25,7 +25,8 @@
     <argument ref="blueprintBundleContext" />
   </bean>
 
-  <bean id="akkaReader" class="org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader"/>
+  <reference id="akkaReader" interface="org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader"/>
+
   <bean id="akkaConfig" class="org.opendaylight.controller.cluster.akka.impl.AkkaConfigFactory"
           factory-method="createAkkaConfig">
     <argument ref="akkaReader" />