1 package org.opendaylight.controller.sal.dom.broker
3 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession
4 import org.opendaylight.controller.sal.core.api.BrokerService
5 import org.opendaylight.controller.sal.core.api.Consumer
6 import org.osgi.framework.BundleContext
7 import org.opendaylight.yangtools.yang.common.QName
8 import org.opendaylight.yangtools.yang.data.api.CompositeNode
9 import org.opendaylight.controller.sal.dom.broker.osgi.AbstractBrokerServiceProxy
10 import com.google.common.collect.ClassToInstanceMap
11 import com.google.common.collect.MutableClassToInstanceMap
12 import org.opendaylight.controller.sal.dom.broker.osgi.ProxyFactory
14 class ConsumerContextImpl implements ConsumerSession {
17 private val Consumer consumer;
20 private var BrokerImpl broker;
22 private val ClassToInstanceMap<BrokerService> instantiatedServices = MutableClassToInstanceMap.create();
23 private boolean closed = false;
25 private BundleContext context;
27 public new(Consumer consumer, BundleContext ctx) {
28 this._consumer = consumer;
32 override rpc(QName rpc, CompositeNode input) {
33 return broker.invokeRpc(rpc, input);
36 override <T extends BrokerService> T getService(Class<T> service) {
37 val localProxy = instantiatedServices.getInstance(service);
38 if(localProxy != null) {
41 val serviceRef = context.getServiceReference(service);
42 if(serviceRef == null) {
45 val serviceImpl = context.getService(serviceRef);
48 val ret = ProxyFactory.createProxy(serviceRef,serviceImpl);
50 instantiatedServices.putInstance(service, ret);
56 val toStop = instantiatedServices.values();
58 for (BrokerService brokerService : toStop) {
59 if(brokerService instanceof AbstractBrokerServiceProxy<?>) {
60 (brokerService as AutoCloseable).close();
63 broker.consumerSessionClosed(this);