Use Empty instead of Void in cohorts
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / DirectTransactionCommitCohort.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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14 import org.opendaylight.mdsal.common.api.CommitInfo;
15 import org.opendaylight.yangtools.yang.common.Empty;
16
17 /**
18  * An {@link AbstractTransactionCommitCohort} implementation for transactions which contain a single proxy. Since there
19  * is only one proxy,
20  *
21  * @author Robert Varga
22  */
23 final class DirectTransactionCommitCohort extends AbstractTransactionCommitCohort {
24     private final AbstractProxyTransaction proxy;
25
26     DirectTransactionCommitCohort(final AbstractClientHistory parent, final TransactionIdentifier txId,
27         final AbstractProxyTransaction proxy) {
28         super(parent, txId);
29         this.proxy = requireNonNull(proxy);
30     }
31
32     @Override
33     public ListenableFuture<Boolean> canCommit() {
34         return proxy.directCommit();
35     }
36
37     @Override
38     public ListenableFuture<Empty> preCommit() {
39         return EMPTY_FUTURE;
40     }
41
42     @Override
43     public ListenableFuture<Empty> abort() {
44         complete();
45         return EMPTY_FUTURE;
46     }
47
48     @Override
49     public ListenableFuture<CommitInfo> commit() {
50         complete();
51         return CommitInfo.emptyFluentFuture();
52     }
53 }