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%2FRpcRoutingTableImpl.java;h=78fa88bb1b24d0c55e966afaaab085b04560ba10;hp=808358fb3503c1ea38bca66951137c1353c7b64d;hb=159881b2b1c44301f740a6d20199df58eea04851;hpb=454f93d530edea269105cebd0020d0bf1aa75c79 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java index 808358fb35..78fa88bb1b 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java @@ -1,28 +1,31 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.binding.codegen.impl; -import org.opendaylight.controller.sal.binding.spi.RpcRoutingTable; -import org.opendaylight.yangtools.yang.binding.BaseIdentity; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - import java.util.Collections; +import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; - -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.controller.md.sal.common.api.routing.RouteChangePublisher; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; +import org.opendaylight.controller.md.sal.common.api.routing.RouteChangePublisher; import org.opendaylight.controller.md.sal.common.impl.routing.RoutingUtils; +import org.opendaylight.controller.sal.binding.api.rpc.RpcRoutingTable; import org.opendaylight.yangtools.concepts.AbstractObjectRegistration; -import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.Mutable; +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; -class RpcRoutingTableImpl // -implements // +final class RpcRoutingTableImpl implements Mutable, // RpcRoutingTable, // RouteChangePublisher, InstanceIdentifier> { @@ -37,8 +40,8 @@ implements // private RouteChangeListener, InstanceIdentifier> listener; private S defaultRoute; - - public RpcRoutingTableImpl(String routerName,Class contextType, Class serviceType) { + + public RpcRoutingTableImpl(final String routerName,final Class contextType, final Class serviceType) { super(); this.routerName = routerName; this.serviceType = serviceType; @@ -48,7 +51,7 @@ implements // } @Override - public void setDefaultRoute(S target) { + public void setDefaultRoute(final S target) { defaultRoute = target; } @@ -59,10 +62,10 @@ implements // @Override public , InstanceIdentifier>> ListenerRegistration registerRouteChangeListener( - L listener) { - return (ListenerRegistration) new SingletonListenerRegistration(listener); + final L listener) { + return new SingletonListenerRegistration(listener); } - + @Override public Class getIdentifier() { return contextType; @@ -70,9 +73,9 @@ implements // @Override @SuppressWarnings("unchecked") - public void updateRoute(InstanceIdentifier path, S service) { + public void updateRoute(final InstanceIdentifier path, final S service) { S previous = this.routes.put(path, service); - + LOGGER.debug("Route {} updated to {} in routing table {}",path,service,this); @SuppressWarnings("rawtypes") RouteChangeListener listenerCapture = listener; @@ -81,10 +84,10 @@ implements // } } - + @Override @SuppressWarnings("unchecked") - public void removeRoute(InstanceIdentifier path) { + public void removeRoute(final InstanceIdentifier path) { S previous = this.routes.remove(path); LOGGER.debug("Route {} to {} removed in routing table {}",path,previous,this); @SuppressWarnings("rawtypes") @@ -93,8 +96,8 @@ implements // listenerCapture.onRouteChange(RoutingUtils.removalChange(contextType, path)); } } - - public void removeRoute(InstanceIdentifier path, S service) { + + void removeRoute(final InstanceIdentifier path, final S service) { @SuppressWarnings("rawtypes") RouteChangeListener listenerCapture = listener; if (routes.remove(path, service) && listenerCapture != null) { @@ -104,7 +107,7 @@ implements // } @Override - public S getRoute(InstanceIdentifier nodeInstance) { + public S getRoute(final InstanceIdentifier nodeInstance) { S route = routes.get(nodeInstance); if (route != null) { return route; @@ -116,12 +119,17 @@ implements // public Map, S> getRoutes() { return unmodifiableRoutes; } - - protected void removeAllReferences(S service) { - + + void removeAllReferences(final S service) { + // FIXME: replace this via properly-synchronized BiMap (or something) + final Iterator it = routes.values().iterator(); + while (it.hasNext()) { + final S s = it.next(); + if (service.equals(s)) { + it.remove(); + } + } } - - @Override public String toString() { @@ -129,13 +137,11 @@ implements // + contextType.getSimpleName() + "]"; } - - private class SingletonListenerRegistration, InstanceIdentifier>> extends AbstractObjectRegistration implements ListenerRegistration { - public SingletonListenerRegistration(L instance) { + public SingletonListenerRegistration(final L instance) { super(instance); listener = instance; } @@ -145,4 +151,4 @@ implements // listener = null; } } -} \ No newline at end of file +}