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=e641ed10397ef215d182f78d465853c37ebf2ff4;hb=0840e8281ad7e43b3c1c792c80d44b671a946f7a;hp=8e402e2f36ca8fe6b265dcfe6ae434f17ef6646d;hpb=4b1c94354c0396645effe64388bbefb653e29344;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 8e402e2f36..e641ed1039 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,20 +1,30 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.dom.broker 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.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); @@ -22,25 +32,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); + val origReg = broker.router.addRpcImplementation(rpcType, implementation); + val newReg = new RpcRegistrationWrapper(origReg); + registrations.add(newReg); + return newReg; } - override removeRpcImplementation(QName rpcType, RpcImplementation implToRemove) throws IllegalArgumentException { - val localImpl = rpcImpls.get(rpcType); - if(localImpl != implToRemove) { - throw new IllegalStateException( - "Implementation was not registered in this session"); + protected def removeRpcImplementation(RpcRegistrationWrapper implToRemove) throws IllegalArgumentException { + registrations.remove(implToRemove); + } + + override close() { + + 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; + } - broker.removeRpcImplementation(rpcType, implToRemove); - rpcImpls.remove(rpcType); + 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 + } } +