From af184cd606cd7e8da607ff0e188f3fb45a1ee4e8 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 4 Nov 2015 18:23:58 +0100 Subject: [PATCH] Improve YangStoreService performance Simple changes to eliminate synthetic methods and unneeded duplication of collections. Change-Id: I370d4ed85720e2b7eb811204afa9f532b716b16d Signed-off-by: Robert Varga --- .../facade/xml/osgi/YangStoreService.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java index ebdfe550da..462d67bc00 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreService.java @@ -10,6 +10,7 @@ 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; import java.lang.ref.SoftReference; import java.util.Collections; @@ -20,7 +21,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicReference; -import javax.annotation.Nullable; import org.opendaylight.controller.config.util.capability.Capability; import org.opendaylight.controller.config.util.capability.ModuleListener; import org.opendaylight.controller.config.util.capability.YangModuleCapability; @@ -83,7 +83,7 @@ public class YangStoreService implements YangStoreContext { this.sourceProvider = sourceProvider; } - private synchronized YangStoreContext getYangStoreSnapshot() { + synchronized YangStoreContext getYangStoreSnapshot() { SoftReference r = ref.get(); YangStoreSnapshot ret = r.get(); @@ -106,6 +106,7 @@ public class YangStoreService implements YangStoreContext { return getYangStoreSnapshot(); } + @Deprecated @Override public Map> getModuleMXBeanEntryMap() { return getYangStoreSnapshot().getModuleMXBeanEntryMap(); @@ -150,15 +151,16 @@ public class YangStoreService implements YangStoreContext { return new AutoCloseable() { @Override - public void close() throws Exception { + public void close() { YangStoreService.this.listeners.remove(listener); } }; } - private Set toCapabilities(final Set modules, final YangStoreContext current) { - return Sets.newHashSet(Collections2.transform(modules, new Function() { - @Nullable @Override public Capability apply(final Module input) { + private static Set toCapabilities(final Set modules, final YangStoreContext current) { + return ImmutableSet.copyOf(Collections2.transform(modules, new Function() { + @Override + public Capability apply(final Module input) { return new YangModuleCapability(input, current.getModuleSource(input)); } })); @@ -176,12 +178,17 @@ public class YangStoreService implements YangStoreContext { public void run() { final YangStoreContext current = getYangStoreSnapshot(); - if(!current.equals(previous)) { - final Set removed = Sets.difference(previous.getModules(), current.getModules()); - final Set added = Sets.difference(current.getModules(), previous.getModules()); + if (!current.equals(previous)) { + final Set prevModules = previous.getModules(); + final Set currModules = current.getModules(); + final Set removed = Sets.difference(prevModules, currModules); + final Set added = Sets.difference(currModules, prevModules); + + final Set addedCaps = toCapabilities(added, current); + final Set removedCaps = toCapabilities(removed, current); for (final ModuleListener listener : listeners) { - listener.onCapabilitiesChanged(toCapabilities(added, current), toCapabilities(removed, current)); + listener.onCapabilitiesChanged(addedCaps, removedCaps); } } } -- 2.36.6