config-persister-impl: use lambdas
[controller.git] / opendaylight / config / config-persister-impl / src / main / java / org / opendaylight / controller / config / persist / impl / osgi / ConfigPersisterActivator.java
index 5f25d6c3b2c27cd1f3b0d9dd2a0144eb250f8e38..c99fa767e299170c8ea68201ca3686281ca39480 100644 (file)
@@ -65,21 +65,21 @@ public class ConfigPersisterActivator implements BundleActivator {
         ServiceTrackerCustomizer<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory> schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer<ConfigSubsystemFacadeFactory, ConfigSubsystemFacadeFactory>() {
 
             @Override
-            public ConfigSubsystemFacadeFactory addingService(ServiceReference<ConfigSubsystemFacadeFactory> reference) {
+            public ConfigSubsystemFacadeFactory addingService(final ServiceReference<ConfigSubsystemFacadeFactory> reference) {
                 LOG.debug("Got addingService(SchemaContextProvider) event");
                 // Yang store service should not be registered multiple times
-                ConfigSubsystemFacadeFactory ConfigSubsystemFacadeFactory = reference.getBundle().getBundleContext().getService(reference);
-                startPusherThread(configs, maxWaitForCapabilitiesMillis, ConfigSubsystemFacadeFactory, conflictingVersionTimeoutMillis, persisterAggregator);
-                return ConfigSubsystemFacadeFactory;
+                ConfigSubsystemFacadeFactory configSubsystemFacadeFactory = reference.getBundle().getBundleContext().getService(reference);
+                startPusherThread(configs, maxWaitForCapabilitiesMillis, configSubsystemFacadeFactory, conflictingVersionTimeoutMillis, persisterAggregator);
+                return configSubsystemFacadeFactory;
             }
 
             @Override
-            public void modifiedService(ServiceReference<ConfigSubsystemFacadeFactory> reference, ConfigSubsystemFacadeFactory service) {
+            public void modifiedService(final ServiceReference<ConfigSubsystemFacadeFactory> reference, final ConfigSubsystemFacadeFactory service) {
                 LOG.warn("Config manager facade was modified unexpectedly");
             }
 
             @Override
-            public void removedService(ServiceReference<ConfigSubsystemFacadeFactory> reference, ConfigSubsystemFacadeFactory service) {
+            public void removedService(final ServiceReference<ConfigSubsystemFacadeFactory> reference, final ConfigSubsystemFacadeFactory service) {
                 LOG.warn("Config manager facade was removed unexpectedly");
             }
         };
@@ -89,18 +89,18 @@ public class ConfigPersisterActivator implements BundleActivator {
         schemaContextProviderServiceTracker.open();
     }
 
-    private long getConflictingVersionTimeoutMillis(PropertiesProviderBaseImpl propertiesProvider) {
+    private long getConflictingVersionTimeoutMillis(final PropertiesProviderBaseImpl propertiesProvider) {
         String timeoutProperty = propertiesProvider.getProperty(CONFLICTING_VERSION_TIMEOUT_MILLIS_PROPERTY);
         return timeoutProperty == null ? CONFLICTING_VERSION_TIMEOUT_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
     }
 
-    private long getMaxWaitForCapabilitiesMillis(PropertiesProviderBaseImpl propertiesProvider) {
+    private long getMaxWaitForCapabilitiesMillis(final PropertiesProviderBaseImpl propertiesProvider) {
         String timeoutProperty = propertiesProvider.getProperty(MAX_WAIT_FOR_CAPABILITIES_MILLIS_PROPERTY);
         return timeoutProperty == null ? MAX_WAIT_FOR_CAPABILITIES_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
     }
 
     @Override
-    public void stop(BundleContext context) throws Exception {
+    public void stop(final BundleContext context) throws Exception {
         synchronized(autoCloseables) {
             CloseableUtil.closeAll(autoCloseables);
             autoCloseables.clear();
@@ -119,33 +119,26 @@ 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 (InterruptedException e) {
-                        LOG.info("ConfigPusher thread stopped",e);
-                    }
-                    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();
     }
 }