Refactor EffectiveRibInWriter 90/29990/2
authorClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 20 Nov 2015 14:06:37 +0000 (15:06 +0100)
committerMilos Fabian <milfabia@cisco.com>
Sat, 21 Nov 2015 15:49:30 +0000 (15:49 +0000)
Refactor EffectiveRibInWriter to fix Sonar Complains

Change-Id: Ie5b5892b26f045cf683ca5af56307cad3de683ef
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java

index 818de4cc1132866c682c8be9b13f52ec3c25d3be..90bb3b086c8d136d14837f081c056ae5f375c9ee 100644 (file)
@@ -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<NormalizedNode<?, ?>> 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<NormalizedNode<?, ?>> 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<DataTreeCandidate> changes) {
+        public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> 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