From: msunal Date: Tue, 22 Oct 2013 07:43:28 +0000 (+0200) Subject: Proper unregistration of provider's session X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~593 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=80b7e666e6c057608018b33c3c31ad3e3f7e6035 Proper unregistration of provider's session - if provider's session is closed, all RPCs from broker are removed Change-Id: Ie59c19868b340588c2b7114830493986d1be3b6b Signed-off-by: Martin Sunal --- diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend index 6b57cdc4db..bdd4491d01 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend @@ -7,25 +7,26 @@ */ package org.opendaylight.controller.sal.dom.broker; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.Consumer; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.spi.BrokerModule; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.osgi.framework.BundleContext; -import org.slf4j.LoggerFactory; +import java.util.Collections +import java.util.HashMap +import java.util.HashSet +import java.util.Map +import java.util.Set +import java.util.concurrent.Callable +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors +import java.util.concurrent.Future +import org.opendaylight.controller.sal.core.api.Broker +import org.opendaylight.controller.sal.core.api.BrokerService +import org.opendaylight.controller.sal.core.api.Consumer +import org.opendaylight.controller.sal.core.api.Provider +import org.opendaylight.controller.sal.core.api.RpcImplementation +import org.opendaylight.controller.sal.core.spi.BrokerModule +import org.opendaylight.yangtools.yang.common.QName +import org.opendaylight.yangtools.yang.common.RpcResult +import org.opendaylight.yangtools.yang.data.api.CompositeNode +import org.osgi.framework.BundleContext +import org.slf4j.LoggerFactory public class BrokerImpl implements Broker { private static val log = LoggerFactory.getLogger(BrokerImpl); @@ -44,7 +45,7 @@ public class BrokerImpl implements Broker { // Implementation specific @Property - private var ExecutorService executor; + private var ExecutorService executor = Executors.newFixedThreadPool(5); @Property private var BundleContext bundleContext; @@ -99,10 +100,8 @@ public class BrokerImpl implements Broker { rpcImpls.put(rpcType, implementation); } - protected def void removeRpcImplementation(QName rpcType, RpcImplementation implToRemove) { - if(implToRemove == rpcImpls.get(rpcType)) { - rpcImpls.remove(rpcType); - } + protected def void removeRpcImplementation(QName rpcType) { + rpcImpls.remove(rpcType); } protected def Future> invokeRpc(QName rpc, CompositeNode input) { diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend index 11f68d6e04..27e559cb9b 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/ProviderContextImpl.xtend @@ -1,13 +1,14 @@ package org.opendaylight.controller.sal.dom.broker +import java.util.Collections +import java.util.HashMap import org.opendaylight.controller.sal.core.api.Broker.ProviderSession import org.opendaylight.controller.sal.core.api.Provider -import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.controller.sal.core.api.RpcImplementation +import org.opendaylight.yangtools.yang.common.QName import org.osgi.framework.BundleContext -import static java.util.Collections.* -import java.util.Collections -import java.util.HashMap +import org.opendaylight.yangtools.concepts.AbstractObjectRegistration +import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession { @@ -30,19 +31,32 @@ class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession } broker.addRpcImplementation(rpcType, implementation); rpcImpls.put(rpcType, implementation); - //FIXME: Return registration - return null; + + return new RpcRegistrationImpl(rpcType, implementation, this); } - def removeRpcImplementation(QName rpcType, RpcImplementation implToRemove) throws IllegalArgumentException { - val localImpl = rpcImpls.get(rpcType); - if(localImpl != implToRemove) { + def removeRpcImplementation(RpcRegistrationImpl implToRemove) throws IllegalArgumentException { + val localImpl = rpcImpls.get(implToRemove.type); + if(localImpl !== implToRemove.instance) { throw new IllegalStateException( "Implementation was not registered in this session"); } - - broker.removeRpcImplementation(rpcType, implToRemove); - rpcImpls.remove(rpcType); + broker.removeRpcImplementation(implToRemove.type); + rpcImpls.remove(implToRemove.type); + } + + override close() { + removeAllRpcImlementations + super.close + } + + private def removeAllRpcImlementations() { + if (!rpcImpls.empty) { + for (entry : rpcImpls.entrySet) { + broker.removeRpcImplementation(entry.key); + } + rpcImpls.clear + } } override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) { @@ -54,3 +68,23 @@ class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession } } + +class RpcRegistrationImpl extends AbstractObjectRegistration implements RpcRegistration { + + @Property + val QName type + + private var ProviderContextImpl context + + new(QName type, RpcImplementation instance, ProviderContextImpl ctx) { + super(instance) + _type = type + context = ctx + } + + override protected removeRegistration() { + context.removeRpcImplementation(this) + context = null + } + +} \ No newline at end of file