1 package org.opendaylight.controller.sal.dom.broker
3 import java.util.Collections
4 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession
5 import java.util.HashMap
6 import org.opendaylight.controller.sal.core.api.BrokerService
7 import org.opendaylight.controller.sal.core.api.Consumer
8 import org.osgi.framework.BundleContext
9 import org.opendaylight.yangtools.yang.common.QName
10 import org.opendaylight.yangtools.yang.data.api.CompositeNode
12 class ConsumerContextImpl implements ConsumerSession {
15 private val Consumer consumer;
18 private var BrokerImpl broker;
20 private val instantiatedServices = Collections.synchronizedMap(
21 new HashMap<Class<? extends BrokerService>, BrokerService>());
22 private boolean closed = false;
24 private BundleContext context;
26 public new(Consumer consumer, BundleContext ctx) {
27 this._consumer = consumer;
31 override rpc(QName rpc, CompositeNode input) {
32 return broker.invokeRpc(rpc, input);
35 override <T extends BrokerService> T getService(Class<T> service) {
36 val potential = instantiatedServices.get(service);
37 if(potential != null) {
38 val ret = potential as T;
41 val ret = broker.serviceFor(service, this);
43 instantiatedServices.put(service, ret);
49 val toStop = instantiatedServices.values();
51 for (BrokerService brokerService : toStop) {
52 brokerService.closeSession();
54 broker.consumerSessionClosed(this);