X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fimpl%2FBindingAwareBrokerImpl.xtend;h=d9a3dd547f67a1cc448272f7d0a67c2284fb9ddb;hp=bd7f25c02ffb866376515165e5adbe18eee34273;hb=caee336f062eba4909ba53cbaccdde0714236134;hpb=ee7b48483f602adb6179960baad1ba76e20770c3 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend index bd7f25c02f..d9a3dd547f 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend @@ -42,12 +42,18 @@ import com.google.common.collect.Multimap import com.google.common.collect.HashMultimap import static org.opendaylight.controller.sal.binding.impl.osgi.ClassLoaderUtils.* import java.util.concurrent.Executors +import java.util.Collections +import org.opendaylight.yangtools.yang.binding.DataObject -class BindingAwareBrokerImpl implements BindingAwareBroker { +class BindingAwareBrokerImpl implements BindingAwareBroker, AutoCloseable { private static val log = LoggerFactory.getLogger(BindingAwareBrokerImpl) + + private InstanceIdentifier root = InstanceIdentifier.builder().toInstance(); + private val clsPool = ClassPool.getDefault() private var RuntimeCodeGenerator generator; + /** * Map of all Managed Direct Proxies @@ -63,28 +69,58 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { */ private val Map, RpcRouter> rpcRouters = new ConcurrentHashMap(); + @Property private var NotificationBrokerImpl notifyBroker + + @Property private var DataBrokerImpl dataBroker - private var ServiceRegistration notifyBrokerRegistration - + @Property var BundleContext brokerBundleContext + + ServiceRegistration notifyProviderRegistration + + ServiceRegistration notifyConsumerRegistration + + ServiceRegistration dataProviderRegistration + + ServiceRegistration dataConsumerRegistration + + private HashMapDataStore store = new HashMapDataStore(); + + public new(BundleContext bundleContext) { + _brokerBundleContext = bundleContext; + } def start() { + log.info("Starting MD-SAL: Binding Aware Broker"); initGenerator(); val executor = Executors.newCachedThreadPool; // Initialization of notificationBroker + log.info("Starting MD-SAL: Binding Aware Notification Broker"); notifyBroker = new NotificationBrokerImpl(executor); notifyBroker.invokerFactory = generator.invokerFactory; + + log.info("Starting MD-SAL: Binding Aware Data Broker"); dataBroker = new DataBrokerImpl(); + dataBroker.executor = executor; + val brokerProperties = newProperties(); - notifyBrokerRegistration = brokerBundleContext.registerService(NotificationProviderService, notifyBroker, + + + log.info("Starting MD-SAL: Binding Aware Data Broker"); + notifyProviderRegistration = brokerBundleContext.registerService(NotificationProviderService, notifyBroker, brokerProperties) - brokerBundleContext.registerService(NotificationService, notifyBroker, brokerProperties) - brokerBundleContext.registerService(DataProviderService, dataBroker, brokerProperties) - brokerBundleContext.registerService(DataBrokerService, dataBroker, brokerProperties) - + notifyConsumerRegistration = brokerBundleContext.registerService(NotificationService, notifyBroker, brokerProperties) + dataProviderRegistration = brokerBundleContext.registerService(DataProviderService, dataBroker, brokerProperties) + dataConsumerRegistration = brokerBundleContext.registerService(DataBrokerService, dataBroker, brokerProperties) + + + getDataBroker().registerDataReader(root, store); + getDataBroker().registerCommitHandler(root, store) + + log.info("MD-SAL: Binding Aware Broker Started"); } def initGenerator() { @@ -150,16 +186,11 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { def registerRpcImplementation(Class type, T service, OsgiProviderContext context, Hashtable properties) { val proxy = getManagedDirectProxy(type) - checkState(proxy.delegate === null, "The Service for type {} is already registered", type) + checkState(proxy.delegate === null, "The Service for type %s is already registered", type) val osgiReg = context.bundleContext.registerService(type, service, properties); proxy.delegate = service; - return new RpcServiceRegistrationImpl(type, service, osgiReg); - } - - def RpcRegistration registerMountedRpcImplementation(Class type, T service, - InstanceIdentifier identifier, OsgiProviderContext context) { - throw new UnsupportedOperationException("TODO: auto-generated method stub") + return new RpcServiceRegistrationImpl(type, service, osgiReg,this); } def RoutedRpcRegistration registerRoutedRpcImplementation(Class type, T service, @@ -230,7 +261,16 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { val routingTable = router.getRoutingTable(context) val path = ctxMap.value routingTable.removeRoute(path) + } + } + + protected def void unregisterRpcService(RpcServiceRegistrationImpl registration) { + val type = registration.serviceType; + + val proxy = managedProxies.get(type); + if(proxy.proxy.delegate === registration.instance) { + proxy.proxy.delegate = null; } } @@ -238,6 +278,17 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { getManagedDirectProxy(type); } + def getRpcRouters() { + return Collections.unmodifiableMap(rpcRouters); + } + + override close() { + dataConsumerRegistration.unregister() + dataProviderRegistration.unregister() + notifyConsumerRegistration.unregister() + notifyProviderRegistration.unregister() + } + } class RoutedRpcRegistrationImpl extends AbstractObjectRegistration implements RoutedRpcRegistration { @@ -272,10 +323,6 @@ class RoutedRpcRegistrationImpl extends AbstractObjectRegi unregisterPath(context, instance); } - override getService() { - return instance; - } - override registerPath(Class context, InstanceIdentifier path) { checkClosed() broker.registerPath(this, context, path); @@ -285,6 +332,10 @@ class RoutedRpcRegistrationImpl extends AbstractObjectRegi checkClosed() broker.unregisterPath(this, context, path); } + + override getServiceType() { + return router.serviceType; + } private def checkClosed() { if (closed) @@ -292,3 +343,24 @@ class RoutedRpcRegistrationImpl extends AbstractObjectRegi } } +class RpcServiceRegistrationImpl extends AbstractObjectRegistration implements RpcRegistration { + + val ServiceRegistration osgiRegistration; + private var BindingAwareBrokerImpl broker; + + @Property + val Class serviceType; + + public new(Class type, T service, ServiceRegistration osgiReg,BindingAwareBrokerImpl broker) { + super(service); + this._serviceType = type; + this.osgiRegistration = osgiReg; + this.broker= broker; + } + + override protected removeRegistration() { + broker.unregisterRpcService(this); + broker = null; + } + +}