*/
package org.opendaylight.controller.sal.binding.codegen.impl;
-import java.util.Map;
-import java.util.WeakHashMap;
-
+import com.google.common.base.Supplier;
+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;
import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils;
-import com.google.common.base.Supplier;
+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")
return invoker;
}
- utils.getLock().lock();
- try {
+ synchronized (utils) {
invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier<RuntimeGeneratedInvokerPrototype>() {
@Override
public RuntimeGeneratedInvokerPrototype get() {
return generateListenerInvoker(cls);
}
});
-
- invokerClasses.put(cls, invoker);
- return invoker;
- } finally {
- utils.getLock().unlock();
}
+
+ invokerClasses.put(cls, invoker);
+ return invoker;
}
@Override
@Override
public final <T extends RpcService> T getDirectProxyFor(final Class<T> serviceType) {
- utils.getLock().lock();
- try {
+ synchronized (utils) {
return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType));
- } finally {
- utils.getLock().unlock();
}
}
}
});
- utils.getLock().lock();
- try {
+ 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<T>(name, serviceType, instance, metadata.getContexts());
- } finally {
- utils.getLock().unlock();
}
}