X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2FProviderContextImpl.xtend;h=cf5d220943142ad83c948299aeef3222d882b136;hb=6668a20ff21282576d2d408d9b1ce4cf9ba0c9ac;hp=27e559cb9b5011161a25050287555d8ee0c6165c;hpb=80b7e666e6c057608018b33c3c31ad3e3f7e6035;p=controller.git 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 27e559cb9b..cf5d220943 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,21 +1,23 @@ 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.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 org.opendaylight.controller.sal.core.api.RpcRegistrationListener +import org.opendaylight.yangtools.concepts.Registration + +import java.util.Set +import java.util.HashSet class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession { @Property private val Provider provider; - private val rpcImpls = Collections.synchronizedMap(new HashMap()); + private val Set> registrations = new HashSet(); new(Provider provider, BundleContext ctx) { super(null, ctx); @@ -23,68 +25,61 @@ class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession } override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException { - if(rpcType == null) { - throw new IllegalArgumentException("rpcType must not be null"); - } - if(implementation == null) { - throw new IllegalArgumentException("Implementation must not be null"); - } - broker.addRpcImplementation(rpcType, implementation); - rpcImpls.put(rpcType, implementation); - - return new RpcRegistrationImpl(rpcType, implementation, this); + val origReg = broker.router.addRpcImplementation(rpcType, implementation); + val newReg = new RpcRegistrationWrapper(origReg); + registrations.add(newReg); + return newReg; } - 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(implToRemove.type); - rpcImpls.remove(implToRemove.type); + protected def removeRpcImplementation(RpcRegistrationWrapper implToRemove) throws IllegalArgumentException { + registrations.remove(implToRemove); } override close() { - removeAllRpcImlementations - super.close - } - - private def removeAllRpcImlementations() { - if (!rpcImpls.empty) { - for (entry : rpcImpls.entrySet) { - broker.removeRpcImplementation(entry.key); - } - rpcImpls.clear - } + + for (reg : registrations) { + reg.close() + } + super.close } - + 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.router.supportedRpcs; + } + + override addRpcRegistrationListener(RpcRegistrationListener listener) { + broker.router.addRpcRegistrationListener(listener); + } +} + +class RpcRegistrationWrapper implements RpcRegistration { + + + @Property + val RpcRegistration delegate + + new(RpcRegistration delegate) { + _delegate = delegate + } + + override getInstance() { + delegate.instance + } + + override close() { + delegate.close + } + + override getType() { + delegate.type + } } -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