Split out EffectiveRibInWriter.processModifications() 06/78506/4
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Dec 2018 14:34:59 +0000 (15:34 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Thu, 6 Dec 2018 21:32:52 +0000 (21:32 +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>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java

index ba776ea818f9e58634a98490504e1c954d1953a8..932b1eeb14b9b23d1558fed99ebdbb4648ac9f5f 100644 (file)
@@ -151,19 +151,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:
@@ -216,28 +228,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")