1 package org.opendaylight.controller.sal.binding.impl;
3 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
4 import org.opendaylight.controller.sal.binding.api.BindingAwareService;
5 import org.opendaylight.yangtools.yang.binding.RpcService;
6 import org.osgi.framework.BundleContext;
7 import org.osgi.framework.InvalidSyntaxException;
8 import org.osgi.framework.ServiceReference;
9 import org.slf4j.LoggerFactory
11 class OsgiConsumerContext implements ConsumerContext {
13 static val log = LoggerFactory.getLogger(OsgiConsumerContext)
14 protected val BundleContext bundleContext;
15 protected val BindingAwareBrokerImpl broker;
17 new(BundleContext ctx,BindingAwareBrokerImpl broker) {
18 this.bundleContext = ctx;
23 override def <T extends BindingAwareService> getSALService(Class<T> service) {
24 // SAL Services are global
25 var ref = bundleContext.getServiceReference(service);
26 return bundleContext.getService(ref) as T;
31 override def <T extends RpcService> T getRpcService(Class<T> module) {
34 val services = bundleContext.getServiceReferences(module, getProxyFilter());
36 // Proxy service found / using first implementation
37 // FIXME: Add advanced logic to retrieve service with right set of models
38 if(false == services.empty) {
39 val ref = services.iterator().next() as ServiceReference<T>;
40 return bundleContext.getService(ref) as T;
42 } catch (InvalidSyntaxException e) {
43 log.error("Created filter was invalid:", e.message,e)
50 private def getProxyFilter() {
51 return '''(«Constants.SAL_SERVICE_TYPE»=«Constants.SAL_SERVICE_TYPE_CONSUMER_PROXY»)'''