Fix some rib-impl warnigs
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / TableContext.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Collection;
13 import javax.annotation.concurrent.NotThreadSafe;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
16 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
23
24 /**
25  * A context for a single RIB table instance. It is always bound to a particular {@link AdjRibInWriter}.
26  */
27 // FIXME: need a better name once we local-rib and rib-out contexts
28 @NotThreadSafe
29 final class TableContext {
30     private final YangInstanceIdentifier tableId;
31     private final RIBSupportContext tableSupport;
32
33     TableContext(final RIBSupportContext tableSupport, final YangInstanceIdentifier tableId) {
34         this.tableSupport = requireNonNull(tableSupport);
35         this.tableId = requireNonNull(tableId);
36     }
37
38     YangInstanceIdentifier getTableId() {
39         return this.tableId;
40     }
41
42
43     void createEmptyTableStructure(final DOMDataWriteTransaction tx) {
44         this.tableSupport.createEmptyTableStructure(tx, this.tableId);
45     }
46
47     void removeTable(final DOMDataWriteTransaction tx) {
48         tx.delete(LogicalDatastoreType.OPERATIONAL, this.tableId);
49     }
50
51     Collection<NodeIdentifierWithPredicates> writeRoutes(final DOMDataWriteTransaction tx, final MpReachNlri nlri,
52                                                          final Attributes attributes) {
53         return this.tableSupport.writeRoutes(tx, this.tableId, nlri, attributes);
54     }
55
56     void removeRoutes(final DOMDataWriteTransaction tx, final MpUnreachNlri nlri) {
57         this.tableSupport.deleteRoutes(tx, this.tableId, nlri);
58     }
59
60     YangInstanceIdentifier routesPath() {
61         return tableSupport.getRibSupport().routesPath(this.tableId);
62     }
63
64     YangInstanceIdentifier routePath(final PathArgument routeId) {
65         return tableSupport.getRibSupport().routePath(this.tableId, routeId);
66     }
67 }