config-persister-impl: use lambdas 70/57170/4
authorStephen Kitt <skitt@redhat.com>
Tue, 16 May 2017 15:48:58 +0000 (17:48 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 30 Jul 2017 10:18:06 +0000 (10:18 +0000)
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 <skitt@redhat.com>
opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java
opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/osgi/ConfigPersisterActivator.java

index ae4fb09..684e680 100644 (file)
@@ -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<String> transformCapabilities(final Set<Capability> currentCapabilities) {
-        return new HashSet<>(Collections2.transform(currentCapabilities, new Function<Capability, String>() {
-            @Override
-            public String apply(@Nonnull final Capability input) {
-                return input.getCapabilityUri();
-            }
-        }));
+        return new HashSet<>(Collections2.transform(currentCapabilities, Capability::getCapabilityUri));
     }
 
     static class ConfigPusherException extends Exception {
index 412309b..c99fa76 100644 (file)
@@ -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();

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.