Fix checkstyle issues to enforce it
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / osgi / YangStoreService.java
index f89d26b0cd1b426e6fb765b2e962ca4e7bdd05ee..4eef7ee39eaeae9143214c45e343bf2f2e0a5a47 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,7 +8,6 @@
 
 package org.opendaylight.controller.config.facade.xml.osgi;
 
-import com.google.common.base.Function;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
@@ -24,7 +23,7 @@ import org.opendaylight.controller.config.util.capability.Capability;
 import org.opendaylight.controller.config.util.capability.ModuleListener;
 import org.opendaylight.controller.config.util.capability.YangModuleCapability;
 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
-import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
+import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
@@ -36,29 +35,30 @@ public class YangStoreService implements YangStoreContext {
 
     private final SchemaSourceProvider<YangTextSchemaSource> sourceProvider;
     private final ExecutorService notificationExecutor = Executors.newSingleThreadExecutor(
-        new ThreadFactoryBuilder().setDaemon(true).setNameFormat("yangstore-capability-notifications").build());
+            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("yangstore-capability-notifications").build());
 
     /**
-     * Guarded by explicit lock to allow for properly synchronizing the initial notification and modification
-     * of the listener set.
+     * Guarded by explicit lock to allow for properly synchronizing the initial
+     * notification and modification of the listener set.
      */
     @GuardedBy("listeners")
     private final Set<ModuleListener> listeners = new HashSet<>();
 
     /**
-     * This is the latest snapshot. Some of its state is always initialized, but the MXBean maps potentially cause
-     * recomputation. Accessing those two specific methods needs to re-check whether the snapshot has changed
-     * asynchronously and retry if it didi.
+     * This is the latest snapshot. Some of its state is always initialized, but the
+     * MXBean maps potentially cause recomputation. Accessing those two specific
+     * methods needs to re-check whether the snapshot has changed asynchronously and
+     * retry if it didi.
      */
     private volatile YangStoreSnapshot snap;
 
     public YangStoreService(final SchemaContextProvider schemaContextProvider,
-        final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
+            final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
         this.sourceProvider = sourceProvider;
     }
 
     public YangStoreContext getCurrentSnapshot() {
-        return snap;
+        return this.snap;
     }
 
     @Deprecated
@@ -68,9 +68,9 @@ public class YangStoreService implements YangStoreContext {
         YangStoreSnapshot snapshot;
 
         do {
-            snapshot = snap;
+            snapshot = this.snap;
             ret = snapshot.getModuleMXBeanEntryMap();
-        } while (!snapshot.equals(snap));
+        } while (!snapshot.equals(this.snap));
 
         return ret;
     }
@@ -81,56 +81,49 @@ public class YangStoreService implements YangStoreContext {
         YangStoreSnapshot snapshot;
 
         do {
-            snapshot = snap;
+            snapshot = this.snap;
             ret = snapshot.getQNamesToIdentitiesToModuleMXBeanEntries();
-        } while (!snapshot.equals(snap));
+        } while (!snapshot.equals(this.snap));
 
         return ret;
     }
 
     @Override
     public Set<Module> getModules() {
-        return snap.getModules();
+        return this.snap.getModules();
     }
 
     @Override
     public String getModuleSource(final ModuleIdentifier moduleIdentifier) {
-        return snap.getModuleSource(moduleIdentifier);
+        return this.snap.getModuleSource(moduleIdentifier);
     }
 
     @Override
     public EnumResolver getEnumResolver() {
-        return snap.getEnumResolver();
+        return this.snap.getEnumResolver();
     }
 
     public void refresh(final BindingRuntimeContext runtimeContext) {
-        final YangStoreSnapshot next = new YangStoreSnapshot(runtimeContext, sourceProvider);
-        final YangStoreSnapshot previous = snap;
-        snap = next;
-        notificationExecutor.submit(new Runnable() {
-            @Override
-            public void run() {
-                notifyListeners(previous, next);
-            }
-        });
+        final YangStoreSnapshot next = new YangStoreSnapshot(runtimeContext, this.sourceProvider);
+        final YangStoreSnapshot previous = this.snap;
+        this.snap = next;
+        this.notificationExecutor.submit(() -> notifyListeners(previous, next));
     }
 
     public AutoCloseable registerModuleListener(final ModuleListener listener) {
-        final YangStoreContext context = snap;
+        final YangStoreContext context = this.snap;
 
-        synchronized (listeners) {
+        synchronized (this.listeners) {
             if (context != null) {
-                listener.onCapabilitiesChanged(toCapabilities(context.getModules(), context), Collections.<Capability>emptySet());
+                listener.onCapabilitiesChanged(toCapabilities(context.getModules(), context),
+                        Collections.<Capability>emptySet());
             }
             this.listeners.add(listener);
         }
 
-        return new AutoCloseable() {
-            @Override
-            public void close() {
-                synchronized (listeners) {
-                    listeners.remove(listener);
-                }
+        return () -> {
+            synchronized (YangStoreService.this.listeners) {
+                YangStoreService.this.listeners.remove(listener);
             }
         };
     }
@@ -144,19 +137,15 @@ public class YangStoreService implements YangStoreContext {
         final Set<Capability> addedCaps = toCapabilities(added, current);
         final Set<Capability> removedCaps = toCapabilities(removed, current);
 
-        synchronized (listeners) {
-            for (final ModuleListener listener : listeners) {
+        synchronized (this.listeners) {
+            for (final ModuleListener listener : this.listeners) {
                 listener.onCapabilitiesChanged(addedCaps, removedCaps);
             }
         }
     }
 
     private static Set<Capability> toCapabilities(final Set<Module> modules, final YangStoreContext current) {
-        return ImmutableSet.copyOf(Collections2.transform(modules, new Function<Module, Capability>() {
-            @Override
-            public Capability apply(final Module input) {
-                return new YangModuleCapability(input, current.getModuleSource(input));
-            }
-        }));
+        return ImmutableSet.copyOf(Collections2.transform(modules,
+            input -> new YangModuleCapability(input, current.getModuleSource(input))));
     }
 }