From f08bc43decffa086771b41fba063f31656f46e24 Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Fri, 20 Nov 2015 15:06:37 +0100 Subject: [PATCH] Refactor EffectiveRibInWriter Refactor EffectiveRibInWriter to fix Sonar Complains Change-Id: Ie5b5892b26f045cf683ca5af56307cad3de683ef Signed-off-by: Claudio D. Gasparini --- .../bgp/rib/impl/EffectiveRibInWriter.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java index 818de4cc11..90bb3b086c 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java @@ -62,9 +62,6 @@ final class EffectiveRibInWriter implements AutoCloseable { private static final NodeIdentifier ADJRIBIN_NID = new NodeIdentifier(AdjRibIn.QNAME); private static final NodeIdentifier TABLES_NID = new NodeIdentifier(Tables.QNAME); - /** - * Maintains {@link TableRouteListener} instances. - */ private final class AdjInTracker implements AutoCloseable, DOMDataTreeChangeListener { private final RIBSupportContextRegistry registry; private final YangInstanceIdentifier ribId; @@ -140,24 +137,12 @@ final class EffectiveRibInWriter implements AutoCloseable { // No-op break; case SUBTREE_MODIFIED: - if (TABLE_ROUTES.equals(childIdentifier)) { - for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) { - processRoute(tx, ribSupport, policy, childPath, route); - } - } else { - tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get()); - } + processModifiedRouteTables(child, childIdentifier,tx, ribSupport, policy, childPath, childDataAfter); break; case APPEARED: case WRITE: - tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get()); - // Routes are special, as they may end up being filtered. The previous put conveniently - // ensured that we have them in at target, so a subsequent delete will not fail :) - if (TABLE_ROUTES.equals(childIdentifier)) { - for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) { - processRoute(tx, ribSupport, policy, childPath, route); - } - } + writeRouteTables(child, childIdentifier,tx, ribSupport, policy, childPath, childDataAfter); + break; default: LOG.warn("Ignoring unhandled child {}", child); @@ -166,6 +151,28 @@ final class EffectiveRibInWriter implements AutoCloseable { } } + private void processModifiedRouteTables(final DataTreeCandidateNode child, final PathArgument childIdentifier, final DOMDataWriteTransaction tx, + final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier childPath, final Optional> childDataAfter) { + if (TABLE_ROUTES.equals(childIdentifier)) { + for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) { + processRoute(tx, ribSupport, policy, childPath, route); + } + } else { + tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get()); + } + } + + private void writeRouteTables(final DataTreeCandidateNode child, final PathArgument childIdentifier, final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier childPath, final Optional> childDataAfter) { + tx.put(LogicalDatastoreType.OPERATIONAL, childPath, childDataAfter.get()); + // Routes are special, as they may end up being filtered. The previous put conveniently + // ensured that we have them in at target, so a subsequent delete will not fail :) + if (TABLE_ROUTES.equals(childIdentifier)) { + for (final DataTreeCandidateNode route : ribSupport.changedRoutes(child)) { + processRoute(tx, ribSupport, policy, childPath, route); + } + } + } + private RIBSupportContext getRibSupport(final NodeIdentifierWithPredicates tableKey) { return this.registry.getRIBSupportContext(tableKey); } @@ -193,7 +200,7 @@ final class EffectiveRibInWriter implements AutoCloseable { } @Override - public void onDataTreeChanged(final Collection changes) { + public void onDataTreeChanged(@Nonnull final Collection changes) { LOG.trace("Data changed called to effective RIB. Change : {}", changes); // we have a lot of transactions created for 'nothing' because a lot of changes -- 2.36.6