X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2Fimpl%2FSchemaAwareRpcBroker.java;h=32139308b11230b806467f95d078c1608077a1f6;hp=3e7b115f11e28667114c798062bd4737cda9f333;hb=a9533db1d57a2729772ee192a2f96d358c71bede;hpb=3ab0ebe1df3e7606cce0a61572f79bf12deb17c0 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareRpcBroker.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareRpcBroker.java index 3e7b115f11..32139308b1 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareRpcBroker.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareRpcBroker.java @@ -14,6 +14,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import com.google.common.base.Preconditions; import org.opendaylight.controller.md.sal.common.api.routing.RouteChange; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; import org.opendaylight.controller.md.sal.common.impl.routing.RoutingUtils; @@ -140,17 +141,34 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro RpcDefinition definition = findRpcDefinition(rpcType); checkArgument(!isRoutedRpc(definition), "RPC Type must not be routed."); GlobalRpcRegistration reg = new GlobalRpcRegistration(rpcType, implementation, this); - implementations.putIfAbsent(rpcType, implementation); + final RpcImplementation previous = implementations.putIfAbsent(rpcType, implementation); + Preconditions.checkState(previous == null, "Rpc %s is already registered.",rpcType); + notifyRpcAdded(rpcType); return reg; } + private void notifyRpcAdded(QName rpcType) { + for (ListenerRegistration listener : rpcRegistrationListeners) { + try { + listener.getInstance().onRpcImplementationAdded(rpcType); + } catch (Exception ex) { + LOG.error("Unhandled exception during invoking listener {}", listener.getInstance(), ex); + } + + } + } + private boolean isRoutedRpc(RpcDefinition definition) { return getRoutingStrategy(definition) instanceof RoutedRpcStrategy; } @Override public ListenerRegistration addRpcRegistrationListener(RpcRegistrationListener listener) { - return rpcRegistrationListeners.register(listener); + ListenerRegistration reg = rpcRegistrationListeners.register(listener); + for (QName impl : implementations.keySet()) { + listener.onRpcImplementationAdded(impl); + } + return reg; } @Override @@ -174,8 +192,12 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro if (potentialImpl != null) { return potentialImpl; } + potentialImpl = defaultImplementation; - checkState(potentialImpl != null, "Implementation is not available."); + if( potentialImpl == null ) { + throw new UnsupportedOperationException( "No implementation for this operation is available." ); + } + return potentialImpl; } @@ -225,7 +247,6 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro if (CONTEXT_REFERENCE.equals(extension.getNodeType())) { return Optional.fromNullable(extension.getQName()); } - ; } return Optional.absent(); } @@ -326,7 +347,8 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro SimpleNode routeContainer = inputContainer.getFirstSimpleByName(strategy.getLeaf()); checkArgument(routeContainer != null, "Leaf %s must be set with value", strategy.getLeaf()); Object route = routeContainer.getValue(); - checkArgument(route instanceof InstanceIdentifier); + checkArgument(route instanceof InstanceIdentifier, + "The routed node %s is not an instance identifier", route); RpcImplementation potential = null; if (route != null) { RoutedRpcRegImpl potentialReg = implementations.get(route); @@ -457,7 +479,7 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro try { listener.onRouteChange(initial); } catch (Exception e) { - LOG.error("Unhandled exception during sending initial route change event {} to {}",initial,listener); + LOG.error("Unhandled exception during sending initial route change event {} to {}",initial,listener, e); } return reg; }