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
12 import static java.util.Collections.*
13 import java.util.Collections
14 import java.util.HashMap
15 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener
17 class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession {
20 private val Provider provider;
22 private val rpcImpls = Collections.synchronizedMap(new HashMap<QName, RpcImplementation>());
24 new(Provider provider, BundleContext ctx) {
26 this._provider = provider;
29 override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
31 throw new IllegalArgumentException("rpcType must not be null");
33 if(implementation == null) {
34 throw new IllegalArgumentException("Implementation must not be null");
36 broker.addRpcImplementation(rpcType, implementation);
37 rpcImpls.put(rpcType, implementation);
39 return new RpcRegistrationImpl(rpcType, implementation, this);
42 def removeRpcImplementation(RpcRegistrationImpl implToRemove) throws IllegalArgumentException {
43 val localImpl = rpcImpls.get(implToRemove.type);
44 if(localImpl !== implToRemove.instance) {
45 throw new IllegalStateException(
46 "Implementation was not registered in this session");
48 broker.removeRpcImplementation(implToRemove.type,localImpl);
49 rpcImpls.remove(implToRemove.type);
53 removeAllRpcImlementations
57 private def removeAllRpcImlementations() {
58 if (!rpcImpls.empty) {
59 for (entry : rpcImpls.entrySet) {
60 broker.removeRpcImplementation(entry.key,entry.value);
66 override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) {
67 throw new UnsupportedOperationException("TODO: auto-generated method stub")
70 override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
71 throw new UnsupportedOperationException("TODO: auto-generated method stub")
74 override getSupportedRpcs() {
75 broker.getSupportedRpcs();
78 override addRpcRegistrationListener(RpcRegistrationListener listener) {
79 broker.addRpcRegistrationListener(listener);
83 class RpcRegistrationImpl extends AbstractObjectRegistration<RpcImplementation> implements RpcRegistration {
88 private var ProviderContextImpl context
90 new(QName type, RpcImplementation instance, ProviderContextImpl ctx) {
96 override protected removeRegistration() {
97 context.removeRpcImplementation(this)