- private def void implementsType(CtClass it, CtClass supertype) {
- checkArgument(supertype.interface, "Supertype must be interface");
- addInterface(supertype);
+ for (ctx : metadata.contexts) {
+ field(ctx.routingTableField, Map)
+ }
+ implementMethodsFrom(supertype) [
+ if (parameterTypes.size === 1) {
+ val rpcMeta = metadata.getRpcMethod(name);
+ val bodyTmp = '''
+ {
+ if($1 == null) {
+ throw new IllegalArgumentException("RPC input must not be null and must contain a value for field «rpcMeta.inputRouteGetter.name»");
+ }
+ if($1.«rpcMeta.inputRouteGetter.name»() == null) {
+ throw new IllegalArgumentException("Field «rpcMeta.inputRouteGetter.name» must not be null");
+ }
+ 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»;
+ }
+ if(instance == null) {
+ throw new java.lang.IllegalStateException("No routable provider is processing routed message for " + String.valueOf(identifier));
+ }
+ return ($r) instance.«it.name»($$);
+ }'''
+ body = bodyTmp
+ } else if (parameterTypes.size === 0) {
+ body = '''return ($r) «DELEGATE_FIELD».«it.name»($$);'''
+ }
+ ]
+ implementMethodsFrom(RpcImplementation.asCtClass) [
+ body = '''
+ {
+ throw new java.lang.IllegalStateException("No provider is processing supplied message");
+ return ($r) null;
+ }
+ '''
+ ]
+ ]
+ return targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance as RpcService
+ ];