X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fdom%2Fbroker%2FSerializedDOMDataBroker.java;h=c41d2c0b1480b4d6a6a456c74c11f12e6f0cd100;hb=90b0687e0640ee23369d2ad9978628e3ff957a26;hp=29ac230e790310ba2dce1dca5579ee78cb36750e;hpb=ee479de332c71ae6811a9f307b0e7a3fe5e50861;p=mdsal.git diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/SerializedDOMDataBroker.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/SerializedDOMDataBroker.java index 29ac230e79..c41d2c0b14 100644 --- a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/SerializedDOMDataBroker.java +++ b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/SerializedDOMDataBroker.java @@ -5,54 +5,55 @@ * 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.DOMDataTreeWriteTransaction; -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import java.util.Collection; import java.util.Map; +import java.util.concurrent.Executor; 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.broker.CommitCoordinationTask.WithTracker; +import org.opendaylight.mdsal.dom.spi.AbstractDOMDataBroker; +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; /** - * Implementation of blocking three phase commit coordinator, which which - * supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}. + * Implementation of blocking three phase commit coordinator, which which supports coordination on multiple + * {@link DOMStoreThreePhaseCommitCohort}. This implementation does not support cancellation of commit. * - * This implementation does not support cancellation of commit, - * - * In order to advance to next phase of three phase commit all subtasks of - * previous step must be finish. + *

+ * In order to advance to next phase of three phase commit all subtasks of previous step must be finish. * + *

* This executor does not have an upper bound on subtask timeout. */ -public class SerializedDOMDataBroker extends AbstractDOMDataBroker { +public final class SerializedDOMDataBroker extends AbstractDOMDataBroker { private static final Logger LOG = LoggerFactory.getLogger(SerializedDOMDataBroker.class); + private final DurationStatisticsTracker commitStatsTracker = DurationStatisticsTracker.createConcurrent(); - private final ListeningExecutorService executor; + private final Executor executor; /** - * * Construct DOMDataCommitCoordinator which uses supplied executor to * process commit coordinations. * - * @param executor + * @param datastores the Map of backing DOMStore instances + * @param executor the Executor to use */ - public SerializedDOMDataBroker(final Map datastores, final ListeningExecutorService executor) { + public SerializedDOMDataBroker(final Map datastores, final Executor 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 +61,20 @@ public class SerializedDOMDataBroker extends AbstractDOMDataBroker { } @Override - protected CheckedFuture submit(final DOMDataTreeWriteTransaction transaction, - final Collection cohorts) { - Preconditions.checkArgument(transaction != null, "Transaction must not be null."); - Preconditions.checkArgument(cohorts != null, "Cohorts must not be null."); + protected FluentFuture commit(final DOMDataTreeWriteTransaction transaction, + final DOMStoreThreePhaseCommitCohort cohort) { LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier()); - ListenableFuture commitFuture = null; + final ListenableFuture future; 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)); + // FIXME: use FluentFutures.submit() once it is available + future = Futures.submit(new WithTracker(transaction, cohort, commitStatsTracker), executor); + } 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); + return FluentFuture.from(future); } }