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.impl;
10 import com.google.common.base.Preconditions;
12 import java.util.HashMap;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
16 import org.opendaylight.protocol.bgp.rib.RibReference;
17 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
18 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsInFactory;
19 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 final class RIBTables {
26 private static final Logger LOG = LoggerFactory.getLogger(RIBTables.class);
28 private final Map<TablesKey, AdjRIBsIn> tables = new HashMap<>();
29 private final RIBExtensionConsumerContext registry;
31 RIBTables(final RIBExtensionConsumerContext extensions) {
32 this.registry = Preconditions.checkNotNull(extensions);
35 public synchronized AdjRIBsIn get(final TablesKey key) {
36 LOG.debug("Looking for key {} in tables {}", key, this.tables);
37 final AdjRIBsIn ret = this.tables.get(key);
38 LOG.trace("Key found {}", ret);
42 public synchronized AdjRIBsIn create(final DataModificationTransaction trans, final RibReference rib, final TablesKey key) {
43 if (this.tables.containsKey(key)) {
44 LOG.warn("Duplicate create request for key {}", key);
45 return this.tables.get(key);
48 final AdjRIBsInFactory f = this.registry.getAdjRIBsInFactory(key.getAfi(), key.getSafi());
50 LOG.debug("RIBsInFactory not found for key {}, returning null", key);
54 final AdjRIBsIn table = Preconditions.checkNotNull(f.createAdjRIBsIn(trans, rib, key));
55 LOG.debug("Table {} created for key {}", table, key);
56 this.tables.put(key, table);