BUG-614: migrate RuntimeGeneratedInvoker 37/7737/6
authorRobert Varga <rovarga@cisco.com>
Thu, 5 Jun 2014 11:54:08 +0000 (13:54 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 10 Jun 2014 08:46:24 +0000 (08:46 +0000)
RuntimeGeneratedInvoker is another DTO, so let's migrate it to
java-land.

Change-Id: If8e654c38de1be5f8e263f81eb7550d745913906
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvoker.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvokerPrototype.java

index 63a1b211a3d361b129cd95c10e3ad44a1535310a..ac782051a85b708ad5d2d7ac1444b408753acef0 100644 (file)
@@ -13,9 +13,7 @@ import javassist.ClassPool
 import javassist.CtClass
 import javassist.CtMethod
 import javassist.LoaderClassPath
-import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper
 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory
-import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker
 import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils
 import org.opendaylight.yangtools.yang.binding.DataContainer
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
@@ -189,7 +187,7 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
         val cls = instance.class
         val prototype = resolveInvokerClass(cls);
 
-        return new RuntimeGeneratedInvoker(instance, prototype)
+        return RuntimeGeneratedInvoker.create(instance, prototype)
     }
 
     protected def generateListenerInvoker(Class<? extends NotificationListener> iface) {
@@ -219,10 +217,6 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
             finalClass as Class<? extends org.opendaylight.controller.sal.binding.api.NotificationListener<?>>);
     }
 
-
-
-
-
     protected def resolveInvokerClass(Class<? extends NotificationListener> class1) {
         return ClassLoaderUtils.<RuntimeGeneratedInvokerPrototype>withClassLoaderAndLock(class1.classLoader,lock) [|
             val invoker = invokerClasses.get(class1);
@@ -232,34 +226,6 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
             val newInvoker = generateListenerInvoker(class1);
             invokerClasses.put(class1, newInvoker);
             return newInvoker
-
         ]
     }
 }
-
-@Data
-package class RuntimeGeneratedInvoker implements NotificationInvoker {
-
-    @Property
-    val NotificationListener delegate;
-
-    @Property
-    var org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> invocationProxy;
-
-    @Property
-    var RuntimeGeneratedInvokerPrototype prototype;
-
-    new(NotificationListener delegate, RuntimeGeneratedInvokerPrototype prototype) {
-        _delegate = delegate;
-        _prototype = prototype;
-        _invocationProxy = prototype.protoClass.newInstance as org.opendaylight.controller.sal.binding.api.NotificationListener<Notification>;
-        RuntimeCodeHelper.setDelegate(_invocationProxy, delegate);
-    }
-
-    override getSupportedNotifications() {
-        prototype.supportedNotifications;
-    }
-
-    override close() {
-    }
-}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvoker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvoker.java
new file mode 100644 (file)
index 0000000..8762562
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.binding.codegen.impl;
+
+import java.util.Set;
+
+import org.eclipse.xtext.xbase.lib.util.ToStringHelper;
+import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper;
+import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+
+import com.google.common.base.Preconditions;
+
+final class RuntimeGeneratedInvoker implements NotificationInvoker {
+    private final org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> invocationProxy;
+    private final RuntimeGeneratedInvokerPrototype prototype;
+    private final NotificationListener delegate;
+
+    @SuppressWarnings("unchecked")
+    private RuntimeGeneratedInvoker(final NotificationListener delegate, final RuntimeGeneratedInvokerPrototype prototype, final org.opendaylight.controller.sal.binding.api.NotificationListener<?> proxy) {
+        this.invocationProxy = (org.opendaylight.controller.sal.binding.api.NotificationListener<Notification>) proxy;
+        this.delegate = Preconditions.checkNotNull(delegate);
+        this.prototype = prototype;
+    }
+
+    public static RuntimeGeneratedInvoker create(final NotificationListener delegate, final RuntimeGeneratedInvokerPrototype prototype) throws InstantiationException, IllegalAccessException {
+        final org.opendaylight.controller.sal.binding.api.NotificationListener<?> proxy = Preconditions.checkNotNull(prototype.getProtoClass().newInstance());
+        RuntimeCodeHelper.setDelegate(proxy, delegate);
+        return new RuntimeGeneratedInvoker(delegate, prototype, proxy);
+    }
+
+    @Override
+    public NotificationListener getDelegate() {
+        return delegate;
+    }
+
+    @Override
+    public org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> getInvocationProxy() {
+        return invocationProxy;
+    }
+
+    @Override
+    public Set<Class<? extends Notification>> getSupportedNotifications() {
+        return prototype.getSupportedNotifications();
+    }
+
+    @Override
+    public void close() {
+        // Nothing to do
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + delegate.hashCode();
+        result = prime * result + invocationProxy.hashCode();
+        result = prime * result + prototype.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof RuntimeGeneratedInvoker)) {
+            return false;
+        }
+        final RuntimeGeneratedInvoker other = (RuntimeGeneratedInvoker) obj;
+        if (!delegate.equals(other.delegate)) {
+            return false;
+        }
+        if (!invocationProxy.equals(other.invocationProxy)) {
+            return false;
+        }
+        return prototype.equals(other.prototype);
+    }
+
+    @Override
+    public String toString() {
+        String result = new ToStringHelper().toString(this);
+        return result;
+    }
+}
index f16074845d457edbde86fcd5fb62b4a572f3027b..317268420f1ce1ffc44c620e60c087c75bd7cb78 100644 (file)
@@ -28,7 +28,7 @@ final class RuntimeGeneratedInvokerPrototype {
         return supportedNotifications;
     }
 
-    public Class<? extends NotificationListener<? extends Object>> getProtoClass() {
+    public Class<? extends NotificationListener<?>> getProtoClass() {
         return protoClass;
     }