f63f2a313ef58375e95d165f4b5823b504cda3d4
[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 org.opendaylight.yangtools.yang.binding.DataObject
12 import static org.opendaylight.controller.sal.binding.codegen.impl.XtendHelper.*
13
14 class RpcRouterCodegenInstance<T extends RpcService> implements RpcRouter<T> {
15
16     @Property
17     val T invocationProxy
18
19     @Property
20     val Class<T> rpcServiceType
21
22     @Property
23     val Set<Class<? extends BaseIdentity>> contexts
24
25     val routingTables = new HashMap<Class<? extends BaseIdentity>, RpcRoutingTableImpl<? extends BaseIdentity, ?>>;
26
27     @Property
28     var T defaultService
29
30     new(Class<T> type, T routerImpl, Set<Class<? extends BaseIdentity>> contexts) {
31         _rpcServiceType = type
32         _invocationProxy = routerImpl
33         _contexts = contexts
34
35         for (ctx : contexts) {
36             val table = XtendHelper.createRoutingTable(ctx)
37             invocationProxy.setRoutingTable(ctx, table.routes);
38             routingTables.put(ctx, table);
39         }
40     }
41
42     override <C extends BaseIdentity> getRoutingTable(Class<C> table) {
43         routingTables.get(table) as RpcRoutingTable<C,T>
44     }
45
46     override getService(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
47         val table = getRoutingTable(context);
48         return table.getRoute(path);
49     }
50 }