Updated implementation of broker (data services, generated code), added Integration...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / codegen / impl / RpcRouterCodegenInstance.xtend
1 package org.opendaylight.controller.sal.binding.codegen.impl
2
3 import org.opendaylight.yangtools.yang.binding.RpcService
4 import org.opendaylight.controller.sal.binding.spi.RpcRouter
5 import org.opendaylight.yangtools.yang.binding.BaseIdentity
6 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
7 import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.*
8 import java.util.Set
9 import java.util.HashMap
10 import org.opendaylight.controller.sal.binding.spi.RpcRoutingTable
11 import static org.opendaylight.controller.sal.binding.codegen.impl.XtendHelper.*
12 import org.opendaylight.yangtools.yang.binding.DataContainer
13 import org.opendaylight.yangtools.yang.binding.RpcImplementation
14
15 class RpcRouterCodegenInstance<T extends RpcService> implements RpcRouter<T> {
16
17     @Property
18     val T invocationProxy
19
20     @Property
21     val RpcImplementation invokerDelegate;
22
23     @Property
24     val Class<T> serviceType
25
26     @Property
27     val Set<Class<? extends BaseIdentity>> contexts
28
29     @Property
30     val Set<Class<? extends DataContainer>> supportedInputs;
31
32     val routingTables = new HashMap<Class<? extends BaseIdentity>, RpcRoutingTableImpl<? extends BaseIdentity, ? extends RpcService>>;
33
34     @Property
35     var T defaultService
36
37     new(Class<T> type, T routerImpl, Set<Class<? extends BaseIdentity>> contexts,
38         Set<Class<? extends DataContainer>> inputs) {
39         _serviceType = type
40         _invocationProxy = routerImpl
41         _invokerDelegate = routerImpl as RpcImplementation
42         _contexts = contexts
43         _supportedInputs = inputs;
44
45         for (ctx : contexts) {
46             val table = XtendHelper.createRoutingTable(ctx)
47             invocationProxy.setRoutingTable(ctx, table.routes);
48             routingTables.put(ctx, table);
49         }
50     }
51
52     override <C extends BaseIdentity> getRoutingTable(Class<C> table) {
53         routingTables.get(table) as RpcRoutingTable<C,T>
54     }
55
56     override getService(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
57         val table = getRoutingTable(context);
58         return table.getRoute(path);
59     }
60
61     override <T extends DataContainer> invoke(Class<T> type, T input) {
62         return invokerDelegate.invoke(type, input);
63     }
64
65 }