X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fimpl%2Fosgi%2FNetconfSessionMonitoringService.java;h=103dc1bcf84caf9fb7306e98fd0042d093871a5d;hb=refs%2Fchanges%2F20%2F79220%2F3;hp=68883fde680b80546bd8fa1a3a2fdaa02e995158;hpb=990f1c0d249e9f27e192cf6c1300e516ace81087;p=netconf.git diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfSessionMonitoringService.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfSessionMonitoringService.java index 68883fde68..103dc1bcf8 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfSessionMonitoringService.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfSessionMonitoringService.java @@ -11,8 +11,8 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; @@ -30,7 +30,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class implements {@link SessionListener} to receive updates about Netconf sessions. Instance notifies its listeners + * This class implements {@link SessionListener} to receive updates about Netconf sessions. Instance notifies its + * listeners * about session start and end. It also publishes on regular interval list of sessions, * where events like rpc or notification happened. */ @@ -38,31 +39,36 @@ class NetconfSessionMonitoringService implements SessionListener, AutoCloseable private static final Logger LOG = LoggerFactory.getLogger(NetconfSessionMonitoringService.class); - private final Set sessions = Sets.newHashSet(); - private final Set changedSessions = Sets.newHashSet(); - private final Set listeners = Sets.newHashSet(); + private final Set sessions = new HashSet<>(); + private final Set changedSessions = new HashSet<>(); + private final Set listeners = new HashSet<>(); private final ScheduledExecutorService executor; private final long updateInterval; private boolean running; /** - * @param schedulingThreadPool thread pool for scheduling session stats updates. If not present, updates won't be scheduled. - * @param updateInterval update interval. If is less than 0, updates won't be scheduled + * Constructor for {@code NetconfSessionMonitoringService}. + * + * @param schedulingThreadPool thread pool for scheduling session stats updates. If not present, updates won't be + * scheduled. + * @param updateInterval update interval. If is less than 0, updates won't be scheduled */ NetconfSessionMonitoringService(Optional schedulingThreadPool, long updateInterval) { this.updateInterval = updateInterval; if (schedulingThreadPool.isPresent() && updateInterval > 0) { - this.executor = schedulingThreadPool.get().getExecutor(); + this.executor = schedulingThreadPool.get().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.", + LOG.info("Scheduling thread pool is present = {}, " + + "update interval {}: /netconf-state/sessions won't be updated.", schedulingThreadPool.isPresent(), updateInterval); this.executor = null; } } synchronized Sessions getSessions() { - final Collection managementSessions = Collections2.transform(sessions, NetconfManagementSession::toManagementSession); + final Collection managementSessions = Collections2.transform(sessions, + NetconfManagementSession::toManagementSession); return new SessionsBuilder().setSession(ImmutableList.copyOf(managementSessions)).build(); } @@ -93,16 +99,11 @@ class NetconfSessionMonitoringService implements SessionListener, AutoCloseable if (!running) { startUpdateSessionStats(); } - return new AutoCloseable() { - @Override - public void close() throws Exception { - listeners.remove(listener); - } - }; + return () -> listeners.remove(listener); } @Override - public synchronized void close() throws Exception { + public synchronized void close() { stopUpdateSessionStats(); listeners.clear(); sessions.clear();