+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.controller.sal.dom.broker
-import java.util.Collections
import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession
-import java.util.HashMap
import org.opendaylight.controller.sal.core.api.BrokerService
import org.opendaylight.controller.sal.core.api.Consumer
import org.osgi.framework.BundleContext
import org.opendaylight.yangtools.yang.common.QName
import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import org.opendaylight.controller.sal.dom.broker.osgi.AbstractBrokerServiceProxy
+import com.google.common.collect.ClassToInstanceMap
+import com.google.common.collect.MutableClassToInstanceMap
+import org.opendaylight.controller.sal.dom.broker.osgi.ProxyFactory
class ConsumerContextImpl implements ConsumerSession {
@Property
private var BrokerImpl broker;
- private val instantiatedServices = Collections.synchronizedMap(
- new HashMap<Class<? extends BrokerService>, BrokerService>());
+ private val ClassToInstanceMap<BrokerService> instantiatedServices = MutableClassToInstanceMap.create();
private boolean closed = false;
private BundleContext context;
}
override rpc(QName rpc, CompositeNode input) {
- return broker.invokeRpc(rpc, input);
+ return broker.invokeRpcAsync(rpc, input);
}
override <T extends BrokerService> T getService(Class<T> service) {
- val potential = instantiatedServices.get(service);
- if(potential != null) {
- val ret = potential as T;
- return ret;
+ val localProxy = instantiatedServices.getInstance(service);
+ if(localProxy != null) {
+ return localProxy;
}
- val ret = broker.serviceFor(service, this);
+ val serviceRef = context.getServiceReference(service);
+ if(serviceRef == null) {
+ return null;
+ }
+ val serviceImpl = context.getService(serviceRef);
+
+
+ val ret = ProxyFactory.createProxy(serviceRef,serviceImpl);
if(ret != null) {
- instantiatedServices.put(service, ret);
+ instantiatedServices.putInstance(service, ret);
}
return ret;
}
val toStop = instantiatedServices.values();
this.closed = true;
for (BrokerService brokerService : toStop) {
- brokerService.closeSession();
+ if(brokerService instanceof AbstractBrokerServiceProxy<?>) {
+ (brokerService as AutoCloseable).close();
+ }
}
broker.consumerSessionClosed(this);
}