From 8aef9bdf7f32d49c270c10b29c5bb4b2718e6c3c Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Tue, 16 May 2017 17:48:58 +0200 Subject: [PATCH 1/1] config-persister-impl: use lambdas This series of patches uses lambdas instead of anonymous classes for functional interfaces when possible. Lambdas are replaced with method references when appropriate. Change-Id: I20e8b07b839c168d0944c44a57602c3b9a96ce6a Signed-off-by: Stephen Kitt --- .../config/persist/impl/ConfigPusherImpl.java | 9 +---- .../impl/osgi/ConfigPersisterActivator.java | 40 ++++++++----------- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java b/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java index ae4fb09ddc..684e68079c 100644 --- a/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java +++ b/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.config.persist.impl; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Function; import com.google.common.base.Stopwatch; import com.google.common.collect.Collections2; import java.io.IOException; @@ -23,7 +22,6 @@ import java.util.SortedSet; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; import javax.management.MBeanServerConnection; import org.opendaylight.controller.config.api.ConflictingVersionException; @@ -212,12 +210,7 @@ public class ConfigPusherImpl implements ConfigPusher { } static Set transformCapabilities(final Set currentCapabilities) { - return new HashSet<>(Collections2.transform(currentCapabilities, new Function() { - @Override - public String apply(@Nonnull final Capability input) { - return input.getCapabilityUri(); - } - })); + return new HashSet<>(Collections2.transform(currentCapabilities, Capability::getCapabilityUri)); } static class ConfigPusherException extends Exception { diff --git a/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/osgi/ConfigPersisterActivator.java b/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/osgi/ConfigPersisterActivator.java index 412309bdf6..c99fa767e2 100644 --- a/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/osgi/ConfigPersisterActivator.java +++ b/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/osgi/ConfigPersisterActivator.java @@ -119,32 +119,24 @@ public class ConfigPersisterActivator implements BundleActivator { LOG.debug("Configuration Persister got {}", service); LOG.debug("Context was {}", context); LOG.debug("Registration was {}", registration); - final Thread pushingThread = new Thread(new Runnable() { - @Override - public void run() { - try { - if(configs != null && !configs.isEmpty()) { - configPusher.pushConfigs(configs); - } - if(context != null) { - registration = context.registerService(ConfigPusher.class.getName(), configPusher, null); - configPusher.process(autoCloseables, platformMBeanServer, persisterAggregator, false); - } else { - LOG.warn("Unable to process configs as BundleContext is null"); - } - } catch (final InterruptedException e) { - LOG.info("ConfigPusher thread stopped"); - } - LOG.info("Configuration Persister initialization completed."); + final Thread pushingThread = new Thread(() -> { + try { + if(configs != null && !configs.isEmpty()) { + configPusher.pushConfigs(configs); } - }, "config-pusher"); - synchronized (autoCloseables) { - autoCloseables.add(new AutoCloseable() { - @Override - public void close() { - pushingThread.interrupt(); + if(context != null) { + registration = context.registerService(ConfigPusher.class.getName(), configPusher, null); + configPusher.process(autoCloseables, platformMBeanServer, persisterAggregator, false); + } else { + LOG.warn("Unable to process configs as BundleContext is null"); } - }); + } catch (final InterruptedException e) { + LOG.info("ConfigPusher thread stopped"); + } + LOG.info("Configuration Persister initialization completed."); + }, "config-pusher"); + synchronized (autoCloseables) { + autoCloseables.add(() -> pushingThread.interrupt()); } pushingThread.setDaemon(true); pushingThread.start(); -- 2.36.6