From: Robert Varga Date: Fri, 16 Jul 2021 16:12:35 +0000 (+0200) Subject: Convert netconf-client to OSGi DS X-Git-Tag: v2.0.1~2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=36e48dc5a4067059b06f866fb06d770cf6819775;p=netconf.git Convert netconf-client to OSGi DS 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 --- diff --git a/netconf/netconf-client/pom.xml b/netconf/netconf-client/pom.xml index 91e1243d6b..3bed1320cc 100644 --- a/netconf/netconf-client/pom.xml +++ b/netconf/netconf-client/pom.xml @@ -38,9 +38,15 @@ guava - org.slf4j - slf4j-api + com.guicedee.services + javax.inject + true + + org.osgi + org.osgi.service.component.annotations + + org.opendaylight.yangtools mockito-configuration diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java index df4ee5eeb7..2565a73252 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/NetconfClientDispatcherImpl.java @@ -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 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 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 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 index fb2b56b270..0000000000 --- a/netconf/netconf-client/src/main/resources/OSGI-INF/blueprint/netconf-client.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java index bbddb1d0c5..d5ce7bfee5 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java @@ -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> - implements Closeable { - +public abstract class AbstractNetconfDispatcher> { protected interface ChannelPipelineInitializer { /** * Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore @@ -59,7 +56,6 @@ public abstract class AbstractNetconfDispatcher${project.groupId} netconf-client + + com.guicedee.services + javax.inject + true + org.opendaylight.mdsal.binding.model.ietf rfc6991