Merge "Simplify hasNodeConnector method in Subnet class. Reduce 'if' conditions for...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / BindingAwareBrokerImpl.xtend
index 2bae9f515f40bfe4ed25e95ccd4426493c413a22..8d3545fbbb169f7faafd40330660dc5b109342ef 100644 (file)
@@ -13,7 +13,6 @@ 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
@@ -33,41 +32,48 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcR
 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
-
-class BindingAwareBrokerImpl implements BindingAwareBroker {
+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 java.util.concurrent.locks.ReentrantLock
+import java.util.concurrent.Callable
+import java.util.WeakHashMap
+import javax.annotation.concurrent.GuardedBy
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry
+import org.opendaylight.yangtools.concepts.ListenerRegistration
+import org.opendaylight.yangtools.concepts.util.ListenerRegistry
+
+class BindingAwareBrokerImpl extends RpcProviderRegistryImpl implements BindingAwareBroker, AutoCloseable {
     private static val log = LoggerFactory.getLogger(BindingAwareBrokerImpl)
 
-    private val clsPool = ClassPool.getDefault()
-    private var RuntimeCodeGenerator generator;
-    private Map<Class<? extends RpcService>, RpcProxyContext> managedProxies = new HashMap();
-    private var NotificationBrokerImpl notifyBroker
-    private var DataBrokerImpl dataBroker
-    private var ServiceRegistration<NotificationProviderService> notifyBrokerRegistration
+    private InstanceIdentifier<? extends DataObject> root = InstanceIdentifier.builder().toInstance();
+
+    @Property
+    private var NotificationProviderService notifyBroker
+
+    @Property
+    private var DataProviderService dataBroker
 
     @Property
     var BundleContext brokerBundleContext
 
+    public new(BundleContext bundleContext) {
+        _brokerBundleContext = bundleContext;
+    }
+
     def start() {
-        initGenerator();
-
-        // Initialization of notificationBroker
-        notifyBroker = new NotificationBrokerImpl(null);
-        dataBroker = new DataBrokerImpl();
-        val brokerProperties = newProperties();
-        notifyBrokerRegistration = brokerBundleContext.registerService(NotificationProviderService, notifyBroker,
-            brokerProperties)
-        brokerBundleContext.registerService(NotificationService, notifyBroker, brokerProperties)
-        brokerBundleContext.registerService(DataProviderService,dataBroker,brokerProperties)
-        brokerBundleContext.registerService(DataBrokerService,dataBroker,brokerProperties)
-        
+        log.info("Starting MD-SAL: Binding Aware Broker");
     }
 
-    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)
@@ -89,58 +95,9 @@ class BindingAwareBrokerImpl implements BindingAwareBroker {
     private def createContext(BindingAwareProvider provider, BundleContext providerCtx) {
         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.
-     */
-    def <T extends RpcService> getManagedDirectProxy(Class<T> service) {
-
-        var RpcProxyContext existing = null
-        if((existing = managedProxies.get(service)) != null) {
-            return existing.proxy
-        }
-        val proxyClass = generator.generateDirectProxy(service)
-        val rpcProxyCtx = new RpcProxyContext(proxyClass)
-        val properties = new Hashtable<String, String>()
-        rpcProxyCtx.proxy = proxyClass.newInstance 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 <T extends RpcService> registerRpcImplementation(Class<T> type, T service, OsgiProviderContext context,
-        Hashtable<String, String> properties) {
-        val proxy = getManagedDirectProxy(type)
-        if(proxy.delegate != null) {
-            throw new IllegalStateException("Service " + type + "is already registered");
-        }
-        val osgiReg = context.bundleContext.registerService(type, service, properties);
-        proxy.delegate = service;
-        return new RpcServiceRegistrationImpl<T>(type, service, osgiReg);
-    }
-
-    def <T extends RpcService> RpcRegistration<T> registerMountedRpcImplementation(Class<T> tyoe, T service, InstanceIdentifier<?> identifier,
-        OsgiProviderContext context, Hashtable<String, String> properties) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    def <T extends RpcService> RoutedRpcRegistration<T> registerRoutedRpcImplementation(Class<T> type, T service, OsgiProviderContext context,
-        Hashtable<String, String> properties) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
+    
+    override close() throws Exception {
+        
     }
 
-}
+}
\ No newline at end of file