Bug 4327 - Fixed DataTreeChangeListener registration in PingPongDataBroker
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / CommitCoordinationTask.java
index e0ac702dad59c8d0119460e13b9a87a9535a8cc1..da7a0d19f0a8df00810dc5ec641359c71cdadc35 100644 (file)
@@ -1,16 +1,18 @@
 /*
  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.controller.md.sal.dom.broker.impl;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
-import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collection;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
@@ -29,21 +31,19 @@ final class CommitCoordinationTask implements Callable<Void> {
         canCommit,
         preCommit,
         doCommit,
-    };
+    }
 
     private static final Logger LOG = LoggerFactory.getLogger(CommitCoordinationTask.class);
-    private final Iterable<DOMStoreThreePhaseCommitCohort> cohorts;
+    private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
     private final DurationStatisticsTracker commitStatTracker;
     private final DOMDataWriteTransaction tx;
-    private final int cohortSize;
 
     public CommitCoordinationTask(final DOMDataWriteTransaction transaction,
-            final Iterable<DOMStoreThreePhaseCommitCohort> cohorts,
+            final Collection<DOMStoreThreePhaseCommitCohort> cohorts,
             final DurationStatisticsTracker commitStatTracker) {
         this.tx = Preconditions.checkNotNull(transaction, "transaction must not be null");
         this.cohorts = Preconditions.checkNotNull(cohorts, "cohorts must not be null");
         this.commitStatTracker = commitStatTracker;
-        this.cohortSize = Iterables.size(cohorts);
     }
 
     @Override
@@ -66,7 +66,7 @@ final class CommitCoordinationTask implements Callable<Void> {
 
             LOG.debug("Transaction {}: doCommit completed", tx.getIdentifier());
             return null;
-        } catch (TransactionCommitFailedException e) {
+        } catch (final TransactionCommitFailedException e) {
             LOG.warn("Tx: {} Error during phase {}, starting Abort", tx.getIdentifier(), phase, e);
             abortBlocking(e);
             throw e;
@@ -90,7 +90,7 @@ final class CommitCoordinationTask implements Callable<Void> {
      *
      */
     private void canCommitBlocking() throws TransactionCommitFailedException {
-        for (ListenableFuture<?> canCommit : canCommitAll()) {
+        for (final ListenableFuture<?> canCommit : canCommitAll()) {
             try {
                 final Boolean result = (Boolean)canCommit.get();
                 if (result == null || !result) {
@@ -115,9 +115,9 @@ final class CommitCoordinationTask implements Callable<Void> {
      *
      */
     private ListenableFuture<?>[] canCommitAll() {
-        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohortSize];
+        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
         int i = 0;
-        for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+        for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
             ops[i++] = cohort.canCommit();
         }
         return ops;
@@ -139,7 +139,7 @@ final class CommitCoordinationTask implements Callable<Void> {
     private void preCommitBlocking() throws TransactionCommitFailedException {
         final ListenableFuture<?>[] preCommitFutures = preCommitAll();
         try {
-            for(ListenableFuture<?> future : preCommitFutures) {
+            for(final ListenableFuture<?> future : preCommitFutures) {
                 future.get();
             }
         } catch (InterruptedException | ExecutionException e) {
@@ -162,9 +162,9 @@ final class CommitCoordinationTask implements Callable<Void> {
      *
      */
     private ListenableFuture<?>[] preCommitAll() {
-        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohortSize];
+        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
         int i = 0;
-        for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+        for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
             ops[i++] = cohort.preCommit();
         }
         return ops;
@@ -185,7 +185,7 @@ final class CommitCoordinationTask implements Callable<Void> {
     private void commitBlocking() throws TransactionCommitFailedException {
         final ListenableFuture<?>[] commitFutures = commitAll();
         try {
-            for(ListenableFuture<?> future : commitFutures) {
+            for(final ListenableFuture<?> future : commitFutures) {
                 future.get();
             }
         } catch (InterruptedException | ExecutionException e) {
@@ -205,9 +205,9 @@ final class CommitCoordinationTask implements Callable<Void> {
      * @return List of all cohorts futures from can commit phase.
      */
     private ListenableFuture<?>[] commitAll() {
-        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohortSize];
+        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
         int i = 0;
-        for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+        for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
             ops[i++] = cohort.commit();
         }
         return ops;
@@ -254,11 +254,12 @@ final class CommitCoordinationTask implements Callable<Void> {
      * @return Future which will complete once all cohorts completed
      *         abort.
      */
+    @SuppressWarnings({"unchecked", "rawtypes"})
     private ListenableFuture<Void> abortAsyncAll() {
 
-        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohortSize];
+        final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
         int i = 0;
-        for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+        for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
             ops[i++] = cohort.abort();
         }
 
@@ -267,8 +268,6 @@ final class CommitCoordinationTask implements Callable<Void> {
          * order to fail composite future if any of them failed.
          * See Futures.allAsList for this description.
          */
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        ListenableFuture<Void> compositeResult = (ListenableFuture) Futures.allAsList(ops);
-        return compositeResult;
+        return (ListenableFuture) Futures.allAsList(ops);
     }
 }