Clean up NetconfSessionMonitoringService 52/105752/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 30 Apr 2023 17:24:11 +0000 (19:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 30 Apr 2023 17:24:36 +0000 (19:24 +0200)
Use direct collection to ImmutableList and BindingMap to simplify
indexing.

JIRA: NETCONF-945
Change-Id: I7e8c3fbbb2222842fedcc6e26c599da4a824e7a5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/osgi/NetconfSessionMonitoringService.java

index 81551428a4a5be0e6943e1b5683e78b1bcdbb563..968a931650c7b301861cf33fee6f764371025dbf 100644 (file)
@@ -8,12 +8,8 @@
 package org.opendaylight.netconf.server.osgi;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-import java.util.Collection;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ScheduledExecutorService;
@@ -29,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
 import org.opendaylight.yangtools.concepts.AbstractRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,19 +58,18 @@ class NetconfSessionMonitoringService implements SessionListener, AutoCloseable
             executor = schedulingThreadPool.orElseThrow().getExecutor();
             LOG.info("/netconf-state/sessions will be updated every {} seconds.", updateInterval);
         } else {
-            LOG.info("Scheduling thread pool is present = {}, "
-                    + "update interval {}: /netconf-state/sessions won't be updated.",
-                    schedulingThreadPool.isPresent(), updateInterval);
+            LOG.info(
+                "Scheduling thread pool is present = {}, update interval {}: /netconf-state/sessions won't be updated.",
+                schedulingThreadPool.isPresent(), updateInterval);
             executor = null;
         }
     }
 
     synchronized Sessions getSessions() {
-        final Collection<Session> managementSessions = Collections2.transform(sessions,
-                NetconfManagementSession::toManagementSession);
         return new SessionsBuilder()
-                .setSession(Maps.uniqueIndex(managementSessions, Session::key))
-                .build();
+            .setSession(BindingMap.of(
+                sessions.stream().map(NetconfManagementSession::toManagementSession).collect(Collectors.toList())))
+            .build();
     }
 
     @Override
@@ -122,12 +118,11 @@ class NetconfSessionMonitoringService implements SessionListener, AutoCloseable
         if (changedSessions.isEmpty()) {
             return;
         }
-        final List<Session> changed = changedSessions.stream()
+        final var changed = changedSessions.stream()
                 .map(NetconfManagementSession::toManagementSession)
-                .collect(Collectors.toList());
-        final ImmutableList<Session> sessionImmutableList = ImmutableList.copyOf(changed);
+                .collect(ImmutableList.toImmutableList());
         for (NetconfMonitoringService.SessionsListener listener : listeners) {
-            listener.onSessionsUpdated(sessionImmutableList);
+            listener.onSessionsUpdated(changed);
         }
         changedSessions.clear();
     }