From: Robert Varga Date: Tue, 24 Oct 2023 21:03:23 +0000 (+0200) Subject: Return ImmutableSet from transformCapabilities() X-Git-Tag: v7.0.0~381 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=9ad163e5cf49e47b4f0c7f5d901660cc0789153b;p=netconf.git Return ImmutableSet from transformCapabilities() Ditch use of Collections2 and modernize to return ImmutableSet, which conveys the semantics. JIRA: NETCONF-1106 Change-Id: Ic815d7236299a5da5737299b685fa13592fde2d8 Signed-off-by: Robert Varga --- diff --git a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/CurrentSchemaContext.java b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/CurrentSchemaContext.java index 07761374b2..7bb366c124 100644 --- a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/CurrentSchemaContext.java +++ b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/CurrentSchemaContext.java @@ -15,7 +15,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.dom.api.DOMSchemaService; -import org.opendaylight.netconf.server.api.monitoring.Capability; import org.opendaylight.netconf.server.api.monitoring.CapabilityListener; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; @@ -27,7 +26,7 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; @SuppressWarnings("checkstyle:FinalClass") public class CurrentSchemaContext implements EffectiveModelContextListener, AutoCloseable { private final AtomicReference currentContext = new AtomicReference<>(); - private final Set listeners1 = Collections.synchronizedSet(new HashSet<>()); + private final Set listeners = Collections.synchronizedSet(new HashSet<>()); private final SchemaSourceProvider rootSchemaSourceProvider; private Registration schemaContextListenerListenerRegistration; @@ -59,16 +58,16 @@ public class CurrentSchemaContext implements EffectiveModelContextListener, Auto public void onModelContextUpdated(final EffectiveModelContext schemaContext) { currentContext.set(schemaContext); // FIXME is notifying all the listeners from this callback wise ? - final Set addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities( - currentContext.get(), rootSchemaSourceProvider); - for (final CapabilityListener listener : listeners1) { + final var addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(schemaContext, + rootSchemaSourceProvider); + for (var listener : listeners) { listener.onCapabilitiesChanged(addedCaps, Set.of()); } } @Override public void close() { - listeners1.clear(); + listeners.clear(); schemaContextListenerListenerRegistration.close(); currentContext.set(null); } @@ -76,7 +75,7 @@ public class CurrentSchemaContext implements EffectiveModelContextListener, Auto public Registration registerCapabilityListener(final CapabilityListener listener) { listener.onCapabilitiesChanged(MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get(), rootSchemaSourceProvider), Set.of()); - listeners1.add(listener); - return () -> listeners1.remove(listener); + listeners.add(listener); + return () -> listeners.remove(listener); } } diff --git a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/MdsalNetconfOperationServiceFactory.java b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/MdsalNetconfOperationServiceFactory.java index 3649430d24..75bcf3ed80 100644 --- a/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/MdsalNetconfOperationServiceFactory.java +++ b/plugins/netconf-server-mdsal/src/main/java/org/opendaylight/netconf/server/mdsal/MdsalNetconfOperationServiceFactory.java @@ -88,8 +88,7 @@ public final class MdsalNetconfOperationServiceFactory implements NetconfOperati } // FIXME: ImmutableSet - static Set transformCapabilities( - final EffectiveModelContext currentContext, + static Set transformCapabilities(final EffectiveModelContext currentContext, final SchemaSourceProvider rootSchemaSourceProviderDependency) { final var capabilities = new HashSet(); diff --git a/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionNegotiatorFactory.java b/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionNegotiatorFactory.java index c93740eb5d..19c1a19173 100644 --- a/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionNegotiatorFactory.java +++ b/protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionNegotiatorFactory.java @@ -7,7 +7,6 @@ */ package org.opendaylight.netconf.server; -import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import io.netty.channel.Channel; @@ -100,17 +99,18 @@ public class NetconfServerSessionNegotiatorFactory { public NetconfServerSessionNegotiator getSessionNegotiator(final Channel channel, final Promise promise) { final var sessionId = idProvider.getNextSessionId(); - final var socketAddress = channel.parent() == null ? null : channel.parent().localAddress(); - final var service = getOperationServiceForAddress(sessionId, socketAddress); - final var listener = new NetconfServerSessionListener( - new NetconfOperationRouterImpl(service, monitoringService, sessionId), monitoringService, service); + final var service = getOperationServiceForAddress(sessionId, + channel.parent() == null ? null : channel.parent().localAddress()); return new NetconfServerSessionNegotiator(createHelloMessage(sessionId, monitoringService), sessionId, promise, - channel, timer, listener, connectionTimeoutMillis, maximumIncomingChunkSize); + channel, timer, + new NetconfServerSessionListener(new NetconfOperationRouterImpl(service, monitoringService, sessionId), + monitoringService, service), + connectionTimeoutMillis, maximumIncomingChunkSize); } protected NetconfOperationService getOperationServiceForAddress(final SessionIdType sessionId, - final SocketAddress socketAddress) { + final SocketAddress socketAddress) { return aggregatedOpService.createService(sessionId); } @@ -125,7 +125,7 @@ public class NetconfServerSessionNegotiatorFactory { sessionId); } - public static Set transformCapabilities(final Capabilities capabilities) { - return Sets.newHashSet(Collections2.transform(capabilities.getCapability(), Uri::getValue)); + public static ImmutableSet transformCapabilities(final Capabilities capabilities) { + return capabilities.requireCapability().stream().map(Uri::getValue).collect(ImmutableSet.toImmutableSet()); } }