X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2FProviderContextImpl.xtend;h=3fdd7065770dac618a2fa5cc15ebeb1c37cb110a;hp=8e402e2f36ca8fe6b265dcfe6ae434f17ef6646d;hb=9f6f0ac9246e8161a7d35275042a255398c68eca;hpb=4b1c94354c0396645effe64388bbefb653e29344 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 8e402e2f36..3fdd706577 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,18 @@ 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 org.opendaylight.yangtools.concepts.AbstractObjectRegistration +import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration import static java.util.Collections.* import java.util.Collections import java.util.HashMap +import org.opendaylight.controller.sal.core.api.RpcRegistrationListener class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession { @@ -30,17 +35,67 @@ class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession } broker.addRpcImplementation(rpcType, implementation); rpcImpls.put(rpcType, implementation); + + return new RpcRegistrationImpl(rpcType, implementation, this); } - override 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,localImpl); + rpcImpls.remove(implToRemove.type); + } + + override close() { + removeAllRpcImlementations + super.close + } + + private def removeAllRpcImlementations() { + if (!rpcImpls.empty) { + for (entry : rpcImpls.entrySet) { + broker.removeRpcImplementation(entry.key,entry.value); + } + rpcImpls.clear + } } + + override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) { + throw new UnsupportedOperationException("TODO: auto-generated method stub") + } + + override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) { + throw new UnsupportedOperationException("TODO: auto-generated method stub") + } + + override getSupportedRpcs() { + broker.getSupportedRpcs(); + } + + override addRpcRegistrationListener(RpcRegistrationListener listener) { + broker.addRpcRegistrationListener(listener); + } +} + +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 + } }