Inject the certificate manager in the constructor 47/76947/3
authorStephen Kitt <skitt@redhat.com>
Fri, 12 Oct 2018 10:06:53 +0000 (12:06 +0200)
committerStephen Kitt <skitt@redhat.com>
Fri, 26 Oct 2018 08:27:30 +0000 (10:27 +0200)
This simplifies wiring in other contexts (e.g. with Blueprint
annotations or Guice).

Change-Id: If76dae1ec26d3ef3e3488788b6a5b77d99bb70a1
Signed-off-by: Stephen Kitt <skitt@redhat.com>
library/impl/pom.xml
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java
library/impl/src/main/resources/OSGI-INF/blueprint/library.xml

index 02f25e841d5b774914d63a938de4a7e0e0e22de3..1ba80531e39e492895638ac5bfbb50b5d98d1b33 100644 (file)
@@ -68,6 +68,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>aaa-cert</artifactId>
       <version>0.9.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+    </dependency>
 
     <!-- Testing Dependencies -->
     <dependency>
index 7e12a4ee7fc21c7a6ff6bb9ce0da2770b44cbd58..ed502369c88fba86726da5d53b2b7c4eacfb85a9 100644 (file)
@@ -49,6 +49,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.Nullable;
+import javax.inject.Inject;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
@@ -107,7 +108,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private static final Map<OvsdbClient, Channel> CONNECTIONS = new ConcurrentHashMap<>();
 
     private volatile boolean useSSL = false;
-    private volatile ICertificateManager certManagerSrv;
+    private final ICertificateManager certManagerSrv;
 
     private volatile int jsonRpcDecoderMaxFrameLength = 100000;
     private volatile Channel serverChannel;
@@ -116,6 +117,11 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private volatile String listenerIp = "0.0.0.0";
     private volatile int listenerPort = 6640;
 
+    @Inject
+    public OvsdbConnectionService(ICertificateManager certManagerSrv) {
+        this.certManagerSrv = certManagerSrv;
+    }
+
     /**
      * If the SSL flag is enabled, the method internally will establish TLS communication using the default
      * ODL certificateManager SSLContext and attributes.
@@ -554,15 +560,6 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         useSSL = flag;
     }
 
-    /**
-     * Set default Certificate manager service.
-     *
-     * @param certificateManagerSrv reference
-     */
-    public void setCertificatManager(ICertificateManager certificateManagerSrv) {
-        certManagerSrv = certificateManagerSrv;
-    }
-
     /**
      * Blueprint property setter method. Blueprint call this method and set the value of json rpc decoder
      * max frame length to the value configured for config option (json-rpc-decoder-max-frame-length) in
index 40073a087e20bcd2c7e9b14aa2a81e7d75670ba8..5eaf9f0339d620db8a86d9056256d5050866ff33 100644 (file)
@@ -24,6 +24,7 @@
 
   <!-- Notify OvsdbConnectionService with any change in the config properties value-->
   <bean id="ovsdbConnectionService" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
+    <argument ref="aaaCertificateManager"/>
     <cm:managed-properties persistent-id="org.opendaylight.ovsdb.library"
                            update-strategy="component-managed"
                            update-method="updateConfigParameter"/>
@@ -31,7 +32,6 @@
     <property name="ovsdbListenerPort" value="${ovsdb-listener-port}"/>
     <property name="ovsdbRpcTaskTimeout" value="${ovsdb-rpc-task-timeout}"/>
     <property name="useSsl" value="${use-ssl}"/>
-    <property name="certificatManager" ref="aaaCertificateManager"/>
     <property name="jsonRpcDecoderMaxFrameLength" value="${json-rpc-decoder-max-frame-length}"/>
   </bean>