2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.Preconditions;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.ConcurrentMap;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
21 import org.opendaylight.yangtools.yang.binding.ChildOf;
22 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.Identifiable;
25 import org.opendaylight.yangtools.yang.binding.Identifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class SimpleRIBExtensionProviderContext implements RIBExtensionProviderContext {
31 private static final Logger LOG = LoggerFactory.getLogger(SimpleRIBExtensionProviderContext.class);
33 private final ConcurrentMap<TablesKey, RIBSupport<?, ?, ?, ?>> supports = new ConcurrentHashMap<>();
34 private final ConcurrentMap<NodeIdentifierWithPredicates, RIBSupport<?, ?, ?, ?>> domSupports =
35 new ConcurrentHashMap<>();
38 public <T extends RIBSupport<?, ?, ?, ?>> RIBSupportRegistration<T> registerRIBSupport(
39 final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi,
41 final TablesKey key = new TablesKey(afi, safi);
42 final RIBSupport<?, ?, ?, ?> prev = this.supports.putIfAbsent(key, support);
43 Preconditions.checkArgument(prev == null, "AFI %s SAFI %s is already registered with %s",
45 this.domSupports.put(RibSupportUtils.toYangTablesKey(afi, safi), support);
46 return new AbstractRIBSupportRegistration<>(support) {
48 protected void removeRegistration() {
49 // FIXME: clean up registrations, too
50 SimpleRIBExtensionProviderContext.this.supports.remove(key);
56 public <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<C>,
57 R extends Route & ChildOf<S> & Identifiable<I>, I extends Identifier<R>> RIBSupport<C, S, R, I> getRIBSupport(
58 final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
59 return getRIBSupport(new TablesKey(afi, safi));
63 @SuppressWarnings("unchecked")
64 public <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<C>,
65 R extends Route & ChildOf<S> & Identifiable<I>, I extends Identifier<R>> RIBSupport<C, S, R, I> getRIBSupport(
66 final TablesKey key) {
67 return (RIBSupport<C, S, R, I>) this.supports.get(requireNonNull(key));
71 @SuppressWarnings("unchecked")
72 public <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<C>,
73 R extends Route & ChildOf<S> & Identifiable<I>, I extends Identifier<R>> RIBSupport<C, S, R, I> getRIBSupport(
74 final NodeIdentifierWithPredicates key) {
75 return (RIBSupport<C, S, R, I>) this.domSupports.get(key);