BUG-5280: implement transaction dispatch
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / ClientTransactionCommitCohort.java
1 /*
2  * Copyright (c) 2016 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.cluster.databroker.actors.dds;
9
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.Collection;
13 import java.util.List;
14
15 final class ClientTransactionCommitCohort extends AbstractTransactionCommitCohort {
16     private final List<AbstractProxyTransaction> proxies;
17
18     /**
19      * @param clientTransaction
20      */
21     ClientTransactionCommitCohort(final Collection<AbstractProxyTransaction> proxies) {
22         this.proxies = ImmutableList.copyOf(proxies);
23     }
24
25     @Override
26     public ListenableFuture<Boolean> canCommit() {
27         /*
28          * Issue the request to commit for all participants. We will track the results and report them.
29          */
30         final VotingFuture<Boolean> ret = new VotingFuture<>(Boolean.TRUE, proxies.size());
31         for (AbstractProxyTransaction proxy : proxies) {
32             proxy.canCommit(ret);
33         }
34
35         return ret;
36     }
37
38     @Override
39     public ListenableFuture<Void> preCommit() {
40         final VotingFuture<Void> ret = new VotingFuture<>(null, proxies.size());
41         for (AbstractProxyTransaction proxy : proxies) {
42             proxy.preCommit(ret);
43         }
44
45         return ret;
46     }
47
48     @Override
49     public ListenableFuture<Void> commit() {
50         final VotingFuture<Void> ret = new VotingFuture<>(null, proxies.size());
51         for (AbstractProxyTransaction proxy : proxies) {
52             proxy.doCommit(ret);
53         }
54
55         return ret;
56     }
57
58     @Override
59     public ListenableFuture<Void> abort() {
60         final VotingFuture<Void> ret = new VotingFuture<>(null, proxies.size());
61         for (AbstractProxyTransaction proxy : proxies) {
62             proxy.abort(ret);
63         }
64
65         return ret;
66     }
67 }