1 package org.opendaylight.controller.sal.dom.broker.impl
3 import org.opendaylight.controller.sal.dom.broker.spi.RpcRouter
4 import org.opendaylight.yangtools.concepts.Identifiable
5 import org.opendaylight.yangtools.yang.common.QName
6 import org.opendaylight.controller.sal.core.api.RpcImplementation
7 import org.opendaylight.yangtools.yang.data.api.CompositeNode
8 import static com.google.common.base.Preconditions.*;
10 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration
11 import java.util.concurrent.ConcurrentHashMap
13 import java.util.Collections
14 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration
15 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener
16 import org.slf4j.LoggerFactory
17 import org.opendaylight.yangtools.concepts.util.ListenerRegistry
18 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration
19 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
21 class RpcRouterImpl implements RpcRouter, Identifiable<String> {
23 static val log = LoggerFactory.getLogger(RpcRouterImpl)
25 Map<QName, RpcRegistration> implementations = new ConcurrentHashMap();
28 val Set<QName> supportedRpcs = Collections.unmodifiableSet(implementations.keySet);
30 private val rpcRegistrationListeners = new ListenerRegistry<RpcRegistrationListener>();
33 val String identifier;
39 override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
40 checkNotNull(rpcType, "Rpc Type should not be null");
41 checkNotNull(implementation, "Implementation should not be null.");
42 val reg = new RoutedRpcRegistrationImpl(rpcType, implementation, this);
43 implementations.put(rpcType, reg)
45 for (listener : rpcRegistrationListeners.listeners) {
47 listener.instance.onRpcImplementationAdded(rpcType);
48 } catch (Exception e) {
49 log.error("Unhandled exception during invoking listener", e);
56 override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
57 checkNotNull(rpcType, "Rpc Type should not be null");
58 checkNotNull(implementation, "Implementation should not be null.");
59 checkState(!implementations.containsKey(rpcType), "Provider for supplied rpc is already registered.");
60 val reg = new RpcRegistrationImpl(rpcType, implementation, this);
61 implementations.put(rpcType, reg)
63 for (listener : rpcRegistrationListeners.listeners) {
65 listener.instance.onRpcImplementationAdded(rpcType);
66 } catch (Exception e) {
67 log.error("Unhandled exception during invoking listener", e);
75 override invokeRpc(QName rpc, CompositeNode input) {
76 checkNotNull(rpc, "Rpc Type should not be null");
78 val impl = implementations.get(rpc);
79 checkState(impl !== null, "Provider for supplied rpc is not registered.");
81 return impl.instance.invokeRpc(rpc, input);
84 def remove(RpcRegistrationImpl impl) {
85 val existing = implementations.get(impl.type);
86 if (existing == impl) {
87 implementations.remove(impl.type);
89 for (listener : rpcRegistrationListeners.listeners) {
91 listener.instance.onRpcImplementationRemoved(impl.type);
92 } catch (Exception e) {
93 log.error("Unhandled exception during invoking listener", e);
98 override addRpcRegistrationListener(RpcRegistrationListener listener) {
99 rpcRegistrationListeners.register(listener);
104 class RpcRegistrationImpl extends AbstractObjectRegistration<RpcImplementation> implements RpcRegistration {
110 var RpcRouterImpl router;
112 new(QName type, RpcImplementation instance, RpcRouterImpl router) {
118 override protected removeRegistration() {
122 class RoutedRpcRegistrationImpl extends RpcRegistrationImpl implements RoutedRpcRegistration {
125 new(QName type, RpcImplementation instance, RpcRouterImpl router) {
126 super(type,instance,router)
129 override protected removeRegistration() {
132 override registerPath(QName context, InstanceIdentifier path) {
137 override unregisterPath(QName context, InstanceIdentifier path) {