- body = '''return ($r) «DELEGATE_FIELD».«it.name»($$);'''
- ]
- ]
- return targetCls.toClass(iface.classLoader)
- }
-
- def <T extends RpcService> Class<? extends T> generateRouter(Class<T> iface) {
- val supertype = iface.asCtClass
- val targetCls = createClass(iface.routerName, supertype) [
- //field(ROUTING_TABLE_FIELD,Map)
- field(DELEGATE_FIELD, iface)
- val contexts = new HashMap<String, Class<? extends BaseIdentity>>();
- // We search for routing pairs and add fields
- supertype.methods.filter[declaringClass == supertype && parameterTypes.size === 1].forEach [ method |
- val routingPair = method.routingContextInput;
- if (routingPair !== null)
- contexts.put(routingPair.context.routingTableField, routingPair.context);
- ]
- for (ctx : contexts.entrySet) {
- field(ctx.key, Map)
- }
- implementMethodsFrom(supertype) [
- if (parameterTypes.size === 1) {
- val routingPair = routingContextInput;
- val bodyTmp = '''
- {
- final «InstanceIdentifier.name» identifier = $1.«routingPair.getter.name»();
- «supertype.name» instance = («supertype.name») «routingPair.context.routingTableField».get(identifier);
- if(instance == null) {
- instance = «DELEGATE_FIELD»;
- }
- return ($r) instance.«it.name»($$);
- }'''
- body = bodyTmp
- } else if (parameterTypes.size === 0) {
- body = '''return ($r) «DELEGATE_FIELD».«it.name»($$);'''