Use JvmGlobalLocks in elanmanager 14/77914/11
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 18 Nov 2018 15:54:00 +0000 (16:54 +0100)
committerSam Hague <shague@redhat.com>
Fri, 25 Jan 2019 21:18:21 +0000 (21:18 +0000)
JvmGlobalLocks is giving us all we need to replace String.intern(),
user that.

JIRA: NETVIRT-1510
Change-Id: I72bc211512519e68f06394d28f539bf29f6cd16c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/internal/ElanInterfaceManager.java

index b64e2c1031e4f9fe2b1776ad06172c3099627c26..62255cec3e5cd121808b4a9d4b448cc4c78405f7 100644 (file)
@@ -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<ElanIn
                                                                          String interfaceName, long elanTag,
                                                                          TypedReadWriteTransaction<Operational> 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<String> interfaceLists = dpnInterfaces.getInterfaces();
@@ -479,6 +483,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                 }
             }
             return dpnInterfaces;
+        } finally {
+            lock.unlock();
         }
     }
 
@@ -704,7 +710,10 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
             // DpnInterfaces in the operational DS.
             holder.dpId = interfaceInfo.getDpId();
             if (holder.dpId != null && !holder.dpId.equals(ElanConstants.INVALID_DPN)) {
-                synchronized (elanInstanceName.intern()) {
+                // FIXME: use elanInstaince.key() instead?
+                final ReentrantLock lock = JvmGlobalLocks.getLockForString(elanInstanceName);
+                lock.lock();
+                try {
                     InstanceIdentifier<DpnInterfaces> elanDpnInterfaces = ElanUtils
                         .getElanDpnInterfaceOperationalDataPath(elanInstanceName, holder.dpId);
                     Optional<DpnInterfaces> existingElanDpnInterfaces = operTx.read(elanDpnInterfaces).get();
@@ -745,6 +754,8 @@ public class ElanInterfaceManager extends AsyncDataTreeChangeListenerBase<ElanIn
                         holder.dpnInterfaces =
                             updateElanDpnInterfacesList(elanInstanceName, holder.dpId, elanInterfaces, operTx);
                     }
+                } finally {
+                    lock.unlock();
                 }
             }