Fix checkstyle
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / TableContext.java
index 26414299bd09b76049a6dd0e01b5e9b6c70751ec..179d031ed35c90c83a4b4ee46c2b22e6c4a10329 100644 (file)
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-import java.util.Set;
-import javax.annotation.concurrent.NotThreadSafe;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.ClusterId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.OriginatorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPath;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPref;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDisc;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Origin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpAggregator;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ExtendedCommunity;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import static java.util.Objects.requireNonNull;
+
+import java.util.Collection;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 /**
  * A context for a single RIB table instance. It is always bound to a particular {@link AdjRibInWriter}.
  *
- * FIXME: need a better name once we local-rib and rib-out contexts
+ * <p>
+ * This class is NOT thread-safe.
  */
-@NotThreadSafe
+// FIXME: need a better name once we local-rib and rib-out contexts
 final class TableContext {
-    private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(Attributes.QNAME);
-    private static final ContainerNode EMPTY_ROUTE_ATTRIBUTES = ImmutableNodes.containerNode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes.QNAME);
-    private static final Set<Class<? extends DataObject>> ATTRIBUTE_CACHEABLES;
-
-    static {
-        final Builder<Class<? extends DataObject>> acb = ImmutableSet.builder();
-        acb.add(Aggregator.class);
-        acb.add(BgpAggregator.class);
-        acb.add(AsPath.class);
-        acb.add(ClusterId.class);
-        acb.add(Community.class);
-        acb.add(Communities.class);
-        acb.add(ExtendedCommunity.class);
-        acb.add(ExtendedCommunities.class);
-        acb.add(LocalPref.class);
-        acb.add(MultiExitDisc.class);
-        acb.add(Origin.class);
-        acb.add(OriginatorId.class);
-        ATTRIBUTE_CACHEABLES = acb.build();
-    }
-
     private final YangInstanceIdentifier tableId;
-    private final RIBSupport tableSupport;
-    private final Object attributeCodec;
-    private final Object nlriCodec;
-
-    TableContext(final RIBSupport tableSupport, final YangInstanceIdentifier tableId) {
-        this.tableSupport = Preconditions.checkNotNull(tableSupport);
-        this.tableId = Preconditions.checkNotNull(tableId);
-
-        final Builder<Class<? extends DataObject>> acb = ImmutableSet.builder();
-        acb.addAll(ATTRIBUTE_CACHEABLES);
-        acb.addAll(tableSupport.cacheableAttributeObjects());
-
-        // FIXME: new Codec.create(acb.build(), tableSupport.cacheableNlriObjects());
-        attributeCodec = null;
+    private final RIBSupportContext tableSupport;
 
-        // FIXME: new Codec.create(tableSupport.cacheableNlriObjects());
-        nlriCodec = null;
+    TableContext(final RIBSupportContext tableSupport, final YangInstanceIdentifier tableId) {
+        this.tableSupport = requireNonNull(tableSupport);
+        this.tableId = requireNonNull(tableId);
     }
 
     YangInstanceIdentifier getTableId() {
-        return tableId;
+        return this.tableId;
     }
 
-    void clearTable(final DOMDataWriteTransaction tx) {
-        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> tb =
-                ImmutableNodes.mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates)tableId.getLastPathArgument()).withChild(EMPTY_TABLE_ATTRIBUTES);
 
-        final ChoiceNode routes = tableSupport.emptyRoutes();
-        Verify.verifyNotNull(routes, "Null empty routes in %s", this);
-        Verify.verify(Routes.QNAME.equals(routes.getNodeType()), "Empty routes have unexpected identifier %s, expected %s", routes.getNodeType(), Routes.QNAME);
-
-        tx.put(LogicalDatastoreType.OPERATIONAL, tableId, tb.withChild(routes).build());
+    void createEmptyTableStructure(final DOMDataTreeWriteTransaction tx) {
+        this.tableSupport.createEmptyTableStructure(tx, this.tableId);
     }
 
-    void removeTable(final DOMDataWriteTransaction tx) {
-        tx.delete(LogicalDatastoreType.OPERATIONAL, tableId);
+    void removeTable(final DOMDataTreeWriteTransaction tx) {
+        tx.delete(LogicalDatastoreType.OPERATIONAL, this.tableId);
     }
 
-    void writeRoutes(final Object codecFactory, final DOMDataWriteTransaction tx, final MpReachNlri nlri, final PathAttributes attributes) {
-
-        // FIXME: run the decoder process
-        final ContainerNode domNlri = (ContainerNode) nlriCodec;
-
-        // FIXME: run the decoder process
-        final ContainerNode domAttributes = (ContainerNode) attributeCodec;
-        final ContainerNode routeAttributes = Builders.containerBuilder(EMPTY_ROUTE_ATTRIBUTES).withValue(domAttributes.getValue()).build();
+    Collection<NodeIdentifierWithPredicates> writeRoutes(final DOMDataTreeWriteTransaction tx, final MpReachNlri nlri,
+                                                         final Attributes attributes) {
+        return this.tableSupport.writeRoutes(tx, this.tableId, nlri, attributes);
+    }
 
-        tableSupport.putRoutes(tx, tableId, domNlri, routeAttributes);
+    void removeRoutes(final DOMDataTreeWriteTransaction tx, final MpUnreachNlri nlri) {
+        this.tableSupport.deleteRoutes(tx, this.tableId, nlri);
     }
 
-    void removeRoutes(final Object object, final DOMDataWriteTransaction tx, final MpUnreachNlri nlri) {
-        // FIXME: run the decoder process
-        final ContainerNode domNlri = (ContainerNode) nlriCodec;
+    YangInstanceIdentifier routesPath() {
+        return tableSupport.getRibSupport().routesPath(this.tableId);
+    }
 
-        tableSupport.deleteRoutes(tx, tableId, domNlri);
+    YangInstanceIdentifier routePath(final PathArgument routeId) {
+        return tableSupport.getRibSupport().routePath(this.tableId, routeId);
     }
 }