BUG-1381: make users of JavassistUtils.getLock synchronized properly 95/9095/2
authorRobert Varga <rovarga@cisco.com>
Wed, 16 Jul 2014 21:07:27 +0000 (23:07 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 24 Jul 2014 12:05:56 +0000 (12:05 +0000)
As a transition period, use both locking schemes. Once the initial
patches are in, we can then remove the use of getLock().

Change-Id: Ibf4c0ea9f420d81dfe74f7b0c5479f01b45a8d2d
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java

index 8fa88ead0797a69df10c65f63078bac05476b479..86003b2aedc2344e86244134ea7870e83cfcd7c6 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.sal.binding.codegen.impl;
 
+import com.google.common.base.Supplier;
+
 import java.util.Map;
 import java.util.WeakHashMap;
 
@@ -29,8 +31,6 @@ import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
 import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils;
 
-import com.google.common.base.Supplier;
-
 abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory {
     @GuardedBy("this")
     private final Map<Class<? extends NotificationListener>, RuntimeGeneratedInvokerPrototype> invokerClasses = new WeakHashMap<>();
@@ -138,12 +138,14 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll
 
         utils.getLock().lock();
         try {
-            invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier<RuntimeGeneratedInvokerPrototype>() {
-                @Override
-                public RuntimeGeneratedInvokerPrototype get() {
-                    return generateListenerInvoker(cls);
-                }
-            });
+            synchronized (utils) {
+                invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier<RuntimeGeneratedInvokerPrototype>() {
+                    @Override
+                    public RuntimeGeneratedInvokerPrototype get() {
+                        return generateListenerInvoker(cls);
+                    }
+                });
+            }
 
             invokerClasses.put(cls, invoker);
             return invoker;
@@ -161,7 +163,9 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll
     public final <T extends RpcService> T getDirectProxyFor(final Class<T> serviceType) {
         utils.getLock().lock();
         try {
-            return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType));
+            synchronized (utils) {
+                return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType));
+            }
         } finally {
             utils.getLock().unlock();
         }
@@ -182,8 +186,10 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll
 
         utils.getLock().lock();
         try {
-            final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata));
-            return new RpcRouterCodegenInstance<T>(name, serviceType, instance, metadata.getContexts());
+            synchronized (utils) {
+                final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata));
+                return new RpcRouterCodegenInstance<T>(name, serviceType, instance, metadata.getContexts());
+            }
         } finally {
             utils.getLock().unlock();
         }