X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fcodegen%2Fimpl%2FAbstractRuntimeCodeGenerator.java;h=eba5b8756b88cfaa936e3aa20828706a29abaf5d;hp=86003b2aedc2344e86244134ea7870e83cfcd7c6;hb=170bc1beb43f8082570d066afe6dbd2bf5c3735e;hpb=753af6de42f98637e83bc26b4b058f47840863a8 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java index 86003b2aed..eba5b8756b 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java @@ -8,17 +8,11 @@ package org.opendaylight.controller.sal.binding.codegen.impl; import com.google.common.base.Supplier; - -import java.util.Map; -import java.util.WeakHashMap; - +import com.google.common.collect.Iterables; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; import javassist.NotFoundException; - -import javax.annotation.concurrent.GuardedBy; - import org.eclipse.xtext.xbase.lib.Extension; import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter; import org.opendaylight.controller.sal.binding.codegen.RpcIsNotRoutedException; @@ -31,6 +25,10 @@ import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext; import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils; +import javax.annotation.concurrent.GuardedBy; +import java.util.Map; +import java.util.WeakHashMap; + abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory { @GuardedBy("this") private final Map, RuntimeGeneratedInvokerPrototype> invokerClasses = new WeakHashMap<>(); @@ -136,22 +134,17 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll return invoker; } - utils.getLock().lock(); - try { - synchronized (utils) { - invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier() { - @Override - public RuntimeGeneratedInvokerPrototype get() { - return generateListenerInvoker(cls); - } - }); - } - - invokerClasses.put(cls, invoker); - return invoker; - } finally { - utils.getLock().unlock(); + synchronized (utils) { + invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier() { + @Override + public RuntimeGeneratedInvokerPrototype get() { + return generateListenerInvoker(cls); + } + }); } + + invokerClasses.put(cls, invoker); + return invoker; } @Override @@ -161,13 +154,8 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll @Override public final T getDirectProxyFor(final Class serviceType) { - utils.getLock().lock(); - try { - synchronized (utils) { - return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType)); - } - } finally { - utils.getLock().unlock(); + synchronized (utils) { + return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType)); } } @@ -184,14 +172,13 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll } }); - utils.getLock().lock(); - try { - synchronized (utils) { - final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata)); - return new RpcRouterCodegenInstance(name, serviceType, instance, metadata.getContexts()); - } - } finally { - utils.getLock().unlock(); + if (Iterables.isEmpty(metadata.getContexts())) { + throw new RpcIsNotRoutedException("Service doesn't have routing context associated."); + } + + synchronized (utils) { + final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata)); + return new RpcRouterCodegenInstance(name, serviceType, instance, metadata.getContexts()); } }