Specialize CommitCoordinationTask
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / SerializedDOMDataBroker.java
index 4200029a2e2895f6fcefb140954c6bd3e3330fd5..d100e8f230d4e32c7c38f5e54d1bebc2700405e8 100644 (file)
@@ -5,25 +5,24 @@
  * 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.mdsal.dom.broker;
 
-import org.opendaylight.mdsal.dom.spi.store.DOMStore;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import static java.util.Objects.requireNonNull;
 
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
-import org.opendaylight.mdsal.dom.api.DOMDataWriteTransaction;
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.RejectedExecutionException;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStore;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
-import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -31,11 +30,14 @@ import org.slf4j.LoggerFactory;
  * Implementation of blocking three phase commit coordinator, which which
  * supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}.
  *
+ *<p>
  * This implementation does not support cancellation of commit,
  *
+ *<p>
  * In order to advance to next phase of three phase commit all subtasks of
  * previous step must be finish.
  *
+ *<p>
  * This executor does not have an upper bound on subtask timeout.
  */
 public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
@@ -44,15 +46,16 @@ public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
     private final ListeningExecutorService executor;
 
     /**
-     *
      * Construct DOMDataCommitCoordinator which uses supplied executor to
      * process commit coordinations.
      *
-     * @param executor
+     * @param datastores the Map of backing DOMStore instances
+     * @param executor the ListeningExecutorService to use
      */
-    public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores, final ListeningExecutorService executor) {
+    public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores,
+            final ListeningExecutorService executor) {
         super(datastores);
-        this.executor = Preconditions.checkNotNull(executor, "executor must not be null.");
+        this.executor = requireNonNull(executor, "executor must not be null.");
     }
 
     public DurationStatisticsTracker getCommitStatsTracker() {
@@ -60,25 +63,19 @@ public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
     }
 
     @Override
-    protected CheckedFuture<Void,TransactionCommitFailedException> submit(final DOMDataWriteTransaction transaction,
+    protected FluentFuture<? extends CommitInfo> commit(final DOMDataTreeWriteTransaction transaction,
             final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
         Preconditions.checkArgument(transaction != null, "Transaction must not be null.");
         Preconditions.checkArgument(cohorts != null, "Cohorts must not be null.");
         LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());
 
-        ListenableFuture<Void> commitFuture = null;
         try {
-            commitFuture = executor.submit(new CommitCoordinationTask(transaction, cohorts,
-                    commitStatsTracker));
-        } catch(RejectedExecutionException e) {
-            LOG.error("The commit executor's queue is full - submit task was rejected. \n" +
-                      executor, e);
-            return Futures.immediateFailedCheckedFuture(
-                    new TransactionCommitFailedException(
-                        "Could not submit the commit task - the commit queue capacity has been exceeded.", e));
+            return FluentFuture.from(executor.submit(
+                new CommitCoordinationTask.WithTracker(transaction, cohorts, commitStatsTracker)));
+        } catch (RejectedExecutionException e) {
+            LOG.error("The commit executor's queue is full - submit task was rejected. \n{}", executor, e);
+            return FluentFutures.immediateFailedFluentFuture(new TransactionCommitFailedException(
+                "Could not submit the commit task - the commit queue capacity has been exceeded.", e));
         }
-
-        return MappingCheckedFuture.create(commitFuture,
-                TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER);
     }
 }