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=d69aeed3523a660177774826a25be1db2f2974c7;hp=052fd2169a523b955a427f036e2a0ab6b7a03bc4;hb=eee7641cc93aa82b9769c6e8799163ef102ace35;hpb=4f8e371e1b7f6a2aa31115407c3f37738030f4c5 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 052fd2169a..d69aeed352 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 @@ -8,11 +8,14 @@ package org.opendaylight.controller.sal.binding.codegen.impl; import static org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.setRoutingTable; - +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; - +import javax.annotation.concurrent.GuardedBy; 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; @@ -22,23 +25,18 @@ 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.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; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - public class RpcRouterCodegenInstance implements // RpcRouter, RouteChangeListener, InstanceIdentifier> { private static final Logger LOG = LoggerFactory.getLogger(RpcRouterCodegenInstance.class); - private T defaultService; - private final Class serviceType; private final T invocationProxy; @@ -49,11 +47,8 @@ RpcRouter, RouteChangeListener, InstanceIdentif private final Map, RpcRoutingTableImpl> routingTables; - private final String name; - @SuppressWarnings("unchecked") public RpcRouterCodegenInstance(final String name,final Class type, final T routerImpl, final Iterable> contexts) { - this.name = name; this.listeners = ListenerRegistry.create(); this.serviceType = type; this.invocationProxy = routerImpl; @@ -90,7 +85,7 @@ RpcRouter, RouteChangeListener, InstanceIdentif @Override public T getDefaultService() { - return defaultService; + return RuntimeCodeHelper.getDelegate(invocationProxy); } @Override @@ -125,14 +120,27 @@ RpcRouter, RouteChangeListener, InstanceIdentif 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(final T service) { - // TODO Auto-generated method stub RuntimeCodeHelper.setDelegate(invocationProxy, service); - return null; + return new DefaultRpcImplementationRegistration(service); } - private class RoutedRpcRegistrationImpl extends AbstractObjectRegistration implements RoutedRpcRegistration { + private final class RoutedRpcRegistrationImpl extends AbstractObjectRegistration implements RoutedRpcRegistration { + /* + * FIXME: retaining this collection is not completely efficient. We really should be storing + * a reference to this registration, as a particular listener may be registered multiple + * times -- and then this goes kaboom in various aspects. + */ + @GuardedBy("this") + private final Collection> contexts = new ArrayList<>(1); public RoutedRpcRegistrationImpl(final T instance) { super(instance); @@ -144,28 +152,65 @@ RpcRouter, RouteChangeListener, InstanceIdentif } @Override - public void registerPath(final Class context, final InstanceIdentifier path) { + public synchronized void registerPath(final Class context, final InstanceIdentifier path) { + if (isClosed()) { + LOG.debug("Closed registration of {} ignoring new path {}", getInstance(), path); + return; + } + routingTables.get(context).updateRoute(path, getInstance()); + contexts.add(context); } @Override - public void unregisterPath(final Class context, final InstanceIdentifier path) { + public synchronized void unregisterPath(final Class context, final InstanceIdentifier path) { + if (isClosed()) { + LOG.debug("Closed unregistration of {} ignoring new path {}", getInstance(), path); + return; + } + routingTables.get(context).removeRoute(path, getInstance()); + contexts.remove(context); } + @Deprecated @Override public void registerInstance(final Class context, final InstanceIdentifier instance) { registerPath(context, instance); } + @Deprecated @Override public void unregisterInstance(final Class context, final InstanceIdentifier instance) { unregisterPath(context, instance); } + @Override + protected synchronized void removeRegistration() { + for (Class ctx : contexts) { + routingTables.get(ctx).removeAllReferences(getInstance()); + } + contexts.clear(); + } + } + + private final 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; } } + + }