- def Class<?> generateListenerInvoker(Class<? extends NotificationListener> iface) {
- val targetCls = createClass(iface.invokerName) [
- field(DELEGATE_FIELD, iface)
- it.method(Void, "invoke", Notification) [
- val callbacks = iface.methods.filter[notificationCallback]
- body = '''
- {
- «FOR callback : callbacks SEPARATOR " else "»
- if($1 instanceof «val cls = callback.parameterTypes.get(0).name») {
- «DELEGATE_FIELD».«callback.name»((«cls») $1);
- return;
+ override <T extends RpcService> getRouterFor(Class<T> iface,String routerInstanceName) {
+ val metadata = withClassLoader(iface.classLoader) [|
+ val supertype = iface.asCtClass
+ return supertype.rpcMetadata;
+ ]
+
+ val instance = <T>withClassLoaderAndLock(iface.classLoader,lock) [ |
+ val supertype = iface.asCtClass
+ val routerName = iface.routerName;
+ val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(routerName)
+ if(potentialClass != null) {
+ return potentialClass.newInstance as T;
+ }
+
+ val targetCls = createClass(iface.routerName, supertype) [
+
+
+ field(DELEGATE_FIELD, iface)
+ //field(REMOTE_INVOKER_FIELD,iface);
+ implementsType(RpcImplementation.asCtClass)
+
+ for (ctx : metadata.contexts) {
+ field(ctx.routingTableField, Map)
+ }
+ implementMethodsFrom(supertype) [
+ if (parameterTypes.size === 1) {
+ val rpcMeta = metadata.rpcMethods.get(name);
+ val bodyTmp = '''
+ {
+ final «InstanceIdentifier.name» identifier = $1.«rpcMeta.inputRouteGetter.name»()«IF rpcMeta.
+ routeEncapsulated».getValue()«ENDIF»;
+ «supertype.name» instance = («supertype.name») «rpcMeta.context.routingTableField».get(identifier);
+ if(instance == null) {
+ instance = «DELEGATE_FIELD»;