1 package org.opendaylight.controller.sal.dom.broker
3 import java.util.Collections
4 import java.util.HashMap
5 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession
6 import org.opendaylight.controller.sal.core.api.Provider
7 import org.opendaylight.controller.sal.core.api.RpcImplementation
8 import org.opendaylight.yangtools.yang.common.QName
9 import org.osgi.framework.BundleContext
10 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration
11 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration
13 class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession {
16 private val Provider provider;
18 private val rpcImpls = Collections.synchronizedMap(new HashMap<QName, RpcImplementation>());
20 new(Provider provider, BundleContext ctx) {
22 this._provider = provider;
25 override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
27 throw new IllegalArgumentException("rpcType must not be null");
29 if(implementation == null) {
30 throw new IllegalArgumentException("Implementation must not be null");
32 broker.addRpcImplementation(rpcType, implementation);
33 rpcImpls.put(rpcType, implementation);
35 return new RpcRegistrationImpl(rpcType, implementation, this);
38 def removeRpcImplementation(RpcRegistrationImpl implToRemove) throws IllegalArgumentException {
39 val localImpl = rpcImpls.get(implToRemove.type);
40 if(localImpl !== implToRemove.instance) {
41 throw new IllegalStateException(
42 "Implementation was not registered in this session");
44 broker.removeRpcImplementation(implToRemove.type);
45 rpcImpls.remove(implToRemove.type);
49 removeAllRpcImlementations
53 private def removeAllRpcImlementations() {
54 if (!rpcImpls.empty) {
55 for (entry : rpcImpls.entrySet) {
56 broker.removeRpcImplementation(entry.key);
62 override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) {
63 throw new UnsupportedOperationException("TODO: auto-generated method stub")
66 override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
67 throw new UnsupportedOperationException("TODO: auto-generated method stub")
72 class RpcRegistrationImpl extends AbstractObjectRegistration<RpcImplementation> implements RpcRegistration {
77 private var ProviderContextImpl context
79 new(QName type, RpcImplementation instance, ProviderContextImpl ctx) {
85 override protected removeRegistration() {
86 context.removeRpcImplementation(this)