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=b4bf3f5a83cbcaff144af392ee2f1141235aa753;hp=31d5d0126fc8115546d1d1b7709671e946b2e026;hb=178d185be418a9ed491201bd6a0e4d98efa9d820;hpb=f8e25f0e3d6196b5d3625c94a52ed5a6ab3fe5a7 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 31d5d0126f..b4bf3f5a83 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 @@ -9,126 +9,41 @@ package org.opendaylight.controller.sal.binding.impl import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer import org.opendaylight.controller.sal.binding.api.BindingAwareProvider -import org.opendaylight.yangtools.yang.binding.RpcService -import javassist.ClassPool import org.osgi.framework.BundleContext -import java.util.Map -import java.util.HashMap -import javassist.LoaderClassPath import org.opendaylight.controller.sal.binding.api.BindingAwareBroker -import java.util.Hashtable -import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.* - import org.opendaylight.controller.sal.binding.api.NotificationProviderService -import org.osgi.framework.ServiceRegistration -import static org.opendaylight.controller.sal.binding.impl.osgi.Constants.* -import static extension org.opendaylight.controller.sal.binding.impl.osgi.PropertiesUtils.* -import org.opendaylight.controller.sal.binding.api.NotificationService import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext - -import org.slf4j.LoggerFactory -import org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator import org.opendaylight.yangtools.yang.binding.InstanceIdentifier -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration -import org.opendaylight.controller.sal.binding.api.data.DataProviderService -import org.opendaylight.controller.sal.binding.api.data.DataBrokerService -import org.opendaylight.controller.sal.binding.spi.RpcRouter -import java.util.concurrent.ConcurrentHashMap -import static com.google.common.base.Preconditions.* -import org.opendaylight.yangtools.concepts.AbstractObjectRegistration -import org.opendaylight.yangtools.yang.binding.BaseIdentity -import com.google.common.collect.Multimap -import com.google.common.collect.HashMultimap -import static org.opendaylight.controller.sal.binding.impl.util.ClassLoaderUtils.* -import java.util.concurrent.Executors -import java.util.Collections import org.opendaylight.yangtools.yang.binding.DataObject -import org.opendaylight.controller.sal.binding.impl.connect.dom.ConnectorActivator +import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener +import org.opendaylight.controller.sal.binding.spi.RpcContextIdentifier +import org.opendaylight.controller.sal.binding.api.data.DataProviderService +import org.slf4j.LoggerFactory -class BindingAwareBrokerImpl implements BindingAwareBroker, AutoCloseable { +class BindingAwareBrokerImpl extends RpcProviderRegistryImpl 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 - * - */ - private val Map, RpcProxyContext> managedProxies = new ConcurrentHashMap(); - - /** - * - * Map of all available Rpc Routers - * - * - */ - private val Map, RpcRouter> rpcRouters = new ConcurrentHashMap(); - @Property - private var NotificationBrokerImpl notifyBroker - + private var NotificationProviderService notifyBroker + @Property - private var DataBrokerImpl dataBroker - + private var DataProviderService dataBroker + @Property var BundleContext brokerBundleContext - - ServiceRegistration notifyProviderRegistration - - ServiceRegistration notifyConsumerRegistration - - ServiceRegistration dataProviderRegistration - - ServiceRegistration dataConsumerRegistration - - ConnectorActivator connectorActivator - - - public new(BundleContext bundleContext) { + + public new(String name,BundleContext bundleContext) { + super(name); _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(); - - - log.info("Starting MD-SAL: Binding Aware Data Broker"); - notifyProviderRegistration = brokerBundleContext.registerService(NotificationProviderService, notifyBroker, - brokerProperties) - notifyConsumerRegistration = brokerBundleContext.registerService(NotificationService, notifyBroker, brokerProperties) - dataProviderRegistration = brokerBundleContext.registerService(DataProviderService, dataBroker, brokerProperties) - dataConsumerRegistration = brokerBundleContext.registerService(DataBrokerService, dataBroker, brokerProperties) - - connectorActivator = new ConnectorActivator(dataBroker,brokerBundleContext); - connectorActivator.start(); - log.info("MD-SAL: Binding Aware Broker Started"); } - def initGenerator() { - // YANG Binding Class Loader - clsPool.appendClassPath(new LoaderClassPath(RpcService.classLoader)); - generator = new RuntimeCodeGenerator(clsPool); - } override registerConsumer(BindingAwareConsumer consumer, BundleContext bundleCtx) { val ctx = consumer.createContext(bundleCtx) @@ -151,216 +66,11 @@ class BindingAwareBrokerImpl implements BindingAwareBroker, AutoCloseable { new OsgiProviderContext(providerCtx, this) } - /** - * Returns a Managed Direct Proxy for supplied class - * - * Managed direct proxy is a generated proxy class conforming to the supplied interface - * which delegates all calls to the backing delegate. - * - * Proxy does not do any validation, null pointer checks or modifies data in any way, it - * is only use to avoid exposing direct references to backing implementation of service. - * - * If proxy class does not exist for supplied service class it will be generated automatically. - */ - private def getManagedDirectProxy(Class service) { - - var RpcProxyContext existing = null - if ((existing = managedProxies.get(service)) != null) { - return existing.proxy - } - val proxyInstance = generator.getDirectProxyFor(service) - val rpcProxyCtx = new RpcProxyContext(proxyInstance.class) - val properties = new Hashtable() - rpcProxyCtx.proxy = proxyInstance as RpcService - - properties.salServiceType = SAL_SERVICE_TYPE_CONSUMER_PROXY - rpcProxyCtx.registration = brokerBundleContext.registerService(service, rpcProxyCtx.proxy as T, properties) - managedProxies.put(service, rpcProxyCtx) - return rpcProxyCtx.proxy - } - - /** - * Registers RPC Implementation - * - */ - def registerRpcImplementation(Class type, T service, OsgiProviderContext context, - Hashtable properties) { - val proxy = getManagedDirectProxy(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,this); - } - - def RoutedRpcRegistration registerRoutedRpcImplementation(Class type, T service, - OsgiProviderContext context) { - val router = resolveRpcRouter(type); - checkState(router !== null) - return new RoutedRpcRegistrationImpl(service, router, this) - } - - private def RpcRouter resolveRpcRouter(Class type) { - - val router = rpcRouters.get(type); - if (router !== null) { - return router as RpcRouter; - } - - // We created Router - val newRouter = generator.getRouterFor(type); - checkState(newRouter !== null); - rpcRouters.put(type, newRouter); - - // We create / update Direct Proxy for router - val proxy = getManagedDirectProxy(type); - proxy.delegate = newRouter.invocationProxy - return newRouter; - - } - - protected def void registerPath(RoutedRpcRegistrationImpl registration, - Class context, InstanceIdentifier path) { - - val router = registration.router; - val paths = registration.registeredPaths; - - val routingTable = router.getRoutingTable(context) - checkState(routingTable != null); - - // Updating internal structure of registration - routingTable.updateRoute(path, registration.instance) - // Update routing table / send announce to message bus - - val success = paths.put(context, path); - } - - protected def void unregisterPath(RoutedRpcRegistrationImpl registration, - Class context, InstanceIdentifier path) { - - val router = registration.router; - val paths = registration.registeredPaths; - - val routingTable = router.getRoutingTable(context) - checkState(routingTable != null); - - // Updating internal structure of registration - val target = routingTable.getRoute(path) - checkState(target === registration.instance) - routingTable.removeRoute(path) - checkState(paths.remove(context, path)); - } - - protected def void unregisterRoutedRpcService(RoutedRpcRegistrationImpl registration) { - - val router = registration.router; - val paths = registration.registeredPaths; - - for (ctxMap : registration.registeredPaths.entries) { - val context = ctxMap.key - val routingTable = router.getRoutingTable(context) - val path = ctxMap.value - routingTable.removeRoute(path) - } + override >> registerRouteChangeListener(L listener) { + super.registerRouteChangeListener(listener) } - protected def void unregisterRpcService(RpcServiceRegistrationImpl registration) { - - val type = registration.serviceType; + override close() throws Exception { - val proxy = managedProxies.get(type); - if(proxy.proxy.delegate === registration.instance) { - proxy.proxy.delegate = null; - } - } - - def createDelegate(Class type) { - getManagedDirectProxy(type); - } - - def getRpcRouters() { - return Collections.unmodifiableMap(rpcRouters); } - - override close() { - dataConsumerRegistration.unregister() - dataProviderRegistration.unregister() - notifyConsumerRegistration.unregister() - notifyProviderRegistration.unregister() - } - -} - -class RoutedRpcRegistrationImpl extends AbstractObjectRegistration implements RoutedRpcRegistration { - - @Property - private val BindingAwareBrokerImpl broker; - - @Property - private val RpcRouter router; - - @Property - private val Multimap, InstanceIdentifier> registeredPaths = HashMultimap.create(); - - private var closed = false; - - new(T instance, RpcRouter backingRouter, BindingAwareBrokerImpl broker) { - super(instance) - _router = backingRouter; - _broker = broker; - } - - override protected removeRegistration() { - closed = true - broker.unregisterRoutedRpcService(this) - } - - override registerInstance(Class context, InstanceIdentifier instance) { - registerPath(context, instance); - } - - override unregisterInstance(Class context, InstanceIdentifier instance) { - unregisterPath(context, instance); - } - - override registerPath(Class context, InstanceIdentifier path) { - checkClosed() - broker.registerPath(this, context, path); - } - - override unregisterPath(Class context, InstanceIdentifier path) { - checkClosed() - broker.unregisterPath(this, context, path); - } - - override getServiceType() { - return router.serviceType; - } - - private def checkClosed() { - if (closed) - throw new IllegalStateException("Registration was closed."); - } - -} -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; - } - -} +} \ No newline at end of file