From 9225bdb88c85d6aae0ac6bbcffc372e5847d5058 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 18 Nov 2018 16:54:00 +0100 Subject: [PATCH] Use JvmGlobalLocks in elanmanager JvmGlobalLocks is giving us all we need to replace String.intern(), user that. JIRA: NETVIRT-1510 Change-Id: I72bc211512519e68f06394d28f539bf29f6cd16c Signed-off-by: Robert Varga --- .../elan/internal/ElanInterfaceManager.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java index b64e2c1031..62255cec3e 100644 --- a/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java +++ b/elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; +import java.util.concurrent.locks.ReentrantLock; import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Singleton; @@ -67,6 +68,7 @@ import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata; import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager; import org.opendaylight.genius.mdsalutil.matches.MatchMetadata; import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId; +import org.opendaylight.genius.utils.JvmGlobalLocks; import org.opendaylight.genius.utils.ServiceIndex; import org.opendaylight.infrautils.jobcoordinator.JobCoordinator; import org.opendaylight.infrautils.utils.concurrent.ListenableFutures; @@ -462,8 +464,10 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase tx) throws ExecutionException, InterruptedException { - synchronized (elanName.intern()) { - + // FIXME: pass in and use ElanInstanceKey instead? + final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanName); + lock.lock(); + try { DpnInterfaces dpnInterfaces = elanUtils.getElanInterfaceInfoByElanDpn(elanName, dpId); if (dpnInterfaces != null) { List interfaceLists = dpnInterfaces.getInterfaces(); @@ -479,6 +483,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase elanDpnInterfaces = ElanUtils .getElanDpnInterfaceOperationalDataPath(elanInstanceName, holder.dpId); Optional existingElanDpnInterfaces = operTx.read(elanDpnInterfaces).get(); @@ -745,6 +754,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase