X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fcodegen%2Fimpl%2FRuntimeCodeGenerator.xtend;h=90fcbd99aaaad0a6f6448faf0428cbc46cc52b4d;hb=10ba5a102f9e15a24c3f5a355a44fafadbf2801f;hp=ea6dc131c6583b3587b23cc172e61f62c3ad68af;hpb=d2f2d5a34ccd0a715ab6ea7c1f5ac61f16f6e6cc;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend index ea6dc131c6..90fcbd99aa 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend @@ -11,10 +11,6 @@ import javassist.ClassPool import org.opendaylight.yangtools.yang.binding.RpcService import javassist.CtClass -import static com.google.common.base.Preconditions.* - -import javassist.CtField -import javassist.Modifier import javassist.CtMethod import org.opendaylight.yangtools.yang.binding.InstanceIdentifier import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext @@ -22,13 +18,11 @@ import org.opendaylight.yangtools.yang.binding.BaseIdentity import java.util.Map import java.util.HashMap -import javassist.NotFoundException -import javassist.LoaderClassPath -import org.opendaylight.controller.sal.binding.codegen.impl.JavassistUtils.MethodGenerator -import org.opendaylight.controller.sal.binding.codegen.impl.JavassistUtils.ClassGenerator + + import org.opendaylight.yangtools.yang.binding.NotificationListener import org.opendaylight.yangtools.yang.binding.Notification -import java.util.Arrays + import static extension org.opendaylight.controller.sal.binding.codegen.YangtoolsMappingHelper.* import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.* @@ -39,19 +33,21 @@ import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.No import java.util.Set import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper import java.util.WeakHashMap -import javassist.ClassClassPath import org.opendaylight.yangtools.yang.binding.annotations.QName import org.opendaylight.yangtools.yang.binding.DataContainer import org.opendaylight.yangtools.yang.binding.RpcImplementation +import org.opendaylight.controller.sal.binding.codegen.util.JavassistUtils class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory { val CtClass BROKER_NOTIFICATION_LISTENER; val ClassPool classPool; + val extension JavassistUtils utils; val Map, RuntimeGeneratedInvokerPrototype> invokerClasses; public new(ClassPool pool) { classPool = pool; + utils = new JavassistUtils(pool); invokerClasses = new WeakHashMap(); BROKER_NOTIFICATION_LISTENER = org.opendaylight.controller.sal.binding.api.NotificationListener.asCtClass; } @@ -61,16 +57,21 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co val targetCls = createClass(iface.directProxyName, supertype) [ field(DELEGATE_FIELD, iface); implementMethodsFrom(supertype) [ - body = '''return ($r) «DELEGATE_FIELD».«it.name»($$);''' + body = ''' + { + if(«DELEGATE_FIELD» == null) { + throw new java.lang.IllegalStateException("No provider is processing supplied message"); + } + return ($r) «DELEGATE_FIELD».«it.name»($$); + } + ''' ] ] return targetCls.toClass(iface.classLoader).newInstance as T } override getRouterFor(Class iface) { - val contexts = new HashSet> - - val instance = >withClassLoader(iface.classLoader) [ | + val instance = >withClassLoaderAndLock(iface.classLoader,lock) [ | val supertype = iface.asCtClass val metadata = supertype.rpcMetadata; val targetCls = createClass(iface.routerName, supertype) [ @@ -213,77 +214,24 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co ] val finalClass = targetCls.toClass(iface.classLoader, iface.protectionDomain) return new RuntimeGeneratedInvokerPrototype(supportedNotification, - finalClass as Class); - } - - private def void method(CtClass it, Class returnType, String name, Class parameter, MethodGenerator function1) { - val method = new CtMethod(returnType.asCtClass, name, Arrays.asList(parameter.asCtClass), it); - function1.process(method); - it.addMethod(method); - } - - private def void implementMethodsFrom(CtClass target, CtClass source, MethodGenerator function1) { - for (method : source.methods) { - if (method.declaringClass == source) { - val redeclaredMethod = new CtMethod(method, target, null); - function1.process(redeclaredMethod); - target.addMethod(redeclaredMethod); - } - } + finalClass as Class>); } - private def CtClass createClass(String fqn, ClassGenerator cls) { - val target = classPool.makeClass(fqn); - cls.process(target); - return target; - } - - private def CtClass createClass(String fqn, CtClass superInterface, ClassGenerator cls) { - val target = classPool.makeClass(fqn); - target.implementsType(superInterface); - cls.process(target); - return target; - } - - private def void implementsType(CtClass it, CtClass supertype) { - checkArgument(supertype.interface, "Supertype must be interface"); - addInterface(supertype); - } + - private def asCtClass(Class class1) { - classPool.get(class1); - } - private def CtField field(CtClass it, String name, Class returnValue) { - val field = new CtField(returnValue.asCtClass, name, it); - field.modifiers = Modifier.PUBLIC - addField(field); - return field; - } - - def get(ClassPool pool, Class cls) { - try { - return pool.get(cls.name) - } catch (NotFoundException e) { - pool.appendClassPath(new LoaderClassPath(cls.classLoader)); - try { - return pool.get(cls.name) - - } catch (NotFoundException ef) { - pool.appendClassPath(new ClassClassPath(cls)); - return pool.get(cls.name) - } - } - } protected def resolveInvokerClass(Class class1) { - val invoker = invokerClasses.get(class1); - if (invoker !== null) { - return invoker; - } - val newInvoker = generateListenerInvoker(class1); - invokerClasses.put(class1, newInvoker); - return newInvoker + return withClassLoaderAndLock(class1.classLoader,lock) [| + val invoker = invokerClasses.get(class1); + if (invoker !== null) { + return invoker; + } + val newInvoker = generateListenerInvoker(class1); + invokerClasses.put(class1, newInvoker); + return newInvoker + + ] } } @@ -294,7 +242,7 @@ package class RuntimeGeneratedInvoker implements NotificationInvoker { val NotificationListener delegate; @Property - var org.opendaylight.controller.sal.binding.api.NotificationListener invocationProxy; + var org.opendaylight.controller.sal.binding.api.NotificationListener invocationProxy; @Property var RuntimeGeneratedInvokerPrototype prototype; @@ -302,7 +250,7 @@ package class RuntimeGeneratedInvoker implements NotificationInvoker { new(NotificationListener delegate, RuntimeGeneratedInvokerPrototype prototype) { _delegate = delegate; _prototype = prototype; - _invocationProxy = prototype.protoClass.newInstance; + _invocationProxy = prototype.protoClass.newInstance as org.opendaylight.controller.sal.binding.api.NotificationListener; RuntimeCodeHelper.setDelegate(_invocationProxy, delegate); } @@ -321,7 +269,7 @@ package class RuntimeGeneratedInvokerPrototype { val Set> supportedNotifications; @Property - val Class protoClass; + val Class> protoClass; } package class RpcServiceMetadata {