Convert netconf-client to OSGi DS 04/96904/6
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Jul 2021 16:12:35 +0000 (18:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Jul 2021 18:03:56 +0000 (20:03 +0200)
This is a rather straighforward migration, but we also ditch the
now-unneeded Autocloseable from AbstractNetconfDispatcher.

JIRA: NETCONF-791
Change-Id: I4737ef30e0ff3b12bbaedcf8940edf80d8eb7d7a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-client/pom.xml
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java
netconf/netconf-client/src/main/resources/OSGI-INF/blueprint/netconf-client.xml [deleted file]
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java
netconf/tools/netconf-testtool/pom.xml

index 91e1243d6b6de9b261f88dee2d11b74382dc616b..3bed1320ccbe2a34dd6261d8921f587d99056979 100644 (file)
       <artifactId>guava</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
+      <groupId>com.guicedee.services</groupId>
+      <artifactId>javax.inject</artifactId>
+      <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>mockito-configuration</artifactId>
index df4ee5eeb7cde408d8f2384db9d5790f5a143fbf..2565a7325244a19c6724903c489173ef2feff689 100644 (file)
@@ -7,34 +7,45 @@
  */
 package org.opendaylight.netconf.client;
 
+import static java.util.Objects.requireNonNull;
+
 import io.netty.channel.EventLoopGroup;
 import io.netty.util.Timer;
 import io.netty.util.concurrent.Future;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.netconf.nettyutil.AbstractNetconfDispatcher;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
+@Component(immediate = true, service = NetconfClientDispatcher.class, property = "type=netconf-client-dispatcher")
 public class NetconfClientDispatcherImpl
         extends AbstractNetconfDispatcher<NetconfClientSession, NetconfClientSessionListener>
         implements NetconfClientDispatcher {
-
     private static final Logger LOG = LoggerFactory.getLogger(NetconfClientDispatcherImpl.class);
 
     private final Timer timer;
 
-    public NetconfClientDispatcherImpl(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
-                                       final Timer timer) {
+    @Inject
+    @Activate
+    public NetconfClientDispatcherImpl(@Reference(target = "(type=global-boss-group)") final EventLoopGroup bossGroup,
+            @Reference(target = "(type=global-worker-group)") final EventLoopGroup workerGroup,
+            @Reference(target = "(type=global-timer)") final Timer timer) {
         super(bossGroup, workerGroup);
-        this.timer = timer;
+        this.timer = requireNonNull(timer);
     }
 
-    protected Timer getTimer() {
+    protected final Timer getTimer() {
         return timer;
     }
 
@@ -127,15 +138,15 @@ public class NetconfClientDispatcherImpl
         if (odlHelloCapabilities == null || odlHelloCapabilities.isEmpty()) {
             return new NetconfClientSessionNegotiatorFactory(timer, cfg.getAdditionalHeader(),
                     cfg.getConnectionTimeoutMillis());
-        } else {
-            // LinkedHashSet since perhaps the device cares about order of hello message capabilities.
-            // This allows user control of the order while complying with the existing interface.
-            final Set<String> stringCapabilities = new LinkedHashSet<>();
-            for (final Uri uri : odlHelloCapabilities) {
-                stringCapabilities.add(uri.getValue());
-            }
-            return new NetconfClientSessionNegotiatorFactory(timer, cfg.getAdditionalHeader(),
-                    cfg.getConnectionTimeoutMillis(), stringCapabilities);
         }
+
+        // LinkedHashSet since perhaps the device cares about order of hello message capabilities.
+        // This allows user control of the order while complying with the existing interface.
+        final Set<String> stringCapabilities = new LinkedHashSet<>();
+        for (final Uri uri : odlHelloCapabilities) {
+            stringCapabilities.add(uri.getValue());
+        }
+        return new NetconfClientSessionNegotiatorFactory(timer, cfg.getAdditionalHeader(),
+            cfg.getConnectionTimeoutMillis(), stringCapabilities);
     }
 }
diff --git a/netconf/netconf-client/src/main/resources/OSGI-INF/blueprint/netconf-client.xml b/netconf/netconf-client/src/main/resources/OSGI-INF/blueprint/netconf-client.xml
deleted file mode 100644 (file)
index fb2b56b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 Inocybe Technologies Inc. and others.  All rights reserved.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-
-    <reference id="globalBossGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-boss-group"/>
-    <reference id="globalWorkerGroup" interface="io.netty.channel.EventLoopGroup" odl:type="global-worker-group"/>
-    <reference id="timer" interface="io.netty.util.Timer" odl:type="global-timer"/>
-
-    <bean id="netconfClientDispatcherImpl"
-          class="org.opendaylight.netconf.client.NetconfClientDispatcherImpl">
-        <argument ref="globalBossGroup"/>
-        <argument ref="globalWorkerGroup"/>
-        <argument ref="timer"/>
-    </bean>
-    <service ref="netconfClientDispatcherImpl"
-             interface="org.opendaylight.netconf.client.NetconfClientDispatcher"
-             odl:type="netconf-client-dispatcher">
-        <service-properties>
-        <entry key="config-module-namespace" value="urn:opendaylight:params:xml:ns:yang:controller:config:netconf"/>
-        <entry key="config-module-name" value="netconf-client-dispatcher"/>
-        <entry key="config-instance-name" value="global-netconf-dispatcher"/>
-        </service-properties>
-    </service>
-
-</blueprint>
index bbddb1d0c5afaa94364d59881094561a4c83eae4..d5ce7bfee5e0ff1cac556a11c8585a3c85b06731 100644 (file)
@@ -27,7 +27,6 @@ import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
-import java.io.Closeable;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import org.opendaylight.netconf.api.NetconfSession;
@@ -40,9 +39,7 @@ import org.slf4j.LoggerFactory;
  * start method that will handle sockets in different thread.
  */
 @Deprecated
-public abstract class AbstractNetconfDispatcher<S extends NetconfSession, L extends NetconfSessionListener<? super S>>
-        implements Closeable {
-
+public abstract class AbstractNetconfDispatcher<S extends NetconfSession, L extends NetconfSessionListener<? super S>> {
     protected interface ChannelPipelineInitializer<C extends Channel, S extends NetconfSession> {
         /**
          * Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore
@@ -59,7 +56,6 @@ public abstract class AbstractNetconfDispatcher<S extends NetconfSession, L exte
 
     }
 
-
     private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfDispatcher.class);
 
     private final EventLoopGroup bossGroup;
@@ -252,9 +248,4 @@ public abstract class AbstractNetconfDispatcher<S extends NetconfSession, L exte
             bootstrap.group(workerGroup);
         }
     }
-
-    @Deprecated
-    @Override
-    public void close() {
-    }
 }
index 59de196f37766a29f703369d59f1527b9c4df429..233ab26cdeb83368416edcb9cf52ba385da3a916 100644 (file)
             <groupId>${project.groupId}</groupId>
             <artifactId>netconf-client</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.guicedee.services</groupId>
+            <artifactId>javax.inject</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
             <artifactId>rfc6991</artifactId>