Updated implementation of internal RPC Router for Binding-Aware Broker and added...
[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     
28     
29     @Property
30     var T defaultService
31     
32     new(Class<T> type,T routerImpl,Set<Class<? extends BaseIdentity>> contexts) {
33         _rpcServiceType = type
34         _invocationProxy = routerImpl
35         _contexts = contexts
36         
37         for(ctx : contexts) {
38             val table = XtendHelper.createRoutingTable(ctx)
39             invocationProxy.setRoutingTable(ctx,table.routes);
40             routingTables.put(ctx,table);
41         }
42     }
43     
44     override <C extends BaseIdentity> getRoutingTable(Class<C> table) {
45         routingTables.get(table) as RpcRoutingTable<C,T>
46     }
47     
48     override getService(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
49         val table = getRoutingTable(context);
50         return table.getRoute(path);
51     }
52 }