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%2FRuntimeCodeHelper.xtend;h=fbd87d17beede977e4efa2b987f077352522481c;hb=13efd0b8e167e8aadd531b5ec0e72572a72bc249;hp=2e73977804c79f649d502535cc9decae1b30fbd3;hpb=a251833f27fd00040904e2df316cd707c8129d1e;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend index 2e73977804..fbd87d17be 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend @@ -44,6 +44,23 @@ class RuntimeCodeHelper { } else throw new IllegalArgumentException("delegate class is not assignable to proxy"); } + + /** + * Helper method to set delegate to ManagedDirectedProxy with use of reflection. + * + * Note: This method uses reflection, but setting delegate field should not occur too much + * to introduce any significant performance hits. + * + */ + public static def void setDelegate(Object proxy, Object delegate) { + val field = proxy.class.getField(DELEGATE_FIELD) + if (field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy"); + if (field.type.isAssignableFrom(delegate.class)) { + field.set(proxy, delegate) + } else + throw new IllegalArgumentException("delegate class is not assignable to proxy"); + } + public static def Map, ? extends RpcService> getRoutingTable(RpcService target, Class tableClass) {