X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2Fimpl%2FSchemaAwareRpcBroker.java;h=b4d7d2d00109b394f36c1ef138176da4fda364ab;hb=c74d5c2399e500fe3e690edc8cee497b1cb6f867;hp=7bc827dcb0329d41825638efa9b5d1748ac0c83c;hpb=d89bf60857d94ac982ea52e163a5e61a71b52330;p=controller.git 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 7bc827dcb0..b4d7d2d001 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 @@ -10,6 +10,13 @@ package org.opendaylight.controller.sal.dom.broker.impl; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; +import com.google.common.base.Preconditions; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -22,35 +29,33 @@ import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration; import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration; import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation; import org.opendaylight.controller.sal.core.api.RpcImplementation; +import org.opendaylight.controller.sal.core.api.RpcImplementationUnavailableException; import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; import org.opendaylight.controller.sal.core.api.RpcRoutingContext; import org.opendaylight.controller.sal.dom.broker.spi.RpcRouter; import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.concepts.util.ListenerRegistry; +import org.opendaylight.yangtools.util.ListenerRegistry; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.ListenableFuture; - +/** + * RPC broker responsible for routing requests to remote systems. + */ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, RoutedRpcDefaultImplementation { private static final Logger LOG = LoggerFactory.getLogger(SchemaAwareRpcBroker.class); private final ListenerRegistry rpcRegistrationListeners = new ListenerRegistry<>(); - private final ListenerRegistry> routeChangeListeners = new ListenerRegistry<>(); + private final ListenerRegistry> routeChangeListeners = new ListenerRegistry<>(); private final String identifier; @@ -216,19 +221,23 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro } @Override - public ListenableFuture> invokeRpc(final QName rpc, final InstanceIdentifier route, final CompositeNode input) { - checkState(defaultDelegate != null, "No implementation is available for rpc:%s path:%s", rpc, route); - return defaultDelegate.invokeRpc(rpc, route, input); + public ListenableFuture> invokeRpc(final QName rpc, final YangInstanceIdentifier route, final CompositeNode input) { + if (defaultDelegate == null) { + return Futures.immediateFailedCheckedFuture(new RpcImplementationUnavailableException("No RPC implementation found")); + } + + LOG.debug("Forwarding RPC {} path {} to delegate {}", rpc, route); + return defaultDelegate.invokeRpc(rpc, route, input); } void remove(final GlobalRpcRegistration registration) { implementations.remove(registration.getType(), registration); } - void notifyPathAnnouncement(final QName context, final QName identifier, final InstanceIdentifier path) { + void notifyPathAnnouncement(final QName context, final QName identifier, final YangInstanceIdentifier path) { RpcRoutingContext contextWrapped = RpcRoutingContext.create(context, identifier); - RouteChange change = RoutingUtils.announcementChange(contextWrapped , path); - for(ListenerRegistration> routeListener : routeChangeListeners) { + RouteChange change = RoutingUtils.announcementChange(contextWrapped , path); + for(ListenerRegistration> routeListener : routeChangeListeners) { try { routeListener.getInstance().onRouteChange(change); } catch (Exception e) { @@ -238,10 +247,10 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro } - void notifyPathWithdrawal(final QName context,final QName identifier, final InstanceIdentifier path) { + void notifyPathWithdrawal(final QName context,final QName identifier, final YangInstanceIdentifier path) { RpcRoutingContext contextWrapped = RpcRoutingContext.create(context, identifier); - RouteChange change = RoutingUtils.removalChange(contextWrapped , path); - for(ListenerRegistration> routeListener : routeChangeListeners) { + RouteChange change = RoutingUtils.removalChange(contextWrapped , path); + for(ListenerRegistration> routeListener : routeChangeListeners) { try { routeListener.getInstance().onRouteChange(change); } catch (Exception e) { @@ -251,10 +260,10 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro } @Override - public > ListenerRegistration registerRouteChangeListener( + public > ListenerRegistration registerRouteChangeListener( final L listener) { ListenerRegistration reg = routeChangeListeners.registerWithType(listener); - RouteChange initial = createInitialRouteChange(); + RouteChange initial = createInitialRouteChange(); try { listener.onRouteChange(initial); } catch (Exception e) { @@ -263,15 +272,15 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable, Ro return reg; } - private RouteChange createInitialRouteChange() { + private RouteChange createInitialRouteChange() { FluentIterable rpcSelectors = FluentIterable.from(implementations.values()).filter(RoutedRpcSelector.class); - ImmutableMap.Builder> announcements = ImmutableMap.builder(); - ImmutableMap.Builder> removals = ImmutableMap.builder(); + ImmutableMap.Builder> announcements = ImmutableMap.builder(); + ImmutableMap.Builder> removals = ImmutableMap.builder(); for (RoutedRpcSelector routedRpcSelector : rpcSelectors) { final RpcRoutingContext context = routedRpcSelector.getIdentifier(); - final Set paths = ImmutableSet.copyOf(routedRpcSelector.implementations.keySet()); + final Set paths = ImmutableSet.copyOf(routedRpcSelector.implementations.keySet()); announcements.put(context, paths); } return RoutingUtils.change(announcements.build(), removals.build());