X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fcodegen%2Fimpl%2FRpcRouterCodegenInstance.java;h=709b62fee25247c09ec980c188acd504693d4e3e;hp=4f994e5673a2c80896d8c5168af4d0c299ee7bcf;hb=f8225a74b7c11db1ebf77ab9de998c2e953f8ed8;hpb=335aee8c6154a25c76503223e636398d32135bc9 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java index 4f994e5673..709b62fee2 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java @@ -7,29 +7,25 @@ */ package org.opendaylight.controller.sal.binding.codegen.impl; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter; -import org.opendaylight.controller.sal.binding.api.rpc.RpcRoutingTable; -import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper; -import org.opendaylight.yangtools.yang.binding.BaseIdentity; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import static org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.*; +import static org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.setRoutingTable; +import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.HashMap; -import org.opendaylight.yangtools.yang.binding.DataContainer; -import org.opendaylight.yangtools.yang.binding.RpcImplementation; -import org.opendaylight.controller.md.sal.common.api.routing.MutableRoutingTable; import org.opendaylight.controller.md.sal.common.api.routing.RouteChange; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter; +import org.opendaylight.controller.sal.binding.api.rpc.RpcRoutingTable; +import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper; import org.opendaylight.yangtools.concepts.AbstractObjectRegistration; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.util.ListenerRegistry; +import org.opendaylight.yangtools.yang.binding.BaseIdentity; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.RpcService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,12 +33,10 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; public class RpcRouterCodegenInstance implements // - RpcRouter, RouteChangeListener, InstanceIdentifier> { +RpcRouter, RouteChangeListener, InstanceIdentifier> { private static final Logger LOG = LoggerFactory.getLogger(RpcRouterCodegenInstance.class); - private T defaultService; - private final Class serviceType; private final T invocationProxy; @@ -53,12 +47,8 @@ public class RpcRouterCodegenInstance implements // private final Map, RpcRoutingTableImpl> routingTables; - private final String name; - @SuppressWarnings("unchecked") - public RpcRouterCodegenInstance(String name,Class type, T routerImpl, Set> contexts, - Set> inputs) { - this.name = name; + public RpcRouterCodegenInstance(final String name,final Class type, final T routerImpl, final Iterable> contexts) { this.listeners = ListenerRegistry.create(); this.serviceType = type; this.invocationProxy = routerImpl; @@ -66,11 +56,11 @@ public class RpcRouterCodegenInstance implements // Map, RpcRoutingTableImpl> mutableRoutingTables = new HashMap<>(); for (Class ctx : contexts) { RpcRoutingTableImpl table = new RpcRoutingTableImpl<>(name,ctx,type); - + @SuppressWarnings("rawtypes") Map invokerView = table.getRoutes(); - - setRoutingTable((RpcService) invocationProxy, ctx, invokerView); + + setRoutingTable(invocationProxy, ctx, invokerView); mutableRoutingTables.put(ctx, table); table.registerRouteChangeListener(this); } @@ -89,13 +79,13 @@ public class RpcRouterCodegenInstance implements // @Override @SuppressWarnings("unchecked") - public RpcRoutingTable getRoutingTable(Class routeContext) { + public RpcRoutingTable getRoutingTable(final Class routeContext) { return (RpcRoutingTable) routingTables.get(routeContext); } @Override public T getDefaultService() { - return defaultService; + return RuntimeCodeHelper.getDelegate(invocationProxy); } @Override @@ -105,12 +95,12 @@ public class RpcRouterCodegenInstance implements // @Override public , InstanceIdentifier>> ListenerRegistration registerRouteChangeListener( - L listener) { + final L listener) { return listeners.registerWithType(listener); } @Override - public void onRouteChange(RouteChange, InstanceIdentifier> change) { + public void onRouteChange(final RouteChange, InstanceIdentifier> change) { for (ListenerRegistration, InstanceIdentifier>> listener : listeners) { try { listener.getInstance().onRouteChange(change); @@ -121,25 +111,31 @@ public class RpcRouterCodegenInstance implements // } @Override - public T getService(Class context, InstanceIdentifier path) { + public T getService(final Class context, final InstanceIdentifier path) { return routingTables.get(context).getRoute(path); } @Override - public RoutedRpcRegistration addRoutedRpcImplementation(T service) { + public RoutedRpcRegistration addRoutedRpcImplementation(final T service) { return new RoutedRpcRegistrationImpl(service); } + public void removeDefaultImplementation(final T instance) { + RpcService current = RuntimeCodeHelper.getDelegate(invocationProxy); + if(instance == current) { + RuntimeCodeHelper.setDelegate(invocationProxy, null); + } + } + @Override - public RpcRegistration registerDefaultService(T service) { - // TODO Auto-generated method stub + public RpcRegistration registerDefaultService(final T service) { RuntimeCodeHelper.setDelegate(invocationProxy, service); - return null; + return new DefaultRpcImplementationRegistration(service); } private class RoutedRpcRegistrationImpl extends AbstractObjectRegistration implements RoutedRpcRegistration { - public RoutedRpcRegistrationImpl(T instance) { + public RoutedRpcRegistrationImpl(final T instance) { super(instance); } @@ -149,22 +145,22 @@ public class RpcRouterCodegenInstance implements // } @Override - public void registerPath(Class context, InstanceIdentifier path) { + public void registerPath(final Class context, final InstanceIdentifier path) { routingTables.get(context).updateRoute(path, getInstance()); } @Override - public void unregisterPath(Class context, InstanceIdentifier path) { + public void unregisterPath(final Class context, final InstanceIdentifier path) { routingTables.get(context).removeRoute(path, getInstance()); } @Override - public void registerInstance(Class context, InstanceIdentifier instance) { + public void registerInstance(final Class context, final InstanceIdentifier instance) { registerPath(context, instance); } @Override - public void unregisterInstance(Class context, InstanceIdentifier instance) { + public void unregisterInstance(final Class context, final InstanceIdentifier instance) { unregisterPath(context, instance); } @@ -173,4 +169,24 @@ public class RpcRouterCodegenInstance implements // } } + + private class DefaultRpcImplementationRegistration extends AbstractObjectRegistration implements RpcRegistration { + + + protected DefaultRpcImplementationRegistration(final T instance) { + super(instance); + } + + @Override + protected void removeRegistration() { + removeDefaultImplementation(this.getInstance()); + } + + @Override + public Class getServiceType() { + return serviceType; + } + } + + }