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 {
30 if (rpcType == null) {
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("Implementation was not registered in this session");
47 broker.removeRpcImplementation(implToRemove.type, localImpl);
48 rpcImpls.remove(implToRemove.type);
52 removeAllRpcImlementations
56 private def removeAllRpcImlementations() {
57 if (!rpcImpls.empty) {
58 for (entry : rpcImpls.entrySet) {
59 broker.removeRpcImplementation(entry.key, entry.value);
65 override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) {
66 throw new UnsupportedOperationException("TODO: auto-generated method stub")
69 override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
70 throw new UnsupportedOperationException("TODO: auto-generated method stub")
73 override getSupportedRpcs() {
74 broker.getSupportedRpcs();
77 override addRpcRegistrationListener(RpcRegistrationListener listener) {
78 broker.addRpcRegistrationListener(listener);
82 class RpcRegistrationImpl extends AbstractObjectRegistration<RpcImplementation> implements RpcRegistration {
87 private var ProviderContextImpl context
89 new(QName type, RpcImplementation instance, ProviderContextImpl ctx) {
95 override protected removeRegistration() {
96 context.removeRpcImplementation(this)