Split out EffectiveRibInWriter.processModifications() 66/78566/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Dec 2018 14:34:59 +0000 (15:34 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Mon, 10 Dec 2018 11:30:45 +0000 (11:30 +0000)
If we have non-empty modifications, we know we will need a transaction,
separate that handling into a separate method, so we can side-step
null checks.

Change-Id: Ic391790c5ab55a8259849ce330d3af94db3cf6f6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 750f8bb39dc055774a0461797b9b0d95cb9b0cbb)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java

index 41e451e4f41a9851e4ba30fd2aafa90584ded8b8..fbe7714bfb5715fe1a7945bf7674759f61c0fdb8 100644 (file)
@@ -148,19 +148,31 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     public synchronized void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<Tables>> changes) {
         if (this.chain == null) {
             LOG.trace("Chain closed. Ignoring Changes : {}", changes);
             return;
         }
+
         LOG.trace("Data changed called to effective RIB. Change : {}", changes);
-        WriteTransaction tx = null;
+        if (!changes.isEmpty()) {
+            processModifications(changes);
+        }
+
+        //Refresh VPN Table if RT Memberships were updated
+        if (this.rtMembershipsUpdated) {
+            this.vpnTableRefresher.refreshTable(IVP4_VPN_TABLE_KEY, this.peerImportParameters.getFromPeerId());
+            this.vpnTableRefresher.refreshTable(IVP6_VPN_TABLE_KEY, this.peerImportParameters.getFromPeerId());
+            this.rtMembershipsUpdated = false;
+        }
+    }
+
+    @GuardedBy("this")
+    @SuppressWarnings("unchecked")
+    private void processModifications(final Collection<DataTreeModification<Tables>> changes) {
+        final WriteTransaction tx = this.chain.newWriteOnlyTransaction();
         for (final DataTreeModification<Tables> tc : changes) {
             final DataObjectModification<Tables> table = tc.getRootNode();
-            if (tx == null) {
-                tx = this.chain.newWriteOnlyTransaction();
-            }
             final DataObjectModification.ModificationType modificationType = table.getModificationType();
             switch (modificationType) {
                 case DELETE:
@@ -213,28 +225,20 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
                     break;
             }
         }
-        if (tx != null) {
-            final FluentFuture<? extends CommitInfo> future = tx.commit();
-            this.submitted = future;
-            future.addCallback(new FutureCallback<CommitInfo>() {
-                @Override
-                public void onSuccess(final CommitInfo result) {
-                    LOG.trace("Successful commit");
-                }
 
-                @Override
-                public void onFailure(final Throwable trw) {
-                    LOG.error("Failed commit", trw);
-                }
-            }, MoreExecutors.directExecutor());
-        }
+        final FluentFuture<? extends CommitInfo> future = tx.commit();
+        this.submitted = future;
+        future.addCallback(new FutureCallback<CommitInfo>() {
+            @Override
+            public void onSuccess(final CommitInfo result) {
+                LOG.trace("Successful commit");
+            }
 
-        //Refresh VPN Table if RT Memberships were updated
-        if (this.rtMembershipsUpdated) {
-            this.vpnTableRefresher.refreshTable(IVP4_VPN_TABLE_KEY, this.peerImportParameters.getFromPeerId());
-            this.vpnTableRefresher.refreshTable(IVP6_VPN_TABLE_KEY, this.peerImportParameters.getFromPeerId());
-            this.rtMembershipsUpdated = false;
-        }
+            @Override
+            public void onFailure(final Throwable trw) {
+                LOG.error("Failed commit", trw);
+            }
+        }, MoreExecutors.directExecutor());
     }
 
     @SuppressWarnings("unchecked")