atomic-storage: remove type dependency at segment level I/O
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / SerializedDOMDataBroker.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.md.sal.dom.broker.impl;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.base.Supplier;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.ListeningExecutorService;
17 import java.util.Collection;
18 import java.util.Map;
19 import java.util.concurrent.RejectedExecutionException;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
25 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * Implementation of blocking three phase commit coordinator, which which
31  * supports coordination on multiple {@link DOMStoreThreePhaseCommitCohort}.
32  *
33  * <p>
34  * This implementation does not support cancellation of commit,
35  *
36  * <p>
37  * In order to advance to next phase of three phase commit all subtasks of
38  * previous step must be finish.
39  *
40  * <p>
41  * This executor does not have an upper bound on subtask timeout.
42  */
43 @Deprecated(forRemoval = true)
44 public class SerializedDOMDataBroker extends AbstractDOMDataBroker {
45     private static final Logger LOG = LoggerFactory.getLogger(SerializedDOMDataBroker.class);
46     private final DurationStatisticsTracker commitStatsTracker = DurationStatisticsTracker.createConcurrent();
47     private final ListeningExecutorService executor;
48
49     /**
50      * Construct DOMDataCommitCoordinator which uses supplied executor to
51      * process commit coordinations.
52      *
53      * @param datastores data stores
54      * @param executor executor service
55      */
56     public SerializedDOMDataBroker(final Map<LogicalDatastoreType, DOMStore> datastores,
57                                    final ListeningExecutorService executor) {
58         super(datastores);
59         this.executor = requireNonNull(executor, "executor must not be null.");
60     }
61
62     public DurationStatisticsTracker getCommitStatsTracker() {
63         return commitStatsTracker;
64     }
65
66     @Override
67     protected <T> ListenableFuture<T> commit(final DOMDataWriteTransaction transaction,
68             final Collection<DOMStoreThreePhaseCommitCohort> cohorts, final Supplier<T> futureValueSupplier) {
69         checkArgument(transaction != null, "Transaction must not be null.");
70         checkArgument(cohorts != null, "Cohorts must not be null.");
71         LOG.debug("Tx: {} is submitted for execution.", transaction.getIdentifier());
72
73         ListenableFuture<T> commitFuture;
74         try {
75             commitFuture = executor.submit(new CommitCoordinationTask<>(transaction, cohorts, commitStatsTracker,
76                     futureValueSupplier));
77         } catch (RejectedExecutionException e) {
78             LOG.error("The commit executor {} queue is full - submit task was rejected. \n", executor, e);
79             commitFuture = Futures.immediateFailedFuture(new TransactionCommitFailedException(
80                     "Could not submit the commit task - the commit queue capacity has been exceeded.", e));
81         }
82
83         return commitFuture;
84     }
85 }